如何显示与其他数据MySQL PHP对应的数据


How to display data the corresponds to other data MySQL PHP

我的工作PHP脚本连接到我的数据库,获取数据,然后将其放入一个表中,如下所示:

while($row = mysqli_fetch_array($result)) //mysql_fetch_array bring back an object, in this case the $result of the mysql query and puts it into a variable $row
 {
  echo "<tr>";
  echo "<td align='center'><img height='100' width='100' src='"" . $row['picturepath'] . "'" /></td>"; //here I can use the results and call out which column I want from my database
  echo '<td align="center">' . $row['name'] . '</td>';
  echo '<td align="center"><input type="button" value="More Info" onclick="window.location=''more_info.php?start=' . urlencode($row['description']) .' '';" /></td>';

  echo "<td align='center'>" . $row['price'] . "</td> <td align='center'> <input type='button' value='Add to Order' onclick=''> </td>";
  echo "</tr>";
 }
echo "</table>";
echo "<table width='"1024'" align='"center'" >";
    echo "<tr height='"50'"></tr>";

"更多信息"按钮链接到一个单独的php脚本More_Info.php,其中的描述会读取到该特定项目的页面上。我也想显示与该项目相对应的图像,但一直在这样做时遇到问题

我已经试过了

我已经修改了上面的代码以显示:

more_info.php?start=' . urlencode($row['description']) . urlencode($row['picturepath']) . ''';" /></td>';

然后它会拉入正确的信息,但它实际上是拉入图像的文件名,而不是实际的图片。

目标

我想要"更多信息"链接,提取用户点击"更多信息"的项目的描述和图像,并将两者都转储到"More_Info.php"中。在这种情况下,我必须使用$_POST吗?或者在more_info.php上运行一个查询,其中picturepath只有在与项目名称匹配时才会显示?我不确定。。。

在没有看到代码的情况下很难判断more_info.php中发生了什么,但您需要一种方法来区分php脚本中的两个字段(description、picturepath)。对于url,请使用以下内容:

$url = "more_info.php?start=" . urlencode($row['description']) . "&path=" . urlencode($row['picturepath']);

在onclick:中使用$url字符串

... onclick="window.location=''$url''" ...

然后在more_info.php中使用$_GET来检索作为URL:的一部分传递的2个参数(开始,路径)

if(isset($_GET['start']) && isset($_GET['path'])){
    $description = $_GET['start'];
    $picturepath = $_GET['path'];
    echo "Description: $description <img src='"$picturepath'"/>";
}

不确定这是否有帮助/是否是你想要的。如果不提供moreinfo.php及其当前输出。