【发布时间】: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>";
?>
【问题讨论】: