2013-08-26 55 views
-1

我剛創建了我的數據庫請求系統的v.2。然而,由於某種原因,我有這種「階梯效應」,它打印出數據,但隨後一遍又一遍地重複打印,增加了字體的大小。這是什麼?!我的代碼:意外的文字大小循環數據庫時的樓梯效應

$query=$db->prepare("SELECT post_id, title, body, category FROM posts INNER JOIN categories ON categories.category_id"); 
    $query->execute(); 
    $query->bind_result($post_id, $title, $body, $category);  
while($query->fetch()):?> 
    <article> 
    <h2><?php echo $title?><h2> 
    <p><?php echo $body?></p> 
    <p2>Category:</p2><?php echo $category?> 
    <?php endwhile ?> 
    </article> 

你可以看到效果@http://wrya.x10host.com/highflyer/index.php 誰能幫我解決這個問題,並給我解釋一下我做錯了什麼?

+0

用於創意解讀的+1 – necromancer

+1

不應該關閉循環內的文章標籤嗎? – j08691

+0

當你有這樣的問題時,通過驗證器運行你的頁面總是一個好主意。 http://validator.w3.org/check?uri=http%3A%2F%2Fwrya.x10host.com%2Fhighflyer%2Findex.php&charset=%28detect+automatically%29&doctype=Inline&group=0 – j08691

回答

2

它有助於將</article>一行向上移動到while循環中嗎?像這樣:

$query=$db->prepare("SELECT post_id, title, body, category FROM posts INNER JOIN categories ON categories.category_id"); 
$query->execute(); 
$query->bind_result($post_id, $title, $body, $category);  
while($query->fetch()):?> 
    <article> 
     <h2><?php echo $title?></h2> 
     <p><?php echo $body?></p> 
     <p2>Category:</p2><?php echo $category?> 
    </article> 
<?php endwhile ?> 
+1

h2結束標記也是borked – mensi

+0

@mensi好點,錯過了。使用該修補程序更新我的代碼片段! – SilverSnake

1

究竟是一個p2標籤?

很確定這不是任何DOCTYPE中的有效HTML標記。查看問題的最簡單方法是在Firefox中查看源代碼,它將以紅色突出顯示任何未封閉的標籤,我會冒險猜測這是問題所在。

您的循環內還有許多開篇文章標籤,但結束標籤在外面。

+0

p2標籤 - Derp時刻,與h標記混淆:P固定 – tehX