graham23s Posted May 10, 2007 Share Posted May 10, 2007 Hi Guys, i have made a very basic forum, i was going to make the posters names linkable to thier profiles but i'm having trouble with a query here it is: <?php // Query the second forum table...////////////////////////////////////////////////// $sql_2 = "SELECT * FROM `forum_replies` WHERE main_id='$id'"; $result_2 = mysql_query($sql_2); while($rows = mysql_fetch_array($result_2)) { $reply_id = $rows['reply_id']; $reply_message = $rows['reply_message']; // ANOTHER query to get the id.../////////////////////////////////////////////////// $query_id = "SELECT * FROM `membership` WHERE username='$reply_id"; $result_id = mysql_query($query_id); $rows = mysql_fetch_array($result_id); echo $reply_id; ?> <br /> <table width="80%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="10%" bgcolor="#F8F7F1"><p>Reply</td> <td width="60%" bgcolor="#F8F7F1"><p><?php echo $reply_message; ?></td> </tr> <tr> <td bgcolor="#F8F7F1"><p>Poster</td> <td bgcolor="#F8F7F1"><p><i>Posted By:</i> <font color="red"><?php echo $reply_id; ?></font></p></td> </tr> </table> <?php } when a user posts on the forum they're username is stored in "reply_id" e.g graham23s so i did this: $query_id = "SELECT * FROM `membership` WHERE username='$reply_id"; $result_id = mysql_query($query_id); to match up the username: graham23s with $reply_id but i keep getting Resource id #10 and 11 and so on, i don't seem to be getting the info from the query above, can anyone see any errors i have made? thanks guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/50861-solved-help-retrieving-info-from-mysql/ Share on other sites More sharing options...
cmgmyr Posted May 10, 2007 Share Posted May 10, 2007 Change $query_id = "SELECT * FROM `membership` WHERE username='$reply_id"; to $query_id = "SELECT * FROM `membership` WHERE username=$reply_id"; Quote Link to comment https://forums.phpfreaks.com/topic/50861-solved-help-retrieving-info-from-mysql/#findComment-250149 Share on other sites More sharing options...
per1os Posted May 10, 2007 Share Posted May 10, 2007 The query is correct, however you need to do this to get the data out: <?php $query_id = "SELECT * FROM `membership` WHERE username='$reply_id'"; $result = mysql_query($query_id); $row = mysql_fetch_assoc($result); // this will get the first row only. to get all rows do this: while ($row = mysql_fetch_assoc($result)) { $rows = $row; } echo '<pre>', print_r($rows), '</pre>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/50861-solved-help-retrieving-info-from-mysql/#findComment-250157 Share on other sites More sharing options...
cmgmyr Posted May 10, 2007 Share Posted May 10, 2007 he was missing the last ' in the query Quote Link to comment https://forums.phpfreaks.com/topic/50861-solved-help-retrieving-info-from-mysql/#findComment-250165 Share on other sites More sharing options...
per1os Posted May 10, 2007 Share Posted May 10, 2007 Yea, I saw that and fixed it, but your "correction" was incorrect in that anything going into a DB that contains letters should (maybe must) be enclosed in single quotes. Your correction omits the single quotes all together, which would throw an error =) Quote Link to comment https://forums.phpfreaks.com/topic/50861-solved-help-retrieving-info-from-mysql/#findComment-250168 Share on other sites More sharing options...
graham23s Posted May 10, 2007 Author Share Posted May 10, 2007 Nice one guys solved. Graham Quote Link to comment https://forums.phpfreaks.com/topic/50861-solved-help-retrieving-info-from-mysql/#findComment-250174 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.