Jump to content

Need Some Help With a Select


bschultz

Recommended Posts

I have a select statement in a function that I need to tweak.  I needed to add a field to the database, and now the current select won't work.

 

Here's the select:

			$sql = "SELECT row_number, title, $priCASE FROM new_audio
		WHERE (`client_id` = '$client' or `corporation` = '$corporate')
		AND (`start_date` <= '$now' AND `end_date` >= '$now') 
		AND `$dow` = '1' AND `is_active` = '1' 
		AND (`start_hour` <= '$hour' AND `end_hour` >= '$hour') 
		AND `priority` IN ($priIN)
		ORDER BY priSort, last_play ASC
		LIMIT 1";

 

$client and $corporate used to be hard coded.  For instance, client id 1 would be store A.  Client id 2 would be store B.  Client id 3 would be BOTH STORE A AND STORE B.

 

I've now put that info into another db table, so that I can consolidate about 10 scripts into 1.

 

As the info is now, if $client = 0, the commercial to play is a CORPORATE-WIDE ad (plays at ALL locations of a company).  If this is the case, the $corporate field has that company's corporate id in it.

 

If not, it's a STORE-SPECIFIC ad...that only plays at the on location.  In this case, the $client will have a value (not 0), while the $corporate field will be 0.

 

How should I change the select to account for NOT SELECTING a client that equals 0 or a CORPORATE that equals 0...considering that is in the current select as an OR...and it should be an OR?

Link to comment
https://forums.phpfreaks.com/topic/261145-need-some-help-with-a-select/
Share on other sites

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.