开发者

how to make increase number in 2 foreach unite?

...
$count=1;
while ($row = mysql_fetch_array($result)){
    $result1 = mysql_query("SELECT something from something where name like %$row['name']% ");
    while ($data = mysql_fetch_array($result1)){
        echo $data[title];
        echo $count;
    }
    $count++
}

How do I increase a number in foreach united like this? First foreach result for a second query. Then make a count for all the results from 2ed foreach. My code caused

title1 1
title2 1
titl开发者_StackOverflow社区e3 2
title4 2
title5 2
title6 3

how to make

title1 1
title2 2
title3 3
title4 4
title5 5
title6 6

Thanks.


 while ($data = mysql_fetch_array($result1)){
    echo $data[title];
    echo $count;
    $count++;
  }

Basically put $count++ inside the nested while


If you don't want to reset $count for every $row, the code must be like that.

$count=1;
while ($row = mysql_fetch_array($result)){
    $result1 = mysql_query("SELECT something from something where name like %$row['name']% ");
    while ($data = mysql_fetch_array($result1)){
        echo $data[title];
        echo $count++;
    }
}

otherwise;

while ($row = mysql_fetch_array($result)){
    $count=1;
    $result1 = mysql_query("SELECT something from something where name like %$row['name']% ");
    while ($data = mysql_fetch_array($result1)){
        echo $data[title];
        echo $count++;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜