【问题标题】:Pulling data into a second script using a "more info" button from first script使用第一个脚本中的“更多信息”按钮将数据拉入第二个脚本
【发布时间】:2015-12-27 22:45:38
【问题描述】:

我不完全确定我是否正确地问了这个问题。我缺乏术语,对此我深表歉意。你看,我有两个 php 脚本,我正在尝试学习 php 和 MySQL 如何协同工作。在我的第一个 php 脚本 order.php 中,我从数据库中提取信息并将其显示在页面上。在每个被拉出的项目下,都有一个“更多信息”按钮。我的目标是让用户点击任何特定项目的“更多信息”,当他们这样做时,被重定向到列出该项目信息的新页面。

到目前为止,我有一个链接到 moreinfo.php 脚本的“更多信息”按钮,它正在使用 urlencode 检索项目描述,并将其显示在 moreinfo.php 上。

我需要的是让“order.php”上的“更多信息”按钮拉出项目描述、名称和价格。

我已经尝试添加:

. urlencode($row['description']) . urlencode($row['price']) .

到下面的代码,它会提取信息,但我无法将其分开。到目前为止,这是我的所有代码。

require("database.php"); //connect to the database

$start = (isset($_GET['start']) ? (int)$_GET['start'] : 0); //setting the get function to a variable so I can display data on same page

$result = mysqli_query($con,"SELECT * FROM menuitem LIMIT $start, 3");
    if (!$result) {
        printf("Error: %s\n", mysqli_error($con));
        exit();
    }

echo "<table width='1024' border='0' cellpadding='10' cellspacing='5' align='center'>
<tr align='center'>
<th></th>
<th>Menu Items</th>
<th>Description</th>
<th>Price</th>
<th>Add to Order</th>
</tr>";

 while($row = mysqli_fetch_array($result)) 
 {
  echo "<tr>";
  echo "<td align='center'><img height='100' width='100' src=\"" . $row['picturepath'] . "\" /></td>"; 

  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"><input type="button" value="More Info" onclick="window.location=\'more_info.php?start=' . urlencode($row['description']) . urlencode($row['price']) .' \';" /></td>';

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

目前,它正在将描述和价格放在一起,我不知道如何分成不同的表格。如果有人甚至可以给我一个 google 的关键字,我很乐意自己查找信息,或者尽我所能研究它以使其正常工作。

这里是moreinfo.php

$start = (!empty($_GET['start']) ? $_GET['start'] : false);

<html><table width='100%' border='0'><tr><td height="200"></td></tr></table></html>

<?php
echo "<table width='90%' border='0' cellpadding='10' cellspacing='5' align='center'>"
echo "<tr align='center'>
      <td width='60%' align='left'>" . $start . "</td>
      <td width='40%' align='left'>" "</td>
      </tr>";
echo "</table>"; 
?>

【问题讨论】:

    标签: php mysql database


    【解决方案1】:

    看看其他网站如何做同样的事情。 IE 堆栈溢出。在主页上,有一个问题列表。当您点击一个问题时,会出现该问题以及与之相关的所有数据。

    此特定问题的链接是http://stackoverflow.com/questions/20622290

    URL 末尾的数字是这个问题在数据库中的 ID,或者是这个问题的一些数字表示。

    我建议将您的商品 ID 添加到网址的末尾。即,http://example.com/moreinfo.php?id=5.

    5 是您要查看的项目的 ID。这将允许您从数据库中获取该项目信息,然后您将能够显示它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-15
      • 1970-01-01
      • 2012-10-02
      • 2017-12-14
      • 2020-05-06
      • 1970-01-01
      • 1970-01-01
      • 2020-09-06
      相关资源
      最近更新 更多