简体   繁体   中英

Give unique ID in a while loop item

How can I give a uniuqe ID for a item in a while loop.

Example:

while ($row = mysql_fetch_array($query)){
 echo "$row['items']; <a href=\"GoToPageToEditThisItem\">Edit</a>";
}

Output: http://prntscr.com/2bto7g

So I can edit the appropriate item.

Assuming you have an ID (auto incremented/unique) in your table,

while ($row = mysql_fetch_array($query)){
 echo $row['items'] . '<a href="editItem.php?id=' . $row['id'] . '">Edit</a>';
}

You could then access the item using $_GET["id"] .

$id = 0;
while ($row = mysql_fetch_array($query)){
 $id = $row['id'];
 echo $row['items'].'<a href=\"GoToPageToEditThisItem\id\$id">Edit</a>';
}

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