Jump to content

PHP / MySQL select with dynamic LIMIT variable


phoenixx

Recommended Posts

I have a user search form to limit quantities on the returned search using variable $viewquantity.  I need to return $viewquantity rows using a LIMIT in the sql select statement but running into a roadblock when I use:

$result_adhistory = mysql_query("SELECT * FROM adtracker WHERE adtracker_adid NOT LIKE '%index%' AND adtracker_clientid LIKE '%handr%' AND adtracker_adid > '' AND adtracker_pagetitle > '' AND adtracker_status > '' AND adtracker_adstamp > '' ORDER BY adtracker_adstamp DESC LIMIT '$viewquantity' ") or die ('Error: '.mysql_error ());

 

I tried using SET SQL_SELECT_LIMIT = ($viewquantity); on the line before the SQL statement but get an error:

Parse error: syntax error, unexpected T_STRING in /home/xxx/public_html/xxx/xxx/xxx/ad_history_reporter.php on line 135

 

Any help would be greatly appreciated.

Try this:

 

$result_adhistory = mysql_query("SELECT * FROM adtracker WHERE adtracker_adid NOT LIKE '%index%' AND adtracker_clientid LIKE '%handr%' AND adtracker_adid > '' AND adtracker_pagetitle > '' AND adtracker_status > '' AND adtracker_adstamp > '' ORDER BY adtracker_adstamp DESC LIMIT ".$viewquantity)

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.