douchen1924 2012-10-07 17:48
浏览 69

while循环不起作用时,只显示一个结果

Having a bit of trouble with a do wile loop not looping.. There are currently 2 results in the SQL that should be returned but it only shows one.

SQL. - the two results it should find

array('bid'=>4,'bname'=>'fdsfsdaf','section'=>'Network','btype'=>'Activity','breq'=>'fdsfsd','bnotes'=>'fdsfdsf','image'=>'Badges/Network/2inchsquare.png'),
  array('bid'=>3,'bname'=>'Test','section'=>'Network','btype'=>'Activity','breq'=>'dfsfds','bnotes'=>'fsdfs','image'=>'Badges/Network/2inchsquare.png')
);

My PHP

<?php
require_once('inc/global.php');
include('inc/auth.php');
mysql_select_db($dbname, $db);
$sql = "SELECT * FROM badges WHERE section = 'Network'";
$result = mysql_query($sql, $db) or die(mysql_error());
$bnetwork = mysql_fetch_assoc($result);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin</title>
<link href="css/admin.css" type="text/css" rel="stylesheet" media="screen,projection" />
</head>
<body>
<div id="listtable">

<table class="contacts">
        <tr>
            <td class="contactDept" width="20%">Badge Name</td>
            <td class="contactDept" width="20%">Section</td>
            <td class="contactDept" width="20%">Badge Type</td>
            <td class="contactDept" width="20%">Pic</td>
            <td class="contactDept" width="10%">Edit</td>
            <td class="contactDept" width="10%">Del</td>
        </tr>
</table>
<?php do { ?>       
        <ul>
            <li class="badgeName"><?php echo $bnetwork['bname']; ?></li>
            <li class="badgeSection"><?php echo $bnetwork['section']; ?></li>
            <li class="badgeType"><?php echo $bnetwork['btype']; ?></li>
            <li class="badgePic"><img src="<?php echo $bnetwork['image'];?>" width="30px" height="30px"></li>
            <li class="badgeEdit"><a href="#">Edit</a></li>
            <li class="badgeDel"><a href="#">Del</a></li>
        </ul>

<?php } while($bnetwork = mysql_fetch_assoc($result)); ?>
</div>
</body>
</html>

I know the table shouldnt be in LI tags, i was just trying just in case it didn't like TD tags for some unknown reason. Please tell me if you can work out why it only shows one result.

  • 写回答

1条回答 默认 最新

  • dongzhuo3376 2012-10-07 17:59
    关注

    The while loop should be adequete. Also you don't need echo and the ';' when just displaying a variable in your HTML. You can just use an '=' to mean echo when it immediately follows an opening php tag. I hope this helps.

    <? while($n = mysql_fetch_assoc($result)) { ?>
            <ul>
                <li class="badgeName"><?=$n['bname']?></li>
                <li class="badgeSection"><?=$n['section']?></li>
                <li class="badgeType"><?=$n['btype']?></li>
                <li class="badgePic"><img src="<?=$n['image']?>" width="30px" height="30px"></li>
                <li class="badgeEdit"><a href="#">Edit</a></li>
                <li class="badgeDel"><a href="#">Del</a></li>
            </ul>
    <? } ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!