0

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 that I 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 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>
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by facarroll
0

The problem is that your table is currently inside the while loop, this causes the table itself to get recreated. What you need to do is to place the <table> tags outside the loop. This would put each loop on a separate row.

Here's the code

<?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");
echo "<table>";
while($row1 = mysql_fetch_array($query3))
{
$linkname .= $row1['title']."<br />\n";
}
?>
                 
                    <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 /></td></tr>";
                      }
                      ?>
                  </table>
0

The problem is that your table is currently inside the while loop, this causes the table itself to get recreated. What you need to do is to place the <table> tags outside the loop. This would put each loop on a separate row.

Here's the code

<?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");
echo "<table>";
while($row1 = mysql_fetch_array($query3))
{
$linkname .= $row1['title']."<br />\n";
}
?>
                 
                    <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 /></td></tr>";
                      }
                      ?>
                  </table>

Thank you. I had this solution from another source. Yours is virtually identical. Much appreciated.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.