Forum Moderators: coopster

Message Too Old, No Replies

LIMIT Syntax Error

Query not working when LIMIT is used

         

Francis

2:58 pm on Feb 10, 2004 (gmt 0)

10+ Year Member



I am currently using this as part of my PHP script:

$query = "SELECT * FROM $action where year(d_date) like \"$year%\" ORDER BY d_date DESC LIMIT $value_of_limit, $my_limit";
$result = mysql_query($query) or die("Error: " . mysql_error());

if ($row = mysql_fetch_array($query)) {
echo ("Record Found");
} else {
echo ("No Record Found");
}

$action is the table, d_date is a date field, and $year is input from a form, while $value_of_limit and $my_limit are computed and constant values respectively.

My question is:

1. Can I rewrite the $query = .... to .... mysql_error()); to:

$query = mysql_query("SELECT * FROM $action where year(d_date) like \"$year\" ORDER BY d_date DESC LIMIT $value_of_limit, $my_limit") or die("Error: " . mysql_error());

2. Why do I keep on getting a "No record found" even though there are indeed records on the database? But when I remove the LIMIT $value_of_limit, $my_limit, the contents are displayed.

coopster

3:53 pm on Feb 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Your problem lies here:

if ($row = mysql_fetch_array($query)) {

You should be fetching an array from your result set, not your query:

if ($row = mysql_fetch_array($result)) {