php mysql结果没有显示

时间:2014-04-12 13:26:23

标签: php mysql

所以这是代码。它适用于我之前使用过的xampp 1.7。我现在正在使用最新版本的xampp。这可能是问题吗?我可以将数据插入数据库。但无法显示表格内的链接。它显示一个没有文字的空白栏。有人可以帮我这个吗?

     <?php 
     $host="localhost"; // Host name 
     $username="root"; // Mysql username 
     $password=""; // Mysql password 
     $db_name="phoenix_db"; // Database name 
     $tbl_name="questions"; // Table name 
     // Connect to server and select database. 
     mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
     mysql_select_db("$db_name")or die("cannot select DB"); 
     $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // ORDER BY id DESC is order         
     $result=mysql_query($sql); 
     ?> 
     <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
     <tr> 
     <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td> 
     <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Title</strong></td>
     <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td> 
     <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td> 
     <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td> 
     </tr> 
     <?php 
     // Start looping table row 
     while($rows=mysql_fetch_array($result))
     { 
     ?> 
     <tr> 
     <td bgcolor="#FFFFFF">
     <? 
     echo $rows['id']; 
     ?>
     </td> 
     <td bgcolor="#FFFFFF"><a href="viewq.php?id=<? echo $rows['id']; ?>">
     <? echo $rows['title']; ?></a>
     <BR>
     </td> 
     <td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td> 
     <td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td> 
     <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td> 
     </tr> 
     <?php 
     // Exit looping and close connection 
     } 
     mysql_close(); 
     ?> 

3 个答案:

答案 0 :(得分:0)

尝试调试代码..

使用此

while($rows=mysql_fetch_array($result))
{ 
echo "<pre>";
print_r ($rows);
echo "</pre>"; 
......
.....
}

答案 1 :(得分:0)

你好,请你试试这个

我刚刚更改了<? to <?php

并确保列名称和数据存在于数据库中。

<?php 
     $host="localhost"; // Host name 
     $username="root"; // Mysql username 
     $password=""; // Mysql password 
     $db_name="phoenix_db"; // Database name 
     $tbl_name="questions"; // Table name 
     // Connect to server and select database. 
     mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
     mysql_select_db("$db_name")or die("cannot select DB"); 
     $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // ORDER BY id DESC is order         
     $result=mysql_query($sql); 
     ?> 
     <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
     <tr> 
     <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td> 
     <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Title</strong></td>
     <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td> 
     <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td> 
     <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td> 
     </tr> 
     <?php 
     // Start looping table row 
     while($rows=mysql_fetch_array($result))
     { 
     ?> 
     <tr> 
     <td bgcolor="#FFFFFF">
     <?php 
     echo $rows['id']; 
     ?>
     </td> 
     <td bgcolor="#FFFFFF"><a href="viewq.php?id=<? echo $rows['id']; ?>">
     <?php echo $rows['title']; ?></a>
     <BR>
     </td> 
     <td align="center" bgcolor="#FFFFFF"><?php echo $rows['view']; ?></td> 
     <td align="center" bgcolor="#FFFFFF"><?php echo $rows['reply']; ?></td> 
     <td align="center" bgcolor="#FFFFFF"><?php echo $rows['datetime']; ?></td> 
     </tr> 
     <?php 
     // Exit looping and close connection 
     } 
     mysql_close(); 
     ?>

答案 2 :(得分:0)

  

改变      

&安培;在

 mysql_connect($host, $username, $password)or die("cannot connect"); 
 mysql_select_db($db_name)or die("cannot select DB"); 
  

删除“”

<?php 
 $host="localhost"; // Host name 
 $username="root"; // Mysql username 
 $password=""; // Mysql password 
 $db_name="phoenix_db"; // Database name 
 $tbl_name="questions"; // Table name 
 // Connect to server and select database. 
 mysql_connect($host, $username, $password)or die("cannot connect"); 
 mysql_select_db($db_name)or die("cannot select DB"); 
 $sql="SELECT * FROM ".$tbl_name." ORDER BY id DESC"; // ORDER BY id DESC is order         
 $result=mysql_query($sql); 
 ?> 
 <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
 <tr> 
 <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td> 
 <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Title</strong></td>
 <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td> 
 <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td> 
 <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td> 
 </tr> 
 <?php 
 // Start looping table row 
 while($rows=mysql_fetch_array($result))
 { 
 ?> 
 <tr> 
 <td bgcolor="#FFFFFF">
 <?php 
 echo $rows['id']; 
 ?>
 </td> 
 <td bgcolor="#FFFFFF"><a href="viewq.php?id=<?php echo $rows['id']; ?>">
 <?php echo $rows['title']; ?></a>
 <br>
 </td> 
 <td align="center" bgcolor="#FFFFFF"><?php echo $rows['view']; ?></td> 
 <td align="center" bgcolor="#FFFFFF"><?php echo $rows['reply']; ?></td> 
 <td align="center" bgcolor="#FFFFFF"><?php echo $rows['datetime']; ?></td> 
 </tr> 
 <?php 
 // Exit looping and close connection 
 } 
 mysql_close(); 
 ?>