php - 尝试将 MySql 数据库行转换为链接,以便用户可以选择他们想要查看的内容

标签 php html mysql

我正在构建一个网站,允许用户使用表单共享信息。该表单将输入发送到 MySQL 数据库,该数据库为每个类别都有一个包含 3 列的表。我希望能够允许用户选择一个类别,并且所有行都显示为链接,以便他们可以选择和查看。我创建了另一个页面来显示输入,但它只会显示 1 行信息。我做了一些关于存储整个表单的研究,但我读到存储文件不是一个好主意。我处于停滞状态,不知道下一步该做什么。任何人都可以推荐教程或对此有任何建议吗?这是我用来向用户显示信息的代码。

<?php
$connection = mysql_connect("localhost","root","")
or die("no connection");
$db_select=mysql_select_db("smqr",$connection)
or die("no connection to db");

$query= ("SELECT * FROM seafood");
$result=mysql_query($query)or die(mysql_error());

while
($row =mysql_fetch_array($result)):
 $recipe=$row['recipe'];
 $usrtext=$row['usrtext']; 
 $usrtxt=$row['usrtxt'];
 endwhile;
 ?>

 <body bgcolor="#ffccff">
<table align="center"  width="780" height="100%"  bgcolor="lightgrey" border="1">   
<thead>
</thead>
<tbody>
<tr>
<th height="220">
<img src="seafoods.jpg" width="100%" height="220" /></th></tr>
<tr>
<th><h3>Recipe Name</h3> <p align="left">
<?php echo "$recipe" ?></p></th></tr>
<tr>
<th><h3>Ingrediants and Measurements </h3>
<p align="left"><?php echo $usrtext ?></p></th></tr>
<tr>
<th><h3>Instructions </h3>
<p align="left"> <?php echo $usrtxt ?></p></th>
</tr>

谢谢

最佳答案

您需要将表格包装在 while 循环内以显示所有记录,并更好地使用 {} for while 循环。

while($row =mysql_fetch_array($result)){
$recipe=$row['recipe'];
$usrtext=$row['usrtext']; 
$usrtxt=$row['usrtxt'];
?>
<table align="center"  width="780" height="100%"  bgcolor="lightgrey" border="1">   
<thead>
</thead>
<tbody>
<tr>
.....
......
</tr>
</table>
<?php
 }
 ?>

关于php - 尝试将 MySql 数据库行转换为链接,以便用户可以选择他们想要查看的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20309278/

相关文章:

php - 如何将 session 值存储在另一个表中?

javascript - 在不同的 iframe 中共享/更改全局变量

MySQL分组显示零记录

php - 如何在弹出窗口中显示php mysql选择值

php - PDO 联合选择结果没有任何结果

php - 需要从多个具有动态用户 ID 的表插入产品表

javascript - 如何将生成的 javascript pdf 文件保存到服务器的文件系统?

html - 我如何创建背景为矩形的六边形?

javascript - 如何通过 selenium 驱动程序从 "<div class=' ui-helper-hidden-accessible'>"中提取选项?

php - 以 html 形式更新一个依赖于另一个表的表值