PHP/MySQL Question

  gplatt2000 16:04 13 Aug 04
Locked

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";
$result=mysql_query($query);

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!

Cheers

  Matt45 17:26 13 Aug 04

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 04

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.

How to get Windows 10 for free | How to install Windows 10: There is still a way to avoid paying…

1995-2015: How technology has changed the world in 20 years

Alex Chinneck’s giant ice cube Christmas tree at Kings Cross

Apple rumours & predictions 2017: The iPhone 8, new iPads, and everything else you should expect fr7…