在我的数据库中,在名为 portfolio 的表格中更具体,具有特定用户名的用户可以存储多个数据。数据库的列为 id ,用户名,投资组合和 portfolio_description
我希望在我的网页中回显此用户名的所有数据,例如username = nbourlai。到目前为止,我只能回显每个用户名的第一行。我可以使用的循环是什么循环,以便回显多少时间是id号。 下面是当前的结果,我想创建投资组合和投资组合描述,以便与特定用户的最高ID号一起显示适当的值。
这是我的代码......
$portfolio = queryMysql("SELECT portfolio,portfolio_description FROM portfolio WHERE username='nbourlai'");
$row = mysql_fetch_row($portfolio);
echo "<h2>Portfolio</h2>";
echo "Portfolio: ";
echo stripslashes($row[0]) . "<br/>Portfolio Description: ";
echo stripslashes($row[1]) . "<br clear=left /><br />";
你能帮我吗?
答案 0 :(得分:1)
您是否正在寻找像这样的while循环?
$portfolio = queryMysql("SELECT portfolio,portfolio_description FROM portfolio WHERE username='nbourlai'");
echo "<h2>Portfolio</h2>";
while($row = mysql_fetch_row($portfolio)){
echo "Portfolio: ";
echo stripslashes($row[0]) . "<br/>Portfolio Description: ";
echo stripslashes($row[1]) . "<br clear=left /><br />";
}
或者,像这样?
$portfolio = queryMysql("SELECT username,portfolio,portfolio_description FROM portfolio ORDER BY username");
$username = '';
while($row = mysql_fetch_row($portfolio)){
if($username != $row[0]){
echo "<h1>".$row[0]."</h1>";
echo "<h2>Portfolio</h2>";
echo "Portfolio: ";
echo stripslashes($row[1]) . "<br/>Portfolio Description: ";
echo stripslashes($row[2]) . "<br clear=left /><br />";
}else{
echo "Portfolio: ";
echo stripslashes($row[1]) . "<br/>Portfolio Description: ";
echo stripslashes($row[2]) . "<br clear=left /><br />";
}
$username = $row[0];
}