php 循环套 重复,php 循环套循环 出现重复数据

php 循环套循环 出现重复数据0

02ae427d08e371d7e90d5b995e828d6d.pngpangmeng2015.07.13浏览43次分享举报

$qu=mysql_query("select * from user where id=".$row['id]."");//用户 $rowss=mysql_fetch_array($qu); while ($row=mysql_fetch_array($rowss) { 第一个小循环 $squ=mysql_query("select * from shop where id=".$row['id]."");//用户 $rows=mys... $qu=mysql_query("select * from user where id=".$row['id]."");//用户

$rowss=mysql_fetch_array($qu);

while ($row=mysql_fetch_array($rowss) {

第一个小循环

$squ=mysql_query("select * from shop where id=".$row['id]."");//用户

$rows=mysql_fetch_array($squ);

while ($row=mysql_fetch_array($rows) {

$shop .=$row['name'];

}

echo $user.$shop.;

}

这样取出数据时有的出现了重复

比如

id 1 取出1小循环里的 111 222 333 444 值

id 2 取出2小循环里的 555 666 777 888值

id 3 取出3小循环里的 5a 6a 7a 8a值

这是对的。但有的ID上会出现

id 1 取出了111 222 333 444

id 2 取出了111 222 333 444 555 666 777 888

id 3 取出了5a 6a 7a 8a值这个正常

哪里出错? 展开 发现小循环里的id有时不随大循环读出的值变化而变化

外循环

$rowss=mysql_fetch_array(mysql_query("select * from user "));

while ($row=mysql_fetch_array($rowss) {

里循环

$rows=mysql_fetch_array(mysql_query("select * from shop where id=".$row['id].""));

while ($row=mysql_fetch_array($rows) {

$shop .=$row['name']; //数组

}

echo $user.$shop.;//取出数据

}

这样会不会清楚点? 百度了一下原因是 每循环一个分类,就被加入新的值,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值