首先,我为我糟糕的英语技巧道歉
我的ecommarce有一个动态滑块。但我的链接标题有问题。我需要从1到9生成数字或新的id,并将它们作为图像的数字或新ID。
这是我的代码。
$sqlslide= mysql_query("SELECT * FROM products ORDER BY date_add DESC LIMIT 9");
$count2 = mysql_num_rows($sqlslide);
if($count2 > 0){
while($row = mysql_fetch_array($sqlslid)){
$id = $row['id'];
$name = $row['name'];
$description = $row['description'];
$source = "products/$id.jpg";
$img = '<img src="'.$source.'" class="photo" alt="temp">';
$slide1 .=' <div class="panel" title="'.$id.'">
<div class="wrapper">
'.$img.'
<div class="photo-meta-data">
'.$name.$id.' <br />
"'.$descriotion.'
</div>
</div>
</div>
';
$img2 = '<img src="'.$source.'" class="nav-thumb" alt="temp-thumb">';
$nav_thumb .='
<div><a href="'.$id.'" class="cross-link">'.$img2.$id.'</a></div>
'
;
}
我需要替换标题中的'.$id.'
以及
$slide1 .=' <div class="panel" title="'.$id.'">
<a href="'.$id.'" class="cross-link">'.$img2.'</a>
所以问题是,我如何使用while,do或for循环生成新数字或id并用它替换'.$id.'
?
感谢名单
答案 0 :(得分:0)
$sqlslide= mysql_query("SELECT * FROM products ORDER BY date_add DESC LIMIT 9");
$count2 = mysql_num_rows($sqlslide);
if($count2 > 0){
$index=0;
while($row = mysql_fetch_array($sqlslid)){
$id = $row['id'];
$name = $row['name'];
$description = $row['description'];
$source = "products/$id.jpg";
$img = '<img src="'.$source.'" class="photo" alt="temp">';
$slide1 .=' <div class="panel" title="'.$index.'">
<div class="wrapper">
'.$img.'
<div class="photo-meta-data">
'.$name.$id.' <br />
"'.$descriotion.'
</div>
</div>
</div>
';
$img2 = '<img src="'.$source.'" class="nav-thumb" alt="temp-thumb">';
$nav_thumb .='
<div><a href="'.$index.'" class="cross-link">'.$img2.$id.'</a></div>
'
...
$index++;
} // end while
}
编辑1:
生成递增数字的概念:
$index=0;
while($index<9) // incremented numbers till 9
{
echo $index;
$index++;
}
答案 1 :(得分:0)
$no = 1;
while($row = mysql_fetch_array($sqlslid))
{
//do something.
$no++;
if($no > 9)
{
$no = 1;
}
}