dongwei5740 2014-12-01 02:28
浏览 37
已采纳

PHP使用mysql_fetch_array填充表

Ok Before you tell me to use mysqli I am using the depreciated methods on purpose for a webapp lesson. I am not a student, this is not homework, it is to help me teach an understanding for web application security.

I cannot figure out why this wont work. Basically, All I want to do is create a page that takes the data from the mysql database and places it into a table as shown. At this point I am open to anything.

Thank you in advance.

 <html>
 <head><title>Untitled</title></head>
 <body>
  <h1>Weblog Example</h1>
 <dl>
 <?php
   mysql_connect("localhost","root","");
   mysql_select_db("blog1");
   $query ="SELECT entrytitle, entrytext,";
   $query.=" DATE_FORMAT(entrydate, '%M %d, %Y') AS entrydate";
   $query.=" FROM weblog ORDER BY entrydate DESC LIMIT 10";
   $result=mysql_query($query);
  
   ?>
   <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Title</strong></td>
<td width="75%" align="center" bgcolor="#E6E6E6"><strong>Entry</strong></td>
<td width="15" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>
  
<?php
  while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['entrytitle']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['entrytext']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['entrydate']; ?></td>
</tr>

<?php
}
?>

 </dl>
 </body>
</html>

Ok- made some minor edits- it now gives me 3 rows in the table but doesn't populate the data...

</div>
  • 写回答

3条回答 默认 最新

  • dtoaillwk759656786 2014-12-01 03:20
    关注

    Both your $query.= should read as $query .= that alone will be an issue and will not concatenate properly because of the missing space before the dots.

    You're also missing a </table> tag.

    Plus, make sure that short tags are set/on, otherwise do <?php echo $rows...
    instead of <? echo $rows....

    You should also check for possible query errors using:

    $result = mysql_query($query) or die(mysql_error());
    

    and using error reporting.

    Add error reporting to the top of your file(s) which will help find errors.

    <?php 
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    // rest of your code
    

    Sidenote: Error reporting should only be done in staging, and never production.



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

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据