gpt4 book ai didi

php - 无法使用 php 从 mysql 获取数据到 html 表,显示内部服务器错误

转载 作者:行者123 更新时间:2023-11-29 13:20:41 25 4
gpt4 key购买 nike

我编写了下面的php代码来从mysql获取数据到html表,但是无论我如何尝试,它总是显示内部服务器错误,有人可以帮我看一下代码吗?

我在mysql中测试了查询,它有效,我不知道为什么当我将它添加到php时,它就崩溃了。

$StartDate = date( 'Y-m-d' strtotime($_POST['StartDate']));
$EndDate = date( 'Y-m-d' strtotime($_POST['EndDate']));

$link = mysql_connect('****', '****', '****');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db(****);

// Search by date query
$SearchByDate = "
SELECT Order_Info.OrderID, Order_Info.Date, Client_Info.Manager, Material_Info.MateRefNum, Order_Info.CustomMateName,
Order_Info.Quantity, Order_Info.Weight, Order_Info.TechRequire, Order_Info.UniPrice, Order_Info.TotPrice, Order_Info.OtherNote
FROM Order_Info, Client_Info, Material_Info
WHERE Order_Info.MateID = Material_Info.MateID
AND Order_Info.ClientID = Client_Info.ClientID
AND Order_Info.Date > '$StartDate'
AND Order_Info.Date < '$EndDate'
ORDER BY Order_Info.Date DESC;
";

$query = mysql_query($SearchByDate,$link);

echo "<div><table>";
echo "<tr><td>OrderID</td><td>Date</td><td>Client</td><td>Material Number</td><td>Material Name</td><td>Quantity</td><td>Weight</td><td>Technical Requirement</td><td>Unit Price</td><td>Total Price</td><td>Notes</td></tr>";

while($row = mysql_fetch_array($query)){
echo "<tr>";
echo "<td>".row['Order_Info.OrderID']."</td>";
echo "<td>".row['Order_Info.Date']."</td>";
echo "<td>".row['Client_Info.Manager']."</td>";
echo "<td>".row['Material_Info.MateRefNum']."</td>";
echo "<td>".row['Order_info.CustomMateName']."</td>";
echo "<td>".row['Order_Info.Quantity']."</td>";
echo "<td>".row['Order_Info.Weight']."</td>";
echo "<td>".row['Order_Info.TechRequire']."</td>";
echo "<td>".row['Order_Info.UniPrice']."</td>";
echo "<td>".row['Order_Info.TotPrice']."</td>";
echo "<td>".row['Order_Info.OtherNote']."</td>";
echo "</tr>";
}
echo "</table></div>";
?>

最佳答案

  1. 您的变量必须使用符号“$”,但您没有
  2. 您可以使用var_dump($row)来帮助您了解数组的结构

代码:

while($row = mysql_fetch_array($query)){
echo "<tr>";
echo "<td>".$row['OrderID']."</td>";
echo "<td>".$row['Date']."</td>";
echo "<td>".$row['Manager']."</td>";
echo "<td>".$row['MateRefNum']."</td>";
echo "<td>".$row['CustomMateName']."</td>";
echo "<td>".$row['Quantity']."</td>";
echo "<td>".$row['Weight']."</td>";
echo "<td>".$row['TechRequire']."</td>";
echo "<td>".$row['UniPrice']."</td>";
echo "<td>".$row['TotPrice']."</td>";
echo "<td>".$row['OtherNote']."</td>";
echo "</tr>";
}

关于php - 无法使用 php 从 mysql 获取数据到 html 表,显示内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20895754/

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