Witam,

Chcę wyświetlić komentarze tylko do odpowiedniego newsa. Sprawa byłaby prosta gdybym miał wszystko w jednym pliku, a tak nie wiem jak mam to zrobić.

Chcę, aby zapytanie miało formę "SELECT * FROM comments WHERE com_newsid = $newsid ORDER BY com_id DESC", ale nie wiem jak pobrać tą zmienną do tego pliku.

fetch.php
  1. <?php
  2. include_once('Addons/db.php');
  3.  
  4. $sql = "SELECT * FROM comments ORDER BY com_id DESC ";
  5. $res = mysql_query($sql);
  6. $result = array();
  7.  
  8.  
  9.  
  10. while( $row = mysql_fetch_array($res) )
  11. array_push($result, array('com_id' => $row[0],
  12. 'com_author' => $row[1],
  13. 'com_content' => $row[2],
  14. 'com_newsid' => $row[3],
  15. 'com_adate' => $row[4]));
  16.  
  17. echo json_encode(array("result" => $result));
  18. ?>



Skrypt
[JAVASCRIPT] pobierz, plaintext
  1. $(document).ready( function() {
  2. done();
  3. });
  4.  
  5. function done() {
  6. setTimeout( function() {
  7. updates();
  8. done();
  9. }, 200);
  10. }
  11.  
  12. function timeConverter(UNIX_timestamp){
  13. var a = new Date(UNIX_timestamp*1000);
  14. var months = ['01','02','03','04','05','06','07','08','09','10','11','12'];
  15. var year = a.getFullYear();
  16. var month = months[a.getMonth()];
  17. var date = a.getDate();
  18. var hour = a.getHours();
  19. var min = ("0" + a.getMinutes()).substr(-2);
  20. var sec = a.getSeconds();
  21. var time = date+'.'+month+'.'+year+', '+hour+':'+min+':'+sec ;
  22. return time;
  23. }
  24.  
  25.  
  26. function updates() {
  27.  
  28. $.getJSON("fetch.php", function(data) {
  29. $("d").empty();
  30.  
  31. $.each(data.result, function() {
  32.  
  33. $("d").append("<div><div id='l_comment'><img src='' width='50px' height='50px;'/></div>&nbsp<b><a href='../users/user.php?name="+this['com_author']+"' class='toprofile'>"+this['com_author']+"</a></b> napisał/a, <div style='float: right; margin-right: 12px;'>"+timeConverter(this['com_adate'])+"</div><div id='r_comment' style='margin-bottom: 10px;'>"+this['com_content']+"</div></div>");
  34.  
  35. });
  36. });
  37. }
[JAVASCRIPT] pobierz, plaintext


index.php
  1. <?php
  2. $result = mysql_query("SELECT * FROM `news` ORDER BY `news_id` DESC");
  3. while( $row = mysql_fetch_assoc( $result )) {
  4. ?>
  5. <div id="news">
  6. <div class="more-less">
  7. <div class="more-block">
  8. <p style="float: right; padding-bottom: 0px; margin-bottom: -5px;"><?=date('d.m.Y, H:m:s', $row['news_adate'])?></p>
  9. <p style="float: left; padding-bottom: 0px; padding-left: 0px; margin-bottom: -10px;"><b><?=$row['news_title']?></b></p>
  10. <p style="clear: both; padding-bottom: 0px; margin-bottom: -5px;"></p><hr>
  11. <div style="margin-top: 2px;">
  12. <div style="float: left;"><?php echo "<img src='../Addons/Uploads/".$row['news_image']."' width='158px' height='158px'>";?></div>
  13. <div style="float: left; width: 5px; height: 158px;"></div>
  14. <div style="text-indent: 25px;"><?=$row['news_content']?></div>
  15. <div style="clear: both;"></div>
  16. </div>
  17. </div>
  18. </div>
  19. <hr>
  20. <p style="text-align: right; padding-bottom: 0; padding-top: 0;">(0) <f_link><a href="java script:showonlyone('<?=$row['news_id'];?>')" style="cursor: pointer;">- komentarze - </a></f_link></p>
  21.  
  22. <div class="comments" id="<?=$row['news_id']?>">
  23. <?php
  24. $newsid = $row['news_id'];
  25. if($_SESSION['logged']) {
  26. $user_data = get_user_data();
  27. $author = $user_data['user_login'];
  28. ?>
  29. <div id="new_comment">
  30. Napisz komentarz:<br />
  31. <form class="newComment" action="newcomment.php" method="post">
  32. <input type="hidden" name="author" value="<?=$author;?>">
  33. <input type="hidden" name="newsid" value="<?=$newsid;?>">
  34. <div style="float: left;"><textarea name="comment" rows="2" cols="90" value="<?=$_POST['comment']?>"></textarea></div><div style="float: left;"><input type="submit" value="OK" style="width: 40px; height: 34px; margin-left: 3px;"/></div>
  35. <div style="clear: both;"></div>
  36. </form>
  37. </div>
  38.  
  39.  
  40. <?php
  41. } else { echo 'Zaloguj się, aby skomentować ten artykuł.'; };
  42. ?>
  43. <div id='showcomments'>
  44. <d></d>
  45. </div>
  46. </div>
  47. </div>
  48. <?php }; ?>


Z góry dziękuję za pomoc.