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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.