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<?php
include_once('Addons/db.php');
$sql = "SELECT * FROM comments ORDER BY com_id DESC ";
'com_author' => $row[1],
'com_content' => $row[2],
'com_newsid' => $row[3],
'com_adate' => $row[4]));
echo json_encode
(array("result" => $result)); ?>
Skrypt$(document).ready( function() {
done();
});
function done() {
setTimeout( function() {
updates();
done();
}, 200);
}
function timeConverter(UNIX_timestamp){
var a = new Date(UNIX_timestamp*1000);
var months = ['01','02','03','04','05','06','07','08','09','10','11','12'];
var year = a.getFullYear();
var month = months[a.getMonth()];
var date = a.getDate();
var hour = a.getHours();
var min = ("0" + a.getMinutes()).substr(-2);
var sec = a.getSeconds();
var time = date+'.'+month+'.'+year+', '+hour+':'+min+':'+sec ;
return time;
}
function updates() {
$.getJSON("fetch.php", function(data) {
$("d").empty();
$.each(data.result, function() {
$("d").append("<div><div id='l_comment'><img src='' width='50px' height='50px;'/></div> <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>");
});
});
}
index.php<?php
$result = mysql_query("SELECT * FROM `news` ORDER BY `news_id` DESC"); ?>
<div id="news">
<div class="more-less">
<div class="more-block">
<p style="float: right; padding-bottom: 0px; margin-bottom: -5px;">
<?=date('d.m.Y, H:m:s', $row['news_adate'])?></p>
<p style="float: left; padding-bottom: 0px; padding-left: 0px; margin-bottom: -10px;"><b><?=$row['news_title']?></b></p>
<p style="clear: both; padding-bottom: 0px; margin-bottom: -5px;"></p><hr>
<div style="margin-top: 2px;">
<div style="float: left;">
<?php echo "<img src='../Addons/Uploads/".$row['news_image']."' width='158px' height='158px'>";?></div>
<div style="float: left; width: 5px; height: 158px;"></div>
<div style="text-indent: 25px;"><?=$row['news_content']?></div>
<div style="clear: both;"></div>
</div>
</div>
</div>
<hr>
<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>
<div class="comments" id="<?=$row['news_id']?>">
<?php
$newsid = $row['news_id'];
if($_SESSION['logged']) {
$user_data = get_user_data();
$author = $user_data['user_login'];
?>
<div id="new_comment">
Napisz komentarz:<br />
<form class="newComment" action="newcomment.php" method="post">
<input type="hidden" name="author" value="<?=$author;?>">
<input type="hidden" name="newsid" value="<?=$newsid;?>">
<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>
<div style="clear: both;"></div>
</form>
</div>
<?php
} else { echo 'Zaloguj się, aby skomentować ten artykuł.'; }; ?>
<div id='showcomments'>
<d></d>
</div>
</div>
</div>
<?php }; ?>
Z góry dziękuję za pomoc.