dongsimu4422 2009-08-26 18:09
浏览 59
已采纳

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

I've got a site where someone searches for x product in their location and the site spits back a list of results.

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";
}

} ?>

What would be the best way to alternate <div class="norm"> with <div class="alt">?

  • 写回答

6条回答 默认 最新

  • drvlf9739 2009-08-26 18:11
    关注

    keep a counter and use it's value modulo 2 to determine whether the class should be "norm" or "alt".

     $rec2 = mysql_fetch_array($rs2);
     $count++;
       ?>
          <div class="<?php echo($count%2?"norm":"alt"); ?>">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)