Jump to content

How to combine two MYSQL SELECT functions


Wickham

Recommended Posts

I have a booking form with a MySQL database and I have a web page where the current bookings are displayed.

 

At present this code makes the printed table show all entries after yesterday:

$q = "SELECT * FROM villagehall WHERE date >= '$today' ORDER BY date, starttime, endtime";

 

and I have also tested this one which shows all entries that are not cancelled:-

$q = "SELECT * FROM villagehall WHERE book != '$cancel' ORDER BY date, starttime, endtime";

 

and both work individually when followed by

$result = mysql_query($q) or die ("error!");

while ($row = mysql_fetch_array($result)){ echo table..........}

 

but how do I combine them into one SELECT?

 

I want to keep the cancelled entries in the database.

Edited by Wickham
Link to comment
Share on other sites

After much Googling and experimenting I found that I basically just had to add the word AND into the code so the individual SELECT queries:-

 

$q = "SELECT * FROM villagehall WHERE date >= '$today'  ORDER BY date, starttime, endtime";

 

and

 

$q = "SELECT * FROM villagehall WHERE book != '$cancel'  ORDER BY date, starttime, endtime";

 

became

 

$q = "SELECT * FROM villagehall WHERE date >= '$today' AND book 
!= '$cancel' ORDER BY date, starttime, endtime";

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...