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条)

报告相同问题?

悬赏问题

  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类