dongyouzhi7218 2014-08-14 11:44
浏览 118
已采纳

SELECT * FROM没有在MySQL表中获取第一行

I'm not certain if this is a bug or a stupid error on my part, but I'd like to display a list of plays and theatrical performances from a database.

I can get it to display from row/entry 2 downwards fine - but it won't display the first row at all. Where there is only one entry, nothing is displayed. I've tried altering the id's of each, but it seems to just be the first one entered that isn't picked up, but ones entered after are.

The code to display the table is below.

<?php
$con = mysql_connect("localhost"," me "," mypass word");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

  mysql_select_db(" database name", $con);

  $data = mysql_query("SELECT * FROM table") 
 or die(mysql_error());
 $info = mysql_fetch_array( $data );

 while($info = mysql_fetch_array( $data )) 
 {
 Print "<tr><td style='background-color: #D3D3D3;  '>";
 Print " ".$info['title'] . " ";
 Print "</td>";

...etc...

   Print "</td> </tr>";
 } 

?>
    </table>

It seems quite simple but I can't figure it out at all. Any help much appreciated.

  • 写回答

6条回答 默认 最新

  • dongyi0210 2014-08-14 11:45
    关注

    remove this line

     $info = mysql_fetch_array( $data );
    

    you are using it twice. above and in while loop

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入