Trying to get this loop to return all the records

I’m trying to get the database to return all the records and format them into table cells, this only outputs the first one.

How do I format this so that it puts all sets into table before stopping the loop please.

This is the code I currently have:

[php]<?
include(“dbconnect.php”);
$getnews = mysql_query(“select * from news ORDER BY id DESC”);
while($r=mysql_fetch_array($getnews)){
extract($r);
/* echo("$title on $date

$sector

$location

$salary

$details


"); */

}
?>

<?php print $title;?> <?php print $sector;?> <?php print $location;?> <?php print $salary?>
Description <?php print $details;?>
[/php]

THanks for your time.

SDM

[b]Admin Edit: Changed (bold) tags to [php] Tags for readability. Please see http://phphelp.com/guidelines.php for posting guidelines

Can you try putting this between the $getnews = line and the while( line:

print_r($r);

That’s one nifty PHP function to examine what exactly is in your arrays (and in arrays inside arrays). Because I have a feeling your query only returns one row (which it should only do if there’s only one row in your table).

I have inserted the text but it still only returns the one row.

Any further ideas?

Thanks,

SDM

If print_r() only returns one line, then the MySQL resource only has one line :) Which means there’s only one line returned by the SQL query, which means there’s only one row in your ‘news’ table.

Sponsor our Newsletter | Privacy Policy | Terms of Service