gpt4 book ai didi

php - 具有多个 Mysql 结果的交替 CSS 样式

转载 作者:行者123 更新时间:2023-11-29 05:46:24 26 4
gpt4 key购买 nike

我有一个网站,有人在他们的位置搜索 x 产品,该网站会返回结果列表。

if(isset($_POST['zip'])){
$qry="SELECT business_id FROM ".TBL_BUSINESS." WHERE zip LIKE '%".$_POST['zip']."%'";
$rs = mysql_query($qry);

$rec = array();

while(($row = mysql_fetch_array($rs)) !== FALSE ){
$rec[] = $row[0];
}

if(!empty($rec[0])){

echo "Products for this location<br/>";

foreach ($rec as $result)
{
$bid = $result;
$qry2 = "SELECT * FROM products WHERE business_id = '".$bid."'";
$rs2 = mysql_query($qry2);
$rec2 = mysql_fetch_array($rs2);
?>
<div class="norm">
<img src="admin/product/img/<?php echo $rec2['image']; ?>" height="40" width="40" />
<h3><a href="product.php?id=<?php echo $rec2['id']; ?>"><?echo $rec2['name'];?>&nbsp;&nbsp;<?php echo $rec2['prodvalue']?></a></h3>
<div class="prodlistMeta">
<a class='view' href="product.php?id=<?php echo $rec2['id']; ?>">View Product</a>
<a class="print" href="#">Print</a>
</div>
</div>
<?php
}
}
else
{
echo "No Product is added for this location";
}

}?>

交替 <div class="norm"> 的最佳方式是什么?与 <div class="alt">

最佳答案

保留一个计数器并使用它的值模 2 来确定类应该是“norm”还是“alt”。

 $rec2 = mysql_fetch_array($rs2);
$count++;
?>
<div class="<?php echo($count%2?"norm":"alt"); ?>">

关于php - 具有多个 Mysql 结果的交替 CSS 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1336528/

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