0

我有一个标准的 Mysqli/php 代码来回显项目列表。

因此,假设用户选择编辑指定的产品。产品正在一段时间循环中打印。我如何仅在 ex 中切换内容。产品 9 如果在 while 循环中打印了 100 个产品?

所有产品都在一个 Div 中。

一些代码例如:

$query = $mysqli->query("SELECT item_name, item_id FROM items");
while($items = $query->fetch_assoc()){

  echo $items['item_name'];
  echo '<a href="" onclick="switch content of only the single product that has been chosen">Edit me</a>'

}
4

1 回答 1

1

您可以为此使用三元运算符:

$query = $mysqli->query("SELECT item_name, item_id FROM items");
while($items = $query->fetch_assoc())
{   
    $clickEvent = ($items['item_id'] == 9) ? 'for id 9' : 'for others';
    echo $items['item_name'];
    echo '<a href="" onclick="'.$clickEvent.'">Edit me</a>'
}
于 2013-02-07T10:10:10.080 回答