dscojuxf69080 2010-09-10 18:24
浏览 90
已采纳

MySQL查询限制部分查询

I have a mysql query:

$result = mysql_query("SELECT * FROM $table WHERE cat = 'category'");

 while($row = mysql_fetch_array($result)) {
     echo '
     <hgroup><h3>'.$row['mag'].'</h3><h4>'.$row['date'].'</h4></hgroup>
     <a href="'.$row['href'].'" onclick="this.target=\'blank;\'">'.$row['title'].'</a>
          ';
   }

This query will generally select between 2 and 5 different rows and display them in a list.

I want the first echoed line to only appear once and the second line should appear between 2 and 5 depending on the data in my db.

I am sure there is a simple way to do this, I've tried GROUP BY mag but this will eliminate the remaining 1-4 pieces of data I wish to display.

  • 写回答

2条回答 默认 最新

  • douan2478 2010-09-10 19:53
    关注

    Not sure I understand your question, as the following solution seems too simple!

    $row = mysql_fetch_array($result);
    echo '<hgroup><h3>'.$row['mag'].'</h3><h4>'.$row['date'].'</h4></hgroup>
          <a href="'.$row['href'].'" onclick="this.target=\'blank;\'">'.$row['title'].'</a>';
     while ($row = mysql_fetch_array($result)) {
         echo '<a href="'.$row['href'].'" onclick="this.target=\'blank; \'">'.$row['title'].'</a>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作