ananaz Posted January 5, 2011 Share Posted January 5, 2011 Hello im trying to make a comment feature by having a link under my pictures kommentar.php?link=1 Then use the link=1 to see what comments that should be taken from the database. The comments have a linkid like this Linkid: Text: 1 a comment on first picture 1 another comment on first picture 2 a comment on second picture 2 another comment on second picture But i can't get my php to echo all the comments with the linkid of for example 1 without having to get them all separately. This is my script: <?php ob_start(); $host="localhost"; $username="****"; $password="******"; $db_name="db"; $tbl_name="comment"; mysql_connect($host, $username, $password)or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $linkid=filter_input(INPUT_GET,'link'); $sql="SELECT * FROM $tbl_name WHERE linkid='$linkid'"; $result=mysql_query($sql); $grejs=null; while(mysql_fetch_row($result)){ $grejs.="$row[0]"; } echo $grejs; ob_end_flush(); ?> Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted January 5, 2011 Share Posted January 5, 2011 <?php $host="localhost"; $username="****"; $password="******"; $db_name="db"; $tbl_name="comment"; mysql_connect($host, $username, $password)or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $linkid=filter_input(INPUT_GET,'link'); $sql="SELECT * FROM $tbl_name WHERE linkid='$linkid'"; $result=mysql_query($sql); $row = mysql_fetch_assoc($result); $grejs=null; do { $grejs.="$row[0]"; } while(mysql_fetch_row($result)); echo $grejs; ?> Give that a try Quote Link to comment Share on other sites More sharing options...
ananaz Posted January 5, 2011 Author Share Posted January 5, 2011 It did not work i don't know what i am doing wrong Quote Link to comment Share on other sites More sharing options...
xox Posted January 5, 2011 Share Posted January 5, 2011 Try with different quotes, It worked for me. $sql='SELECT * FROM $tbl_name WHERE linkid="$linkid"'; Quote Link to comment Share on other sites More sharing options...
ananaz Posted January 5, 2011 Author Share Posted January 5, 2011 YES! i solved it!! $linkid=filter_input(INPUT_GET,'link'); //WHERE linkid=$linkid $result=mysql_query("SELECT text FROM $tbl_name ",$dbc); while($row=mysql_fetch_row($result)){ echo "$row[0]<br>"; for others who wonder Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.