Ashoar Posted April 10, 2009 Share Posted April 10, 2009 I have this small piece of code here that i cannot get to work properly. I have 2 tables that i need to retrieve information from. The first is a table that holds posts and replies while the second is the user data holding all the membership details. What i need to do is fetch all of the post information along with the author of the post so that i can display it. This works perfectly. I then need to grab the post count of the user who posted so i can display it. I need to somehow fetch the postcount of the username where username is the same as the author of the post. I tried adding variable into the MYSQL query but it would not work and just output an "S" next to posts. Here is the piece of code: $gettopic="SELECT * from post_reply where postid='$id'"; $gettopic2=mysql_query($gettopic) or die("Could not get topic"); $gettopic3=mysql_fetch_array($gettopic2); $postcount="SELECT postcount from Users where Username=$gettopic[author]"; print "<tr class='mainrow'><td valign='top'><p><A href='member_profile.php?username=$gettopic3[author]'>$gettopic3[author]</a></p><p>Posts: $postcount[postcount]</p></td><td vakign='top'>Last replied to at $gettopic3[showtime]<br><hr>"; Anyone know how i can do this? Quote Link to comment https://forums.phpfreaks.com/topic/153438-solved-fetch-data-using-a-query-and-variable/ Share on other sites More sharing options...
cloudy243 Posted April 10, 2009 Share Posted April 10, 2009 that should work, what error do u get when you open the page. Also have you selected the db and have you connected? Quote Link to comment https://forums.phpfreaks.com/topic/153438-solved-fetch-data-using-a-query-and-variable/#findComment-806173 Share on other sites More sharing options...
Ashoar Posted April 10, 2009 Author Share Posted April 10, 2009 Yes the database's are all included above. It all works, except instead of displaying the post count it shows an "S". So there is no error that displays, it just shows an s instead of post count. I know that the posts work because i have them displayed in the users profile, but that was easy as all i needed to do was fetch the user name from the URL of the users profile. Quote Link to comment https://forums.phpfreaks.com/topic/153438-solved-fetch-data-using-a-query-and-variable/#findComment-806175 Share on other sites More sharing options...
cloudy243 Posted April 10, 2009 Share Posted April 10, 2009 ok i think i see problem now. dont you need to have it run the query for $postcount so $gettopic="SELECT * from post_reply where postid='$id'"; $gettopic2=mysql_query($gettopic) or die("Could not get topic"); $gettopic3=mysql_fetch_array($gettopic2); $postcount="SELECT postcount from Users where Username=$gettopic[author]"; $postcount2=mysql_query($postcount) or die("Could not get postcount"); $postcount3=mysql_fetch_array($gettopic2); print "<tr class='mainrow'><td valign='top'><p><A href='member_profile.php?username=$gettopic3[author]'>$gettopic3[author]</a></p><p>Posts: $postcount3[postcount]</p></td><td vakign='top'>Last replied to at $gettopic3[showtime]<br><hr>"; try having it run that Quote Link to comment https://forums.phpfreaks.com/topic/153438-solved-fetch-data-using-a-query-and-variable/#findComment-806177 Share on other sites More sharing options...
mmarif4u Posted April 10, 2009 Share Posted April 10, 2009 Yup, the above should work. i was posting this for you. But cloudy243 won here. Quote Link to comment https://forums.phpfreaks.com/topic/153438-solved-fetch-data-using-a-query-and-variable/#findComment-806178 Share on other sites More sharing options...
Ashoar Posted April 10, 2009 Author Share Posted April 10, 2009 That just gives an error when outputting. "Could not get postcount" Quote Link to comment https://forums.phpfreaks.com/topic/153438-solved-fetch-data-using-a-query-and-variable/#findComment-806180 Share on other sites More sharing options...
mmarif4u Posted April 10, 2009 Share Posted April 10, 2009 Change this line: $postcount3=mysql_fetch_array($gettopic2); to: $postcount3=mysql_fetch_array($postcount2); and try... Quote Link to comment https://forums.phpfreaks.com/topic/153438-solved-fetch-data-using-a-query-and-variable/#findComment-806181 Share on other sites More sharing options...
Ashoar Posted April 10, 2009 Author Share Posted April 10, 2009 No joy, still displays the MYSQL error "Could not get postcount". Quote Link to comment https://forums.phpfreaks.com/topic/153438-solved-fetch-data-using-a-query-and-variable/#findComment-806185 Share on other sites More sharing options...
mmarif4u Posted April 10, 2009 Share Posted April 10, 2009 Hope this change will help. Change this: $postcount="SELECT postcount from Users where Username=$gettopic[author]"; to: $postcount="SELECT postcount from Users where Username='$gettopic3[author]'"; Quote Link to comment https://forums.phpfreaks.com/topic/153438-solved-fetch-data-using-a-query-and-variable/#findComment-806187 Share on other sites More sharing options...
Ashoar Posted April 10, 2009 Author Share Posted April 10, 2009 Ah simple mistake. It works perfectly now Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/153438-solved-fetch-data-using-a-query-and-variable/#findComment-806190 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.