gpt4 book ai didi

php - 移动mysql_fetch_array指针

转载 作者:行者123 更新时间:2023-11-29 08:51:47 24 4
gpt4 key购买 nike

如何在 while 循环中间移动 mysql_fetch_array 指针?像这样的东西:

 while ($subject = mysql_fetch_array($subject_qry))
{
$output = "<div class=\"left\" id=\"{$subject['id']}\"></div>";
next($subject);
$output = "<div class=\"right\" id=\"{$subject['id']}\"></div>";
return $output;
}

最佳答案

这个怎么样:

$counter = 0;
while ($subject = mysql_fetch_array($subject_qry))
{
if ($counter % 2 == 0)
{
$output = "<div class=\"left\" id=\"{$subject['id']}\"></div>";
}
else
{
$output = "<div class=\"right\" id=\"{$subject['id']}\"></div>";
}
// do something with $output here...
$counter ++;
}

或者您可以使用 bool 值获得相同的结果:

$left = true;
while ($subject = mysql_fetch_array($subject_qry))
{
if ($left)
{
$output = "<div class=\"left\" id=\"{$subject['id']}\"></div>";
}
else
{
$output = "<div class=\"right\" id=\"{$subject['id']}\"></div>";
}
// do something with $output here...
$left = !$left;
}

关于php - 移动mysql_fetch_array指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10971913/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com