Re: [PHP] verify another flavor
Paul M Foster wrote: On Fri, Mar 06, 2009 at 10:49:12AM -0600, haliphax wrote: snip 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'; If you already know the first_name and last_name and you're just checking for their existence, then just query for some simple field like id. The verification is to know if the author entered in the form already exists in the db. The person or the script does not know the id without querying the db. If the author exists in db the following directions will take one route otherwise another. :-) Then check for number of rows. If it's zero, it's not there. There's no point in making MySQL return a value which you already know. What is the fascination with using concat_ws()? No fascination... thought it would simplify things. Now I know what it is and how to use it. Thanks. :-) Just say: $name = $first_name . ' ' . $last_name; or $name = $first_name $last_name; Paul -- unheralded genius: A clean desk is the sign of a dull mind. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] verify another flavor
On Fri, Mar 6, 2009 at 10:36 AM, PJ af.gour...@videotron.ca 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
Re: [PHP] verify another flavor
$sql1 = SELECT first_name, last_name) FROM author WHERE (first_name LIKE 'first_nameIN' last_nameIN LIKE 'last_nameIN') On Fri, Mar 6, 2009 at 11:36 AM, PJ af.gour...@videotron.ca 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') -- unheralded genius: A clean desk is the sign of a dull mind. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php You need the % operator for a like comparison $sql1 = SELECT first_name, last_name) FROM author WHERE (first_name LIKE '%first_nameIN%' last_nameIN LIKE '%last_nameIN%') but most likely, you really want a true comparison to see if that user exists $sql1 = SELECT first_name, last_name) FROM author WHERE (first_name = 'first_nameIN' last_nameIN = 'last_nameIN') -- Bastien Cat, the other other white meat
Re: [PHP] verify another flavor
On Fri, Mar 06, 2009 at 10:49:12AM -0600, haliphax wrote: snip 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'; If you already know the first_name and last_name and you're just checking for their existence, then just query for some simple field like id. Then check for number of rows. If it's zero, it's not there. There's no point in making MySQL return a value which you already know. What is the fascination with using concat_ws()? Just say: $name = $first_name . ' ' . $last_name; or $name = $first_name $last_name; Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php