cwilkey
01-30-2007, 07:41 PM
Hi All,
I'm writing a function to dynamiclly generate an SQL statment. The function works fine however it is only return the first row. How can I get it to bring back all results?
Here is my function:
function getNews($criteria, $order, $limit) {
$sql = "SELECT * FROM articles WHERE category1 = '$criteria' AND CURDATE() BETWEEN startdate AND enddate AND active = 'Y' ORDER BY `$order` LIMIT $limit";
$call = mysql_query($sql) or die(mysql_error());
$results = mysql_fetch_assoc($call);
return $results;
}
Here is how I'm calling it:
[code]
<?php $news = getNews('Top Story', 'timestamp', '3') while ($results = mysql_fetch_assoc($call)) { ?>
do blah, blah
<?php } ?>
I'm writing a function to dynamiclly generate an SQL statment. The function works fine however it is only return the first row. How can I get it to bring back all results?
Here is my function:
function getNews($criteria, $order, $limit) {
$sql = "SELECT * FROM articles WHERE category1 = '$criteria' AND CURDATE() BETWEEN startdate AND enddate AND active = 'Y' ORDER BY `$order` LIMIT $limit";
$call = mysql_query($sql) or die(mysql_error());
$results = mysql_fetch_assoc($call);
return $results;
}
Here is how I'm calling it:
[code]
<?php $news = getNews('Top Story', 'timestamp', '3') while ($results = mysql_fetch_assoc($call)) { ?>
do blah, blah
<?php } ?>