m.mahmoudi
4 سال پیش توسط m.mahmoudi مطرح شد
0 پاسخ

نمایش لیست کاربران

این کد درست است اما من میخوام بعد از لاگین کردن لیست کاربران را برای من نمایش دهد و زیر هر ستون که خواستم کاربر خاصی را جستجو کنم،کاربرهایی با مشخصات یکسان را برای من بیاورد.
در کد من دارم ۲۰ ایتم اما اینجا فقط ۲ ایتم نوشته ام.
usersearch.php

require_once 'users.php';
<table class="table table-bordered table-striped table-hover stara">
    <thead>
    <tr>
        <th>آیدی</th>
        <th>نام</th>
    <tr>
    <tr>
        <th>
            <form action="usersearch.php" method="post" novalidate>
                <input  name="searchid" >
            </form>
        </th>
        <th>
            <form action="/usersearch.php" method="post" novalidate>
                <input name="searchname">
            </form>
        </th>
   <tr>
    <?php  while($user = $result-> fetch(PDO::FETCH_ASSOC ))  { ?>
        <tr class="bgyellow">
            <th>
                <?php echo $user['id'] ; ?>
            </th>
            <th>
                <?php echo $user['name'] ; ?>
            </th>
            <th>
     </tr>
       <?php } ?>
    </thead>
 <tbody >
    <?php while($row=$select_stmt->fetch(PDO::FETCH_ASSOC)){ ?>
        <tr>
            <td> <?php echo $row['id'] ; ?> </td>
            <td> <?php echo $row['name'] ; ?> </td>
  </tr>
    <?php } ?>
    </tbody>
</table>

users.php

if(isset($_SESSION['user']) ) {

      $db = new PDO("mysql:host=localhost;dbname=pasak", "root", "");
      $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $select_stmt = $db->prepare("SELECT * FROM users");
      $select_stmt->execute();
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        if($_POST['searchid']){
            $id=$_POST['searchid'];
            $result = $db->prepare( "SELECT * FROM users WHERE id =:id");
            $result->execute((compact('id')));

            if($result ->rowCount() <1){
                echo 'چنین کاربری وجود ندارد';
            }
            echo "</br>"; echo "</br>";
        }
        if($_POST['searchname']){
            $name=$_POST['searchname'];
           $result = $db->prepare( "SELECT * FROM users WHERE name =:name");
            $result->execute((compact('name')));
            if($result ->rowCount() <1){
                echo 'چنین کاربری وجود ندارد';
            }
            echo "</br>"; echo "</br>";
        }
}