Jump to content

[SOLVED] Field = any value?


Adam

Recommended Posts

Hi guys. I was just wondering if there's some kind of operator or something that can mean the field can equal any value?

 

Basically I select records based on the 'site', but there's an option for all. So without having to go..

 

if ($site = 'all')
   //run this query
else
   //run this query

 

I could either have it return records from site 1, site 2, etc. or have it return records with any value for site..

 

 

Hope that makes sense??

 

Cheeers, Adam...

Link to comment
Share on other sites

Sure..

 

$resSQL = mysql_query("SELECT * FROM reservations
		WHERE (datefrom BETWEEN '{$year}/{$month}/01'
		AND '{$year}/{$month}/{$daysInMonth}')
		AND site = '{$site}'
		ORDER BY datefrom ASC") or die(mysql_error());

 

That's the query I'm using. Most of it doesn't really matter right now except "AND site = '{$site}' " .. I have a drop down menu that allows them to select site 1, site 2, site 3, etc. the sites are stored in the database by IDs .. so the value of $site would equal 1, or 2, or 3, etc. except there's an option for ALL, so I was wondering if there was some special operator or something I could enter in the $site variable in order to - in english - return records with 'site' field equalling anything.

 

Any clearer?? Thanks! Adam

Link to comment
Share on other sites

I've come up with a soloution using PHP, but I'd still like to know if there is such a thing in MySQL? would make the code a little nearer, and may help me on another project...

 

$resSQL = 	"SELECT * FROM reservations
		WHERE (datefrom BETWEEN '{$year}/{$month}/01'
		AND '{$year}/{$month}/{$daysInMonth}')";

/* If ALL sites selected do not specify site in query */
if ($site != 'ALL') $resSQL .= "AND site = '{$site}'";

 

Cheers, Adam...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.