On Fri, Mar 6, 2009 at 10:36 AM, PJ <af.gourmet@xxxxxxxxxxxx> wrote: > I know I'm a pain the butt but I just can't help asking for help. You > guys are so nice... ;-) > I am trying to do some checks if there are entries in the db so I can > then insert the right stuff. And I'm looking for ways to simplify things. > I probably dont understand the flow of things here, but this almost > works. :-\ > $Author = $first_nameIN . ' ' . $last_nameIN; > echo $Author; > $sql1 = "SELECT CONCAT_WS(" ", first_name, last_name) as Author FROM > author WHERE Author LIKE '$Author'"; > $result1 = mysql_query($sql1); > this would be instead of > $sql1 = "SELECT first_name, last_name) FROM author WHERE (first_name > LIKE 'first_nameIN' && last_nameIN LIKE 'last_nameIN')" Personally, I would avoid using the CONCAT_WS() MySQL function in your query, since you're just checking for existence rather than inserting records (for efficiency and scalability's sake). Also--why are you using LIKE if you're checking for a particular first and last name? Why not just use the equality operator (=)? And... be careful alternating quote styles in your SQL statements. The double-quotes (" ") following CONCAT_WS( will end your string. Also... I may be wholly wrong on this one, but I'm not sure MySQL uses C-style syntax for comparisons (&&, ||, !=) but rather "BASIC-style" syntax (AND, OR, NOT/<>). Again, I'm not sure about this. Maybe that part works just fine. I would go about it like this: $sql1 = "select concat_ws(' ', first_name, last_name) as Author_Name from author where first_name = '$first_nameIN' and last_name = '$last_nameIN'"; You still get your pretty output (concatenated first and last name), but you're checking the indexed columns individually rather than combining them first, like you did in your second statement. However, in your second statement, you did not prefix your PHP variable names with $, so you were literally checking against the strings 'first_nameIN' and 'last_nameIN'. Hope this helps, -- // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php