2013-10-21 10 views
0

當前我正在嘗試使用CodeIgniter以在用戶輸入後顯示評論或帖子,並且在不刷新頁面的情況下顯示它。CodeIgniter - 從MySQL中檢索數據並在不刷新頁面的情況下進行顯示

我一直在尋找答案几天,我仍然無法爲我的項目得到任何合適的答案。

不好意思說我還在使用CodeIgniter和JQuery。因爲這個項目的目標是希望我們學習新的編程語言。

這是我認爲的代碼,我提取主代碼

<?php 
    foreach ($comment as $comments) { 
     if ($comments['PostID'] == $stickynote['PostID']) { 
?> 
<div style="background-color: lightblue; border-radius: 5px 5px 5px 5px; margin-bottom: 5px; width: 70%; height: 80px"> 
    <a class="pull-left" href="#"> 
     <!-- Profile Picture --> 
     <img style='margin-top: 9px; margin-left: 5px; border-radius: 5px; padding-left: 5px;' class="media-object" id="sub-photo" src="../../images/<?php echo $profile ?>" alt="<?php echo $profile ?>" alt="..."> 
    </a> 
    <div class="media-body"> 
     <!-- Display Username --> 
     <h4 class="media-heading"><?php echo $comments['FirstName'] ?></h4> 
     <p style="width: 500px; word-wrap:break-word;"> 
     <?php echo $comments['Description'] ?> 
     </p> 
    </div> 
</div> 
<?php 
    } <!-- End of IF statement --> 
} <!-- End of FOR LOOP --> 
?> 

這是我的控制器

這是我的模型

public function readComment($studentID) { 

    $this -> db -> select('PostID, Description, FirstName, LastName, PostTime, Image'); 
    $this -> db -> from('Comment'); 
    $this -> db -> join('CollegeUser', 'CollegeUser.StudentID = Comment.StudentID'); 
    $this -> db -> join('PhotoGallery', 'PhotoGallery.PhotoID = CollegeUser.PhotoID'); 
    $this -> db -> order_by("Comment.PostTime", "desc"); 

    return $this -> db -> get() -> result_array(); 
} 

感謝您的誰幫助我。歡呼。

+1

由用戶輸入??你的表單在哪裏,用戶可以輸入評論? – bipen

+0

學習'Ajax'第一個隊友,這裏有一些鏈接:1)http://www.w3schools.com/ajax/,2)http://api.jquery.com/category/ajax/ –

+0

@Bipen,實際上是一個form_open()在那裏。但我沒有展示出來。抱歉。 – Blackie

回答

0

要提交沒有刷新的表單,您將需要使用ajax。

是這樣的:

$("form").on("submit", function(){ 
    $.post("submit.php", $(this).serialize(), function(){ 
    ..your code to display comments/post.. 
    }); 
return false; 
}); 

顯示評論的部分/職位是完全取決於你,你可以做的另一種AJAX來查詢服務器,如果你」獲取後,或者只是輸出$("textarea").val();懶惰。

+0

謝謝。我會馬上嘗試。 – Blackie

相關問題