Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't show all records in PHP recordset

Status
Not open for further replies.

dreamaz

Technical User
Dec 18, 2002
184
CA
Hi

I have a database in MySQL (LAMP) and im trying to display all records in the table. I have been fighting with this quite a bit but can only get the first record in the table to display

<?php
mysql_select_db($database_dsa, $dsa);
$query_GetAlert = "SELECT * FROM Alerts";
$GetAlert = mysql_query($query_GetAlert, $dsa) or die(mysql_error());
$row_GetAlert = mysql_fetch_assoc($GetAlert);
$totalRows_GetAlert = mysql_num_rows($GetAlert);
$num=mysql_num_rows($totalRows_GetAlert);
$row = mysql_fetch_array($row_GetAlert);
?>

<?php echo $row_GetAlert['AlertDescription']; ?>

<?php
mysql_free_result($GetAlert);
?>

Can someone tell me what is wrong with this? any help is appreciated.

Thanks

 
You have to put the mysql_fetch in an while loop

Code:
<?php
   mysql_select_db($database_dsa, $dsa);
   $query_GetAlert = "SELECT * FROM Alerts";
   $GetAlert = mysql_query($query_GetAlert, $dsa) or die(mysql_error()); // this returns a pointer to the set, not the set
$totalRows_GetAlert = mysql_num_rows($GetAlert);
$num=mysql_num_rows($totalRows_GetAlert); // this statement is meaningless
   while ($row_GetAlert = mysql_fetch_assoc($GetAlert)) 
      echo $row_GetAlert['AlertDescription']."<br>\n"; // I assume you want one per line
// if you're only using one field it is better to just request that field in your select statement
   mysql_free_result($GetAlert);
?>

See comments it the above code...

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top