user3111229
user3111229

Reputation: 5

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.

Upvotes: 0

Views: 775

Answers (2)

Ben Fortune
Ben Fortune

Reputation: 32127

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"].

Upvotes: 2

웃웃웃웃웃
웃웃웃웃웃

Reputation: 11984

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

Upvotes: 0

Related Questions