Jump to content

[SOLVED] Why does my code not display all my database info?


PHP Nubsauce

Recommended Posts

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>

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.