facarroll Posted October 14, 2010 Share Posted October 14, 2010 I've got my code working OK in that the correct results are drawn from the database. What I have here in the code is an array consisting of an image, accompanied by its title and thirdly a link to activate a quiz associated with the image. Everything works fine, except because the page is dynamic, I always have an unknown number of sets of data (image, title and link) which I want to display so that each set of data takes up a new row. The code I have here, while displaying the correct data, places all of the results into the same row. Any suggestions are most welcome. <?php // Query the database $query1 = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); $query2 = mysql_query("SELECT url_small FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); $query3 = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); while($row1 = mysql_fetch_array($query3)) { $linkname .= $row1['title']."<br />\n"; } ?> <table> <tr> <td> <?php while ($row2 = mysql_fetch_array($query2)) { $thumbnail.= $row2['url_small']; echo "<img src='wood_tool_images/{$row2['url_small']}' alt='' /><br />\n"; } ?> </td> <td height="200"> <?php echo $linkname ?> </td> <td> <?php while ($row1 = mysql_fetch_array($query1)) { $quizname.= $row1['title']; echo "<a href='../{$row1['title']} Safety Quiz/{$row1['title']} Safety Quiz.php'>Take This Quiz</a><br />\n"; } ?> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/215844-how-can-i-display-results-of-an-array-in-individual-rows/ Share on other sites More sharing options...
litebearer Posted October 14, 2010 Share Posted October 14, 2010 Psuedo code... start table begin while loop start row start cell display data end cell start cell display data end cell start cell display data end cell end row end loop end table Link to comment https://forums.phpfreaks.com/topic/215844-how-can-i-display-results-of-an-array-in-individual-rows/#findComment-1122079 Share on other sites More sharing options...
facarroll Posted October 14, 2010 Author Share Posted October 14, 2010 I understand the concept, but need some more direct help. I'd greatly appreciate some further help. Link to comment https://forums.phpfreaks.com/topic/215844-how-can-i-display-results-of-an-array-in-individual-rows/#findComment-1122082 Share on other sites More sharing options...
litebearer Posted October 14, 2010 Share Posted October 14, 2010 Ok... First, my eyes may be blurry this AM, but why are you using three queries instead of one like this ... $query = ""SELECT * FROM topics WHERE managerId = '$managerId' AND egroup1=1' ORDER BY title ASC"; Link to comment https://forums.phpfreaks.com/topic/215844-how-can-i-display-results-of-an-array-in-individual-rows/#findComment-1122097 Share on other sites More sharing options...
litebearer Posted October 14, 2010 Share Posted October 14, 2010 played with your code abit. You may need to make minor mod... <?php // Query the database $query = "SELECT * FROM topics WHERE managerId = '$managerId' AND egroup1=1 ORDER BY title ASC"; $result = mysql_query($query); echo "<table>"; while($row = mysql_fetch_array($result)){ $linkname = $row['title']; $thumbnail = $row['url_small']; $quizname = // SET THIS VARIABLE TO WHATEVER THE URL TO THE TEST IS ?> <tr> <td><img src="wood_tool_images/<?PHP echo $thumbnail; ?>" alt=""</td> <td height="200"><?php echo $linkname; ?></td> <td><a href="../<?PHP echo $quizname; ?>">Take This Quiz</a></td> </tr> <?PHP } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/215844-how-can-i-display-results-of-an-array-in-individual-rows/#findComment-1122100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.