Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取MySQL生成的Div框的唯一ID_Php_Mysql - Fatal编程技术网

Php 如何获取MySQL生成的Div框的唯一ID

Php 如何获取MySQL生成的Div框的唯一ID,php,mysql,Php,Mysql,这是我的代码: $output .= '<div class="col-md-3"><div class="single-post">'; if ($row["fahrzeugBild"] !== "") { $output .= '<img src="img/cars/'.$row["fahrzeugBild"].'.jpg" alt="">'; } 我在PHP/sql数组中使用它,因

这是我的代码:


        $output .= '<div class="col-md-3"><div class="single-post">';
        if ($row["fahrzeugBild"] !== "") {
          $output .= '<img src="img/cars/'.$row["fahrzeugBild"].'.jpg" alt="">';
        }

我在PHP/sql数组中使用它,因此显示/隐藏所需的div是从数据库生成的。但是当我使用这个脚本时,它只适用于数组中的第一个div。。。。所以(我认为)我基本上需要能够为每个div自动生成一个唯一的id。但是这里有个问题,我不知道我的代码看起来是怎么一团乱的,但是我还在学习php,所以请原谅我。 任何帮助都将是惊人的。

尝试以下方法:

PHP

更新: 理想情况下,您应该分配一个唯一的ID而不是随机数,例如,如果数据库中的每个项目都有一个自动增量ID,您可以使用该自动增量ID,最好将其分配给每个
div
尝试以下操作:

PHP

更新
理想情况下,您应该分配一个唯一的ID而不是一个随机数,例如,如果数据库中的每个项目都有一个自动增量ID,您最好使用该自动增量ID,并将其分配给每个
div

尝试使用类似
$output的方法。='显示/HideTuning详细信息

'尝试类似于
$output.='显示/隐藏调整详细信息

'感谢您的解决方案!现在如何在所有自定义ID上获得css#调整div{padding left:5px;float:left;}调整img{width:12px;height:12px;}尝试使用
div[id^=“tuning”]{padding left:5px;float:left;}调整img{width:12px;height:12px;}
:)这不起作用。给我一个可怕的结果。我想这是找不到的#调整img{width:12px;height:12px;}因为图像仍然很大,但是div是浮动的left尝试:
div[id^=“tuning”]div{padding left:5px;float:left;}
div[id^=“tuning”]img{width:12px;height:12px;}
仍然不起作用,这就是它应该是什么样子:现在它看起来是什么样子,使用相同的CSS代码:图片btw是15x15谢谢你的解决方案!现在如何在所有自定义ID上获得css#调整div{padding left:5px;float:left;}调整img{width:12px;height:12px;}尝试使用
div[id^=“tuning”]{padding left:5px;float:left;}调整img{width:12px;height:12px;}
:)这不起作用。给我一个可怕的结果。我想这是找不到的#调整img{width:12px;height:12px;}因为图像仍然很大,但是div是浮动的left尝试:
div[id^=“tuning”]div{padding left:5px;float:left;}
div[id^=“tuning”]img{width:12px;height:12px;}
仍然不起作用,这是它应该是什么样子的:现在使用相同的CSS代码是什么样子的:顺便说一句,图像是15x15
function myFunction() {
  var x = document.getElementById("tuning");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
} 
$customId = random_int(10000, 99999);
        $output .= '<p><button onclick="myFunction('.$customId.')">Show/Hide</button><div id="tuning'.$customId.'" style="display:none;">Tuning Details</p>';
function myFunction(customId) {
  var x = document.getElementById("tuning"+customId);
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}