andrew_biggart Posted April 12, 2010 Share Posted April 12, 2010 I need help with this please, I cant get my head around the logic at all. I have two databases, a user database containing username, user id, profile picture etc and then I have a thread database for the forum posts containing all of the thread info I.e the post id, post username and post data. What I am aiming to do is i have a while loop on the threads page to loop through all the forum posts and display them. I can get it to display all the posts this is not the problem. The problem is I want it to get all the posts and add them to an array once it has done that I want it to use all of the post username's in the area to get the relevant profile pictures for each user that has made a thread in the forum and display the correct profile picture from the user information table. I have tries several methods but cannot seem to get this working at all, below is one of the solutions I have tried but it doesn't display any of the information at all. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Latest Thread</title> </head> <body> <table cellpadding="0" cellspacing="0" class="acc_status_table"> <tr> <td class="forum_lt">Latest Thread's</td> </tr> <tr> <td class="acc_status_feed"> <?php include("config.php"); // Retrieve data from database $sql="SELECT * FROM biggartfp9_forum_threadst ORDER BY Post_id DESC LIMIT 10 " ; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)) $pic_username = $rows; $pic_query = "SELECT Profile_picture FROM biggartfp9_user_infot WHERE Username = '$pic_username'"; $pic_result = mysql_query($pic_query) or die('Error : ' . mysql_error()); $pic_row = mysql_fetch_array($result); $profile_picture = $row['Profile_picture']; { ?> <table class="acc_status_statuses"> <tr> <td class="acc_status_img" rowspan="2" valign="top"> <a href="profile.php?username=<?php echo $rows['Post_username']; ?>"><?php echo "<img class='profile_pic' src='../Profile_picture/$profile_picture' style='width:50px; height:50px;' />";?></a> </td> <td class="acc_alerts_posted"> In <a class="forum_cat" href="forum_filter.php?id=<? echo $rows['Post_type']; ?>"><?php echo $rows['Post_type']; ?></a> , by <a class="forum_cat" href="profile.php?username=<? echo $rows['Post_username']; ?>"><?php echo $rows['Post_username']; ?></a> on <?php echo $rows['Post_date']; ?> </td> </tr> <tr> <td class="acc_alerts_comment" valign="top"> <a class="forum_subject_link" href="forum_view.php?Post_id=<? echo $rows['Post_id']; ?>"><?php echo $rows['Post_subject']; ?></a> </td> </tr> </table> <br /> <? // close while loop } // close connection mysql_close(); ?> </td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 12, 2010 Share Posted April 12, 2010 $pic_query = "SELECT Profile_picture FROM biggartfp9_user_infot WHERE Username = '$pic_username'"; In the line above, $pic_username is not a String, but an array. So you're matching a Username to an Array. I think what you meant to do is say: $pic_username = $rows['Username']; in the line before that. Either way, what you have now doesn't make sense. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 12, 2010 Author Share Posted April 12, 2010 So what is the best way of going about doing this method then? I can not seem to get my head around it at all. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 12, 2010 Author Share Posted April 12, 2010 Right I have changed it to the code below and it is now displaying one thread with the profile picture but doesn't display the thread data, I am getting any closer? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Latest Thread</title> </head> <body> <table cellpadding="0" cellspacing="0" class="acc_status_table"> <tr> <td class="forum_lt">Latest Thread's</td> </tr> <tr> <td class="acc_status_feed"> <?php include("config.php"); // Retrieve data from database $sql="SELECT * FROM biggartfp9_forum_threadst ORDER BY Post_id DESC LIMIT 10 " ; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)) $pic_username = $rows['Post_username']; $pic_query = "SELECT Profile_picture FROM biggartfp9_user_infot WHERE Username = '$pic_username'"; $pic_result = mysql_query($pic_query) or die('Error : ' . mysql_error()); $pic_row = mysql_fetch_array($pic_result); $profile_picture = $pic_row['Profile_picture']; { ?> <table class="acc_status_statuses"> <tr> <td class="acc_status_img" rowspan="2" valign="top"> <a href="profile.php?username=<?php echo $rows['Post_username']; ?>"><?php echo "<img class='profile_pic' src='../Profile_picture/$profile_picture' style='width:50px; height:50px;' />";?></a> </td> <td class="acc_alerts_posted"> In <a class="forum_cat" href="forum_filter.php?id=<? echo $rows['Post_type']; ?>"><?php echo $rows['Post_type']; ?></a> , by <a class="forum_cat" href="profile.php?username=<? echo $rows['Post_username']; ?>"><?php echo $rows['Post_username']; ?></a> on <?php echo $rows['Post_date']; ?> </td> </tr> <tr> <td class="acc_alerts_comment" valign="top"> <a class="forum_subject_link" href="forum_view.php?Post_id=<? echo $rows['Post_id']; ?>"><?php echo $rows['Post_subject']; ?></a> </td> </tr> </table> <br /> <? // close while loop } // close connection mysql_close(); ?> </td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 12, 2010 Author Share Posted April 12, 2010 Now the thread information is being displayed but the profile picture is not, Im obviously close to getting it working but just need a little nudge in the right direction.... Any ideas anyone? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Latest Thread</title> </head> <body> <table cellpadding="0" cellspacing="0" class="acc_status_table"> <tr> <td class="forum_lt">Latest Thread's</td> </tr> <tr> <td class="acc_status_feed"> <?php include("config.php"); // Retrieve data from database $sql="SELECT * FROM biggartfp9_forum_threadst ORDER BY Post_id DESC LIMIT 10 " ; $result=mysql_query($sql); $pic_username = $rows['Post_username']; $pic_query = "SELECT Profile_picture FROM biggartfp9_user_infot WHERE Username = '$pic_username'"; $pic_result = mysql_query($pic_query) or die('Error : ' . mysql_error()); $pic_row = mysql_fetch_array($pic_result); $profile_picture = $pic_row['Profile_picture']; // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)) { ?> <table class="acc_status_statuses"> <tr> <td class="acc_status_img" rowspan="2" valign="top"> <a href="profile.php?username=<?php echo $rows['Post_username']; ?>"><?php echo "<img class='profile_pic' src='../Profile_picture/$profile_picture' style='width:50px;' />";?></a> </td> <td class="acc_alerts_posted"> In <a class="forum_cat" href="forum_filter.php?id=<? echo $rows['Post_type']; ?>"><?php echo $rows['Post_type']; ?></a> , by <a class="forum_cat" href="profile.php?username=<? echo $rows['Post_username']; ?>"><?php echo $rows['Post_username']; ?></a> on <?php echo $rows['Post_date']; ?> </td> </tr> <tr> <td class="acc_alerts_comment" valign="top"> <a class="forum_subject_link" href="forum_view.php?Post_id=<? echo $rows['Post_id']; ?>"><?php echo $rows['Post_subject']; ?></a> </td> </tr> </table> <br /> <? // close while loop } // close connection mysql_close(); ?> </td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 12, 2010 Share Posted April 12, 2010 You removed the while loop, which actually gets the result. So revert back to what you had 2 posts up. You can actually just use 1 SQL, but I won't get into that. Could you please try to keep a standard in your PHP tags? Either use <? or <?php, but not both and especially not alternating them. That's just annoying to read. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 12, 2010 Author Share Posted April 12, 2010 Ok Ken I do apologise for that, I am only a beginner and I am still learning so please do bare with me and thankyou for your patience, are you able to give me any advice as to where I am going wrong? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Latest Thread</title> </head> <body> <table cellpadding="0" cellspacing="0" class="acc_status_table"> <tr> <td class="forum_lt">Latest Thread's</td> </tr> <tr> <td class="acc_status_feed"> <?php include("config.php"); // Retrieve data from database $sql="SELECT * FROM biggartfp9_forum_threadst ORDER BY Post_id DESC LIMIT 10 " ; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)) $pic_username = $rows['Post_username']; $pic_query = "SELECT Profile_picture FROM biggartfp9_user_infot WHERE Username = '$pic_username'"; $pic_result = mysql_query($pic_query) or die('Error : ' . mysql_error()); $pic_row = mysql_fetch_array($pic_result); $profile_picture = $pic_row['Profile_picture']; { ?> <table class="acc_status_statuses"> <tr> <td class="acc_status_img" rowspan="2" valign="top"> <a href="profile.php?username=<?php echo $rows['Post_username']; ?>"><?php echo "<img class='profile_pic' src='../Profile_picture/$profile_picture' style='width:50px; height:50px;' />";?></a> </td> <td class="acc_alerts_posted"> In <a class="forum_cat" href="forum_filter.php?id=<?php echo $rows['Post_type']; ?>"><?php echo $rows['Post_type']; ?></a> , by <a class="forum_cat" href="profile.php?username=<?php echo $rows['Post_username']; ?>"><?php echo $rows['Post_username']; ?></a> on <?php echo $rows['Post_date']; ?> </td> </tr> <tr> <td class="acc_alerts_comment" valign="top"> <a class="forum_subject_link" href="forum_view.php?Post_id=<?php echo $rows['Post_id']; ?>"><?php echo $rows['Post_subject']; ?></a> </td> </tr> </table> <br /> <?php // close while loop } // close connection mysql_close(); ?> </td> </tr> </table> </body> </html> </html> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 12, 2010 Share Posted April 12, 2010 My guess is that you placed the { in the wrong place. See the brace { after $profile_picture? Move that to below the while loop. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 12, 2010 Author Share Posted April 12, 2010 As if I missed that, I have just looked at it that long it was all a blur, but It is working now thank you! 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.