求php大神帮忙看下代码
<?php$con=mysql_connect("localhost","root","");if(!$con){die('Couldnotconnect:'.mysql...
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("skkd", $con);
$result = mysql_query("SELECT * FROM r_order");
echo "<table border='1'>
<tr>
<th>订单编号</th>
<th>顾客姓名</th>
<th>顾客电话</th>
<th>顾客人数</th>
<th>就餐时间</th>
<th>备注</th>
<th>菜品信息</th>
<th>总价</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['orderID'] . "</td>";
echo "<td>" . $row['user_name'] . "</td>";
echo "<td>" . $row['tel'] . "</td>";
echo "<td>" . $row['people'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['contract'] . "</td>";
echo "<td>" . $row['dinner_id'] . "</td>";
echo "<td>" . $row['total'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
数据库包括
r_order
r_food(food_id,food_name)
我打印出r_order中的数据,里面的dinner_id就是food里面的food_id,怎么把打印表里的dinner_id换成打印food_name 展开
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("skkd", $con);
$result = mysql_query("SELECT * FROM r_order");
echo "<table border='1'>
<tr>
<th>订单编号</th>
<th>顾客姓名</th>
<th>顾客电话</th>
<th>顾客人数</th>
<th>就餐时间</th>
<th>备注</th>
<th>菜品信息</th>
<th>总价</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['orderID'] . "</td>";
echo "<td>" . $row['user_name'] . "</td>";
echo "<td>" . $row['tel'] . "</td>";
echo "<td>" . $row['people'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['contract'] . "</td>";
echo "<td>" . $row['dinner_id'] . "</td>";
echo "<td>" . $row['total'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
数据库包括
r_order
r_food(food_id,food_name)
我打印出r_order中的数据,里面的dinner_id就是food里面的food_id,怎么把打印表里的dinner_id换成打印food_name 展开
3个回答
展开全部
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("skkd", $con);
$result = mysql_query("SELECT a.*,b.food_name FROM r_order a INNER JOIN r_food b on a.dinner_id = b.food_id");
echo "<table border='1'>
<tr>
<th>订单编号</th>
<th>顾客姓名</th>
<th>顾客电话</th>
<th>顾客人数</th>
<th>就餐时间</th>
<th>备注</th>
<th>菜品信息</th>
<th>总价</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['orderID'] . "</td>";
echo "<td>" . $row['user_name'] . "</td>";
echo "<td>" . $row['tel'] . "</td>";
echo "<td>" . $row['people'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['contract'] . "</td>";
echo "<td>" . $row['food_name'] . "</td>";
echo "<td>" . $row['total'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("skkd", $con);
$result = mysql_query("SELECT a.*,b.food_name FROM r_order a INNER JOIN r_food b on a.dinner_id = b.food_id");
echo "<table border='1'>
<tr>
<th>订单编号</th>
<th>顾客姓名</th>
<th>顾客电话</th>
<th>顾客人数</th>
<th>就餐时间</th>
<th>备注</th>
<th>菜品信息</th>
<th>总价</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['orderID'] . "</td>";
echo "<td>" . $row['user_name'] . "</td>";
echo "<td>" . $row['tel'] . "</td>";
echo "<td>" . $row['people'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['contract'] . "</td>";
echo "<td>" . $row['food_name'] . "</td>";
echo "<td>" . $row['total'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
更多追问追答
追问
菜名输出是 ???
追答
echo "" . $row['food_name'] . "";
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
展开全部
你要先将你的 $row 变成一个二维数组 之后再将所编辑的二维数组的键值变成以id开头的拿数据的时候可以用遍历拿出
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
直接把$row['dinner_id']改成$row['food_name']不就可以了吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询