PHP Nubsauce Posted July 8, 2008 Share Posted July 8, 2008 If I close my if statement at the end, it displays all my info but with a new table for each one. If I close it like shown, it only displays one object from the database. I need all my info to be displayed in one table box. Can anybody help me please? $links = @mysql_query("SELECT * FROM ".$mysql_pretext."_documents WHERE document_type_id = '2'"); if (!$links) { echo("Error retrieving student life documents from the database!<br>Error: " . mysql_error()); exit(); } $number = 0; while ($link = mysql_fetch_array($links)) { $ids1 = $link["ID"]; $titles1 = $link["title"]; $type = $link["type"]; $date = $link["date"]; $filename = $link["name"]; $addedby = $link["added_by"]; $number++; } ?> <td height="30" colspan="2" bgcolor="#A0C4EC" class="search"><span class="style1">Student Life Library</span></td> </tr> <tr> <td width="6%" height="30" valign="middle"><img src="images/pdf_icon.png" width="20" height="20" /></td> <td width="94%" height="30" valign="middle" class="text"><a href="getdocument.php?id=<?php echo($ids1); ?>"><?php echo($filename); ?></a> - <?php echo($titles1); ?></td> </tr> <tr> Quote Link to comment Share on other sites More sharing options...
cleibesouza Posted July 8, 2008 Share Posted July 8, 2008 Try this. If I'm not missing anything it should work: if (!$links) { echo("Error retrieving student life documents from the database!<br>Error: " . mysql_error()); exit(); }else{ $number = 0; echo "<table>"; while ($link = mysql_fetch_array($links)) { $ids1 = $link["ID"]; $titles1 = $link["title"]; $type = $link["type"]; $date = $link["date"]; $filename = $link["name"]; $addedby = $link["added_by"]; $number++; echo "<tr> <td height=\"30\" colspan=\"2\" bgcolor=\"#A0C4EC\" class=\"search\"><span class=\"style1\">Student Life Library</span></td> </tr> <tr> <td width=\"6%\" height=\"30\" valign=\"middle\"><img src=\"images/pdf_icon.png\" width=\"20\" height=\"20\" /></td> <td width=\"94%\" height=\"30\" valign=\"middle\" class=\"text\"><a href=\"getdocument.php?id=$ids1>$filename></a> - $titles1</td> </tr>"; }//end while echo "</table>"; }//end else Quote Link to comment Share on other sites More sharing options...
craygo Posted July 8, 2008 Share Posted July 8, 2008 you are closing your loop before you echo anything out, so when you do echo anything it will be the last row in the table <?php $links = @mysql_query("SELECT * FROM ".$mysql_pretext."_documents WHERE document_type_id = '2'"); if (!$links) { echo("Error retrieving student life documents from the database!<br>Error: " . mysql_error()); exit(); } $number = 0; ?> <table> <tr> <td height="30" colspan="2" bgcolor="#A0C4EC" class="search"><span class="style1">Student Life Library</span></td> </tr> <?php while ($link = mysql_fetch_array($links)) { $ids1 = $link["ID"]; $titles1 = $link["title"]; $type = $link["type"]; $date = $link["date"]; $filename = $link["name"]; $addedby = $link["added_by"]; $number++; ?> <tr> <td width="6%" height="30" valign="middle"><img src="images/pdf_icon.png" width="20" height="20" /></td> <td width="94%" height="30" valign="middle" class="text"><a href="getdocument.php?id=<?php echo($ids1); ?>"><?php echo($filename); ?></a> - <?php echo($titles1); ?></td> </tr> <?php } ?> </table> Ray Quote Link to comment Share on other sites More sharing options...
PHP Nubsauce Posted July 8, 2008 Author Share Posted July 8, 2008 Thank you for the help, both of you. Both ways worked. Ray you're the man bro. 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.