PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
i have a small search form with a few fields (one of them is required). i'm having trouble figuring out how to make it work. for instance, if there is an input field that doesn't have data, how would i populate a MySQL query to not query that field? i've got two text input fields (one of which is required) and 3 drop down menus. here's my code.
$result = mysql_query("SELECT * FROM my_search_table
WHERE brideLname LIKE '%". $lname ."%' OR groomLname LIKE '%". $lname ."%'
AND event_month ='". $event_month ."'
AND event_day = '". $event_day ."'
AND event_year = '". $event_year ."'")
or die(mysql_error());
i don't know what to do. or even where to start... any suggestions? it is posting to the same page, btw.
why is it doing this? i think it has something to do with the "event_day/month/year" part, but why would it take off the 't'??? what's going on here?
EDIT: upon further review, i concluded there's something terribly wrong with my substr() function. i'm not defining the parameters correctly. how would i cut off the last 4 characters of the $query_string?
is how you do it. i'm having some other issues, but i don't think it has to do with this new code. i think it's old code that's messed up. as i said before... it never worked properly.
Try implode() instead of the for loop and empty() instead of the null comparison.
EDIT: I didn't explain why you shouldn't use NULL to compare against get/post values. These values are always initialized strings, empty or not, and are never equal to NULL:
You are on the right track boo_lolly. Aaron's advise is good.
In code it is best to reduce duplication as much as possible. For instance I can see here you could do with a function a bit like this:
thank you very much arron for your advice. i will definitely use empty() and implode(). much better than my code.
ole, man i'm tryin to be really good, but i cannot understand your code. it is beyond my skills. can you explain what the code does? and how i would use it in replace of my own code?
ole, man i'm tryin to be really good, but i cannot understand your code. it is beyond my skills. can you explain what the code does? and how i would use it in replace of my own code?
Don't worry actually. I think you would need a class to do what I suggested anyway. I just tried it now and a function alone was too limiting.