• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

MySQL Newbie question... help me please!

Superwormy

Golden Member
Below is what I want to do, its PHP code:

SELECT * from $tablename where (name='$search_name' and email='$search_email')";

Problem being, if the user only wants to enter $search_name or only $search_email, it won't find anything because it'll be searching for, for instance, entries with the name: Keith AND email:


And it won't find anything because all entires with Keith also have email addresses. Is there a mysql thing I can put in there and say if $search_email == "" (ie nothign entered) then $search_email = (mysql character meaning everything I guess...) so that mysql with search for:

name == Keith AND email == (any email)


Did all the make sense? Anyone?
 
why don't you do this?

if ($search_email == "") {
$sqlquery = "SELECT * from $tablename where name='$search_name'";
}
else {
$sqlquery = "SELECT * from $tablename where name='$search_name' and email='$search_email'";
}

mysql_query($sqlquery);

 
Back
Top