2013-05-06 57 views
-2

我寫了一個基本的循環在PHP中工作,我想要什麼,但現在我試圖添加一個鏈接,但無法獲得正確的語法和我發現語法不起作用的例子對我而言,不斷收到錯誤。如果任何人都可以告訴我我錯誤的地方,那將是驚人的。預先感謝您是否能夠提供幫助!使用php鏈接語法錯誤

所引發錯誤的代碼是

<a href=\"addcomment.php?id="'. $row['postid'] .'\">' "Add Comment" '</a>"); 

和完整的代碼。

<?php 
    include("connect.php"); //connect to database 
    //create query 
    $get_messages_query = $db->prepare(" 
     SELECT * FROM `blogposts` 
     ORDER BY `postid` DESC 
     LIMIT 5 
     "); 
    //Homepage should have last 5 blog posts this will take the //last 5 entered into the database and put them into an //array 

    $get_messages_query->execute(); 
    //executes query above 

    while($row = $get_messages_query->fetch()) 
    { 
     $blog_post_history .= 
     '<div class="post" id="post"> 
      <h1>'. $row['title'] .' </h1> 
      <h2>' . $row['author'] . '</h2> 
      <p>'. $row['content'] . '</p> 
      <a href=\"addcomment.php?id="'. $row['postid'] .'\">' "Add Comment" '</a>"); 

     </div>'; 
    } 

    // while loop that takes info from db query and puts the //information in its own div with title andauthor having a //unique heading for css as well as a p for the content of //the blog. This loop puts the information in //$blog_post_history which is called upon in the div code 
    //below 
?> 
+1

PDO有絕對無關,與任何鏈接或HTML。 – 2013-05-06 05:27:57

回答

1

有問題的報價在這裏

$blog_post_history .= 
    '<div class="post" id="post"> 
     <h1>'. $row['title'] .' </h1> 
     <h2>' . $row['author'] . '</h2> 
     <p>'. $row['content'] . '</p> 
     <a href="addcomment.php?id='. $row['postid'] .'">Add Comment</a> 
    </div>'; 
+1

+1給你謝謝。 – ncm 2013-05-06 05:36:31

+1

真棒謝謝你!沒有睡得很寂寞,我知道我想要做什麼,但語法正在殺死我! – Chris 2013-05-06 05:36:54

0
while($row = $get_messages_query->fetch()) 
{ 
    $blog_post_history .= 
    '<div class="post" id="post"> 
     <h1>'. $row['title'] .' </h1> 
     <h2>' . $row['author'] . '</h2> 
     <p>'. $row['content'] . '</p> 
     <a href="addcomment.php?id='. $row['postid'] .'"> Add Comment </a> 
    </div>'; 
}