I want to be able to call the comment that users make on a picture on the same page as the pic. and when a different page comes up that comment for that pic is displayed also. I am able to that, but I can't seem to call the URL for that pic without changing the actual code.
开发者_JS百科<?
include.....
$picid = $_GET['picid'];
$query = mysql_query("SELECT * FROM pic_info WHERE picid = 'picid1' ");// problem
while($rows = mysql_fetch_assoc($query)):
$picid = $rows['picid'];
$title = $rows['title'];
$link = $rows['link'];
$description = $rows['description'];
$movie_pic = $rows['movie_pic'];
$source = $rows['source'];
endwhile;
$get_comment = mysql_query("SELECT * FROM comment WHERE picid ='$picid'");// work partially
$comment_count = mysql_num_rows($get_comment);
if ($comment_count>0)
{
while ($com = mysql_fetch_array($get_comment)){
$comment_id = $com['comment_id'];
$name = $com['name'];
$message = $com['message'];
$time_post= $com['time_post'];
$messages .= '<em> on ' .$time_post.'</em><b> '.$name.' said.....</b><br/> '.$message.'<hr/>';
}
?>
Problem: only works if I change picid1 to some thing else like picid2 or 3 or 4... work partially :: works when I change picid1 to some thing else like picid2 or 3 or 4... other than that it comes up saying no comment.
I'm not sure if the problem is at top, cant figure it out.
you are missing a $...
WHERE picid = '$picid'
Soemething like this:
$picid = $_GET['picid'];
$query = mysql_query("SELECT * FROM pic_info WHERE picid = '$picid' ");
To be in the safe side... I would actually do this
$picid = mysql_real_escape_string($_GET['picid']);
$query = mysql_query("SELECT * FROM pic_info WHERE picid = '$picid' ");
Why? Read here
BTW, if picid is a number type, I would omit the quotes...
WHERE picid = $picid
---- EDIT ------
if ($comment_count>0)
{
$messages = ""; //added this
while ($com = mysql_fetch_array($get_comment)){
$comment_id = $com['comment_id'];
$name = $com['name'];
$message = $com['message'];
$time_post= $com['time_post'];
$messages .= '<em> on ' .$time_post.'</em><b> '.$name.' said.....</b><br/>'.$message.'<hr/>';
}
} // added this...
?>
精彩评论