andrew_biggart Posted March 8, 2009 Share Posted March 8, 2009 Can anyone hep please? apologys for the double post but ive just realised i have posted it in the wrong section. But basiclly what i am trying to is first off al posts and info from the post table, then i want to get all the users that made a post eg $rows post_user and use this info to add to a select statement which wil then be used to slect the user_info table and select all rows where username=$rows post_user and then display prfoile_pic beside the post. Im using the folowing code but the image part is not working. <?php include("config_blog.php"); // Retrieve data from database $sql="SELECT * FROM User_postT ORDER BY Post_id DESC LIMIT 30" ; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ // Retrieve data from database $sql2="SELECT * FROM User_infoT WHERE username=$rows Post_username" ; $result2=mysql_query($sql2); // Start looping rows in mysql database. while($rows2=mysql_fetch_array($result2)){ ?> <table class="profileforum"> <tr><td style="width: 55px"><? echo "<img src='../Thumbnail_images/". $rows2['Profile_picture'] . "' style='width:50px; height:50px;' />";?></td> <td> <table class="forum_post" cellspacing="0" cellpadding="0" style="width: 345px; height: 52px"> <tr><td class="forum_sub">Posted by <a class="posts1" href="profile.php?username=<? echo $rows['Post_username']; ?>"><? echo $rows['Post_username']; ?></a> on <? echo $rows['Post_date']; ?></td></tr> <tr><td class="forum_h" valign="top"><a class="posts2" href="view_topic.php?Post_id=<? echo $rows['Post_id']; ?>"><? echo $rows['Post_subject']; ?></a></td></tr> </table> </td></tr> </table> <? // close while loop } // close connection mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/148505-problems-with-the-a-double-select-statement/ Share on other sites More sharing options...
kickstart Posted March 8, 2009 Share Posted March 8, 2009 Hi You can do it with a table join. However not sure what you want from the 2nd table (I have just put a field called Join_Date from the User_infoT table to show you how to do that). <?php include("config_blog.php"); // Retrieve data from database $sql="SELECT a.Post_username, a.Post_date, a.Post_id, a.Post_subject, b.Join_Date FROM User_postT a LEFT OUTER JOIN User_infoT b ON a.username = b.username ORDER BY Post_id DESC LIMIT 30" ; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)) { ?> <table class="profileforum"> <tr><td style="width: 55px"><? echo "<img src='../Thumbnail_images/". $rows2['Profile_picture'] . "' style='width:50px; height:50px;' />";?></td> <td> <table class="forum_post" cellspacing="0" cellpadding="0" style="width: 345px; height: 52px"> <tr><td class="forum_sub">Posted by <a class="posts1" href="profile.php?username=<? echo $rows['Post_username']; ?>"><? echo $rows['Post_username']; ?></a> on <? echo $rows['Post_date']; ?></td></tr> <tr><td class="forum_h" valign="top"><a class="posts2" href="view_topic.php?Post_id=<? echo $rows['Post_id']; ?>"><? echo $rows['Post_subject']; ?></a></td></tr> </table> </td></tr> </table> <?php // close while loop } // close connection mysql_close(); ?> All the best Keith Link to comment https://forums.phpfreaks.com/topic/148505-problems-with-the-a-double-select-statement/#findComment-779931 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.