用php回显mysql查询结果
我有这个查询,
$people = "SELECT name FROM people";
$people = mysql_query($people) or die(mysql_error());
$row_people = mysql_fetch_assoc($people);
$totalRows_people = mysql_num_rows($people);
我可以使用像这样的 while 循环来回显无序列表中的结果
<ul>
<?php {do { ?>
<li><?php echo $row_people['name'];?></li>
<?php } while ($row_people = mysql_fetch_assoc($people));}?>
</ul>
,但我不能使用它,因为我的 html 不允许它。
<ul>
<li class="first">
<a href="?name=kate">Kate</a>
<li>
<li class="second">
<a href="?name=john"><img src="john.jpg" />John</a>
<li>
<li class="third">
<a href="?name=max"><span>Max</span></a>
<li>
</ul>
我的问题是如何将从数据库检索到的名称回显到该 html 中的适当位置?
感谢您的帮助。
I have this query
$people = "SELECT name FROM people";
$people = mysql_query($people) or die(mysql_error());
$row_people = mysql_fetch_assoc($people);
$totalRows_people = mysql_num_rows($people);
I can echo the results within a unordered list using a while loop like this
<ul>
<?php {do { ?>
<li><?php echo $row_people['name'];?></li>
<?php } while ($row_people = mysql_fetch_assoc($people));}?>
</ul>
But I can't used this as my html does not allow it.
<ul>
<li class="first">
<a href="?name=kate">Kate</a>
<li>
<li class="second">
<a href="?name=john"><img src="john.jpg" />John</a>
<li>
<li class="third">
<a href="?name=max"><span>Max</span></a>
<li>
</ul>
My question is how can echo the name that was retrieved from the database into the appropriate place within this html?
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
您只需为每个“类型”的用户创建一个渲染器(假设您在用户行上有一个类型属性)或根据其属性创建一个渲染器。例如,假设您必须根据属性进行过滤:
这应该可以工作,但您现在将拥有index1、index2 等,而不是类名first、second 等。
You'll just have to create a renderer for each "type" of user (assuming you have a type property on the user rows) or based on their attributes. For example, let's say you're going to have to filter based on the attributes:
This should work, with the exception that instead of class names first, second, etc, you'll now have index1, index2, etc.