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

标签 php mysql css

我有一个网站,有人在他们的位置搜索 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/

相关文章:

mysql - 如何过滤两列之间的一组数字?

css - 使子 div 文本内容不扩展其父固定位置 div 的宽度

html - 如何居中对齐表格

php - symfony symfony 演示

php - PyroCMS 导航栏中的三级导航

mysql - 如果存在则更新否则插入 csv 数据 MySQL

javascript - 使用 JavaScript 增加上/左/下/右值

php - 如何确保在一个下拉列表中选择的值将更改 Laravel 中另一个下拉列表的值

php - 隐藏下载网址

MySQL JOIN 盲目