PHP/MySQL Question

  gplatt2000 16:04 13 Aug 2004

Hi all. I'm a beginner to MySQL/PHP and have been working my way through some tutorials, although still feel pretty confused by it all!

However, I've decided to try and make a start at actually making the scripts I need for the website I'm making.

One of these will be a booking form, where I have different 'slots' which can be booked for one month. I need the page to only display slots which are available.

One way I've thought of doing this is to set up a table which has each slot as a row, with teh different fields being 'jan, feb, mar etc'. If a sopecific slot for a specific month IS available, then I have a 'y' as the record. If not, I have 'n'. E.g. slot1, month apr is available, hance tehre is a 'y'/

I hope that made sense, please tell me if it doesnt/if there is a much simpler way of doing this!

Anyway, as I said I only want the script to display the 'y' records, and print them as the month's name (so if Jan was available, 'jan' would appear on screen - if not, nothing would be shown).

I presume I need an if part to the script - but the problem I have is, how do I 'say' 'if ... = y then print ...' ?

At the start of my script I have this:

$query="SELECT jan FROM booking WHERE slot=1";

to obtain the 'y' or 'n' from the table. How do I then go about telling the browser to only print 'jan' if it is shown as 'y'?

Thanks a lot for any help, and sorry about the lopng post. please also tell me if my m,ethod is flawed and tehre is a better way of doing things!


  Matt45 17:26 13 Aug 2004

You could just change your SQL query to only retrieve records where 'y' is in the field you want. You would need to change you SQL code to

$query="SELECT jan FROM booking WHERE slot=1 AND ...='y'"; $result=mysql_query($query);

Then you could just print all the results and not bother with an if statement. If you still want to use an if statement, then you would need to do it in the format:

if ($value=="y") {
print "January";

Hope that helps

  gplatt2000 19:42 15 Aug 2004

Thanks a load for that, dont know why i didnt think of it, like I said, I'm new...that can be my excuse.

Thanks again

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

OnePlus 6 review

Razer's Core X GPU enclosure hands on review: It's cheaper, bigger, and even works with Macs

MacBook Pro keyboard issues and other problems

E3 2018 : dates, conférences de presse, billets et plus