Jump to content

How to sort order of info from DB


ozzwald1972

Recommended Posts

Hi, 

I have limited knowledge of Mysql, but understand the following script starts at the beginning of the DB and will work its way through. 

<code>public static function getNextLead(){ 

$lead_res = Database::get()->data->query("SELECT `lead_id` FROM `" . DATABASE_TBL_LEADS . "` WHERE `lead_disposition` IS NULL AND (`lead_timeout` IS NULL OR `lead_timeout` < NOW()) AND (`lead_locked` = '0000-00-00 00:00:00' OR `lead_locked` IS NULL) AND `lead_active` = '1' LIMIT 1"); 
$lead_num = $lead_res->numRows(); 

if($lead_num == 1){ 
</code> 

I want to access the leads WHERE `lead_disposition` IS NULL AND (`lead_timeout` IS NULL) AND (`lead_locked` IS NULL) AND `lead_callcount` IS '0' AND `lead_active` = '1'and then access the other available leads. 

I can read code, but do not know the correct syntax, so i am going round round in circles. 

Many thanks for your help in advance

Link to comment
https://forums.phpfreaks.com/topic/275967-how-to-sort-order-of-info-from-db/
Share on other sites

UPDATE:

 

I tired this code in MYPHPHADMIN and it worked: 

 

SELECT `lead_id` FROM `ssc_leads` WHERE `lead_disposition` IS NULL AND (`lead_timeout` IS NULL OR `lead_timeout` < NOW()) AND (`lead_locked` = '0000-00-00 00:00:00' OR `lead_locked` IS NULL) AND `lead_active` = '1' ORDER BY `lead_id` DESC LIMIT 1

 

This works so the last record is displayed, how ever when i put the code into the script, it doesnt make any difference.

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.