PHP循环输出数据库数据只输出第一个结果
代码:$sql=mysql_query("select*fromaname",$conn);for($com=0;$com<3;$com++){$aid=mysql_re...
代码:
$sql=mysql_query("select * from aname",$conn);
for ($com=0;$com<3;$com++){
$aid=mysql_result($sql, $com,"aid");
$sql2="select photo from photo where aid=".$aid;
$img=mysql_query($sql2,$conn);
echo $sql2;
echo $img;
$url=mysql_result($img, $com,"photo");
echo $url;
结果:
select photo from photo where aid=2 Resource id #6 image/2.jpg
select photo from photo where aid=3 Resource id #7
select photo from photo where aid=4 Resource id #8 展开
$sql=mysql_query("select * from aname",$conn);
for ($com=0;$com<3;$com++){
$aid=mysql_result($sql, $com,"aid");
$sql2="select photo from photo where aid=".$aid;
$img=mysql_query($sql2,$conn);
echo $sql2;
echo $img;
$url=mysql_result($img, $com,"photo");
echo $url;
结果:
select photo from photo where aid=2 Resource id #6 image/2.jpg
select photo from photo where aid=3 Resource id #7
select photo from photo where aid=4 Resource id #8 展开
2个回答
展开全部
设定&value为取出值
<?php
$array = array(1, 2, 3, 4, 5, 6, 7);
foreach ($array as $value) {
?>
<tr>
<td><?php echo $value; ?></td>
</tr>
<?php
}
?>
<?php
$array = array(1, 2, 3, 4, 5, 6, 7);
foreach ($array as $value) {
?>
<tr>
<td><?php echo $value; ?></td>
</tr>
<?php
}
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询