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(); ?> Link to comment https://forums.phpfreaks.com/topic/223510-comments/ 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 Link to comment https://forums.phpfreaks.com/topic/223510-comments/#findComment-1155334 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 Link to comment https://forums.phpfreaks.com/topic/223510-comments/#findComment-1155339 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"'; Link to comment https://forums.phpfreaks.com/topic/223510-comments/#findComment-1155343 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 Link to comment https://forums.phpfreaks.com/topic/223510-comments/#findComment-1155354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.