简体   繁体   中英

how to get the value of a user_id link from html table using php

$row[0] is user_id when i click on user_id i need to know how to get the value i clicked from the html table using php so i can use this id to select its data into another form so i can edit it

$select = "SELECT U.id, U.first_name, U.last_name, U.email_address, U.password, U.gender, U.day, U.month, U.year, COUNT(O.user_id) FROM users U LEFT JOIN orders O ON U.id = O.user_id GROUP  BY U.id ORDER BY id $order LIMIT $offset , $rowsPerPage";    
$result=mysql_query($select) or die(mysql_error());
while($row=mysql_fetch_array($result)){ ?>

<table>
<tr>      
    <td><?php echo "<a href= 'editUser.html'> $row[0]</a>"; ?></td>
    <td><?php echo $row[1];?></td>
    <td><?php echo $row[2];?></td>
    <td><?php echo $row[3];?></td>
    <td><?php echo $row[4];?></td>
    <td><?php echo $row[5];?></td>
    <td><?php echo $row[6];?></td>
    <td><?php echo $row[7];?></td>
    <td><?php echo $row[8];?></td>
    <td><?php echo $row[9];}
    </tr>
</table>

Pass as query string and will be available in $_GET

<td><?php echo "<a href= 'editUser.html?id=".$row[0]."'> $row[0]</a>"; ?></td>

You can get in next page like this

echo $_GET['id'];

You can't "get" id from HTML table.
You can only send it using a hyperlink

$select = "SELECT U.id, U.first_name, U.last_name, U.email_address, U.password, U.gender, U.day, U.month, U.year, COUNT(O.user_id) FROM users U LEFT JOIN orders O ON U.id = O.user_id GROUP  BY U.id ORDER BY id $order LIMIT $offset , $rowsPerPage";    
$result=mysql_query($select) or die(mysql_error());
while($row=mysql_fetch_array($result)){ 
  $data[] = $row;
}
?>

<table>
  <tr>
<? foreach($data as $row) { ?>
    <td><a href="edituser.php?id=<?php echo $row['id']?>"><?php echo $row['id']?></a></td>
<? } ?>
  </tr>
</table>

您可以使用Ajax请求将数据从表发送到服务器。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM