gpt4 book ai didi

php - 使用第一个脚本中的 "more info"按钮将数据拉入第二个脚本

转载 作者:行者123 更新时间:2023-11-30 00:55:15 26 4
gpt4 key购买 nike

我什至不确定我是否正确地问了这个问题。我缺乏术语,对此我先表示歉意。你看,我有两个 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>";

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

这是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>";
?>

最佳答案

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

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

URL 末尾的数字是该问题在数据库中的 ID,或者是该问题的某种数字表示形式。

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

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

关于php - 使用第一个脚本中的 "more info"按钮将数据拉入第二个脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20622290/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com