Forum Moderators: coopster
I have a mysql table where i have a number of columns with date01, date02, date03 etc listed.
I'm trying to search the table to see if any of these dates match some user input.
$result3 = mysql_query("SELECT * FROM table WHERE postcode1 = '$row2[0]' AND date01 = '$sqldate'")
Now I assume i could just do
$result3 = mysql_query("SELECT * FROM table WHERE postcode1 = '$row2[0]' AND date01 = '$sqldate' OR date02='$sqldate' OR date03='$sqldate'")
But I have 30 dates. date01 to date30. Is there a simplier/easier way than listing them all individually?
Thankyou. :)
Also, make sure you use parenthesis correctly:
SELECT *
FROM table
WHERE postcode1 = '$row2[0]' AND (date01 = '$sqldate' OR date02='$sqldate' OR date03='$sqldate)
By the way, welcome to WW [webmasterworld.com]!
That comment about the parenthesis is true I probably would've messed that up and spent ages over it.
With my table lay out, i think that is the best i can do really. Basically users (each row) will be able to list days that they are available. I had considered having them in 1 column in a long string, but I think i'll stick with this way.
Thanks again.
The the select is much easier:
SELECT *
FROM UserInfo, AvalableDates
WHERE AvalableDates.AvailableDate='$sqldate' AND UserInfo.UserID=AvalableDates.UserID
This is a nudge in the (hopefully) more efficient direction. Without knowing more about your current structure or application, it's hard to give more direction.
Does AvailableDates.AvailableDate='$sqldate' look through all the columns in that table to see if any of them hold the correct date?
For the structure... A user can input say 30 dates. Another user can search to see if anyone is around on the date they chose. Do i need to explain more? I'm happy to.
Thanks :)
any guidance is very helpful.
So please consider these comments as suggestions, not criticisms.
I've been learning for about 2weeks in my spare time
Instead of Excel, think set theory. Do you remember back in elementary school when you had different ovals of objects and you have to color the intersections or unions of them? Relational databases use a similar model, with each table being one of the ovals. (With more than 2 tables, you can't visualize it in 2 dimensions any more, so it makes it a little more difficult to visualize things sometimes.) Okay, probably thoroughly confused now... :)
Does AvailableDates.AvailableDate='$sqldate' look through all the columns in that table to see if any of them hold the correct date?
In fact, that's another argument against your original structure. To optimize the table, you'd need 30 indexes on it.
A user can input say 30 dates.
I doubt my database will ever get huge, but I do like to try and do things in the best manner.
With relational tables if i increased it to 45 dates, would i not still need the columns set up ready for the data to be inputted? I know you can create tables using php, but to be honest i have done it with php admin in the main because i've found that easier. The user will be able to change their dates as time goes by and i was going to UPDATE rather than INSERT.
I'm sorry. I'm still a bit confused with relational/join stuff.
AvailableDates.AvailableDate='$sqldate';
This means, "look in the table called available.dates, look in the column availabledate to see if it matches $sqldate"? Or does it mean look through the whole table?
Off to try and find some more online
:o)
Venn diagrams
With relational tables if i increased it to 45 dates, would i not still need the columns set up ready for the data to be inputted?
This means, "look in the table called available.dates, look in the column availabledate to see if it matches $sqldate"? Or does it mean look through the whole table?
So I could put the user into that table lots of times. Hmmmmmm. only my other table i have the UserID (which is a professinol body number) set to primary key and unique so I couldn't get duplicate people.
But i guess i wouldn't need to on the dates one. Hmmmm. That could end up a very long table though.
Hmmmm
Thankyou VERY MUCH. I was a bit slow on the uptake but I got there. I hadn't thought have about having the user on multiple rows. I'll give this some thought. I guess it doesn't matter if the table ends up very long, cause I could always search out the info i needed.
Just thinking about deleting old dates too.
Sorry am waffling, ty again.