Jump to content

[SOLVED] loop table to show more results (or something along those lines)


seany02

Recommended Posts

What im trying to do is to bring up all of the entries by a specific where clause. this is fine for 1 return for the type of  table output im using. However the table only shows the first result. (im not getting any errors on screen to help either)  i dont want to sacrifice the look of the table by changing the type of table, which i know works, which proves theres no issue with the sql (obviously you cant see the css formating either) as always any help is appreciated, especially since this is a very important part of the assignment  :o

<?php
$name=$_POST["secondtxt"]; 

$db = @mysql_connect("localhost","root","");

if (!$db)
{
do_error("Could not connect to the server");
}

// Connect to the database
@mysql_select_db("Rufus" ,$db)or do_error("Could not connect to the database");
// Run query
$result = mysql_query("SELECT * FROM project WHERE user_id='$name' ORDER BY project_id",$db);

if ($myrow = mysql_fetch_array($result))
{
                     echo "</b><br><b>Project ID: </b>";
                     echo $myrow['project_id'];
                     echo "</b><br><b>Project Name:</b> <i>";
                     echo $myrow['project_name'];
				 echo "</b><br><b>Client ID: </b>";
                     echo $myrow['client_id'];
				 echo "</b><br><b>Deadline: </b>";
                     echo $myrow['project_deadline'];
                     echo "</i><hr><br><b>Project Description</b><br>";
                     echo $myrow['project_description'];
                     echo "<br><br> <B>Project Requirements</b><br> ";
                     echo $myrow['project_requirements'];
                     echo "<br><br><a href=\"javascript:self.history.back();\"><-- Go Back</a>";
             }

?>
</div>
</div>
<?php

change

if ($myrow = mysql_fetch_array($result))

to

while ($myrow = mysql_fetch_array($result))

 

using an if statement will only provide 1 result because the if statement is only executed once, where the while statement is executed until the condition is false (in this case the condition would become false when there are no more entries from your mysql result)

 

hope that helps!

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.