dourui9570 2013-01-31 11:51
浏览 33

php博客不会显示前2个数据库行

I'm working on my own simple blog. I got it working so far only 1 very irritating bug remaining. If I have 4 rows of data in my databse the first 2 (with the lowest ID) won't show up. So if I add a new 3rd row only the first row will pop-up my screen and it will take 2 new posts before the 3rd row will show up. If I turn around the sequence of ID's it does work if I have 2 useless posts in my database. But ofcourse I want the higher id's to show on top.

Here is the code for putting the database info on the screen:

<?php
require('config.inc.php');
require('template.inc.php');
require('functions.inc.php');
include_once('insert.php');

$query="SELECT * FROM blog ORDER BY ID DESC";
$result=mysql_query($query);

$db_field = mysql_fetch_assoc( $result );
mysql_fetch_assoc( $result );

mysql_close();

htmlOpenen('ServerSideBlog');
while ($db_field = mysql_fetch_assoc($result) ) {
echo'
<span class="post">
    <h1>'.$db_field['title'].'</h1>
    <h2>'.$db_field['date'].'</h2>
    <p>'.$db_field['contents'].'</p>
    <h3>Hoogachtend, Sincerely, Aufrichtig, sinceramente,</h3>
    <h4>'.$db_field['author'].'</h4>
';
}
htmlSluiten();
?>

And here the code for adding the posts in the database:

<?php
$db_host = "db.jxxxxx.com";
$db_username = "md2xxxx230";
$db_pass = "J9xxxx58";
$db_name = "md2xxxxx230";

@mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to      mysql");
@mysql_select_db("$db_name") or die ("no database");

if ($_POST['parse_var'] == "new"){

    $title=$_POST['title'];
    $contents=$_POST['contents'];
    $author=$_POST['author'];
    $date=$_POST['date'];
    $date = strftime("%b %d, %y", strtotime($date));

    $sqlcreate = mysql_query("INSERT INTO blog (date, title, contents, author)
            VALUES(now(),'$title','$contents','$author')");
}

?>

I can't find any solution for the problem... Hope I can get some awnsers here :)

  • 写回答

2条回答 默认 最新

  • dsdt66064367 2013-01-31 11:55
    关注

    why did you put this before while loop ?

    $db_field = mysql_fetch_assoc( $result );
    mysql_fetch_assoc( $result );
    
    mysql_close(); 
    

    and secondly you have close the mysql connection before -

    while ($db_field = mysql_fetch_assoc($result)
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度