wchamber22 Posted August 17, 2012 Share Posted August 17, 2012 Hello again freaks, When testing I noticed that the code as provided below only displays the first db result from my query. I need it to display all the db results. I know I am missing a single key ingredient, but can't put my finger on it after trying and trying. Code below: function coursesCode(){ if( !isset($_SESSION['user_id']) ){ echo '<table width="716" cellpadding="3" cellspacing="0" border="0"> <tr> <td width="250" bgcolor="#CCCCCC"><h4>COURSE NAME</h4></td> <td width="75" bgcolor="#CCCCCC"><h4>TEES</h4></td> <td width="100" bgcolor="#CCCCCC"><h4>YARDAGE</h4></td> <td width="75" bgcolor="#CCCCCC"><h4>RATING</h4></td> <td width="75" bgcolor="#CCCCCC"><h4>SLOPE</h4></td> <td bgcolor="#CCCCCC"><h4>CONDITION</h4></td> </tr>'; $sql = mysql_query("SELECT courseID, courseName, courseTYRS FROM courses") or die(mysql_error()); while($row = mysql_fetch_array($sql)){ $course_id = $row["courseID"]; $courseName = $row["courseName"]; $courseTYRS = $row["courseTYRS"]; echo '<tr> <td valign="top"><a href="coursedetails.php?courseID=' . $course_id . '"><strong>' . $courseName . '</strong></td> <td colspan="4"> <table width="325" cellpadding="3" cellspacing="0" border="0">'; $courseTYRSarray = explode(",", $courseTYRS); foreach ($courseTYRSarray as $key => $value){ $courseTee_Yardage_Rating_Slope = explode("-", $value); $courseTee = $courseTee_Yardage_Rating_Slope[0]; $courseYardage = $courseTee_Yardage_Rating_Slope[1]; $courseRating = $courseTee_Yardage_Rating_Slope[2]; $courseSlope = $courseTee_Yardage_Rating_Slope[3]; echo '<tr> <td width="75">' . $courseTee . '</td> <td width="100">' . $courseYardage . '</td> <td width="75">' . $courseRating . '</td> <td width="75">' . $courseSlope . '</td> </tr>'; } $sql2 = mysql_query("SELECT date FROM course_conditions WHERE courseID='$course_id' ORDER BY date DESC LIMIT 1") or die(mysql_error()); while($row2 = mysql_fetch_array($sql2)){ $date = $row2["date"]; } if(!$date){ $dateOutput = '<img src="images/minus.png"> N/A'; }else{ $dateOutput = '<img src="images/checkmark.png"> ' . $date . ''; } echo '</table> </td> <td valign="top">' . $dateOutput . '</td> </tr> <tr> <td colspan="6"> </td> </tr>'; } echo '</table>'; } } As always thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/267208-display-multiple-db-results-from-query/ Share on other sites More sharing options...
scootstah Posted August 17, 2012 Share Posted August 17, 2012 Which query? Quote Link to comment https://forums.phpfreaks.com/topic/267208-display-multiple-db-results-from-query/#findComment-1370066 Share on other sites More sharing options...
wchamber22 Posted August 17, 2012 Author Share Posted August 17, 2012 Hi scoots, Good question. The first query (SELECT courseID, courseName, courseTYRS FROM courses) Thanks for your quick reply. Quote Link to comment https://forums.phpfreaks.com/topic/267208-display-multiple-db-results-from-query/#findComment-1370067 Share on other sites More sharing options...
scootstah Posted August 17, 2012 Share Posted August 17, 2012 How many rows should there be? You have a lot of code going on there. Try reducing it a bit until you're sure everything works. What does this give you? $sql = mysql_query("SELECT courseID, courseName, courseTYRS FROM courses") or die(mysql_error()); echo mysql_num_rows($sql) . ' rows returned'; Quote Link to comment https://forums.phpfreaks.com/topic/267208-display-multiple-db-results-from-query/#findComment-1370068 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.