Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Having problems with SELECT statement

Codes here !

Moderators: macek, egami, gesf

Postby Redcircle » Wed Jul 16, 2003 4:59 pm

have you tried to echo the query to see what it looks like?
User avatar
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Re: Having problems with SELECT statement

Postby swirlee » Wed Jul 16, 2003 5:39 pm

First of all, follow Redcircle's advice.

jctgonzalez wrote:
Code: Select all
$query .= "first LIKE '%.$first.%' AND ";

Now then, my question is this: are those dots supposed to be there? If we set $first to "Jordan", the above will be evaulated to:

Code: Select all
first LIKE '%.Jordan.%' AND

Unless all of the first names (and most of the other fields, apparently), actually have dots on either side in your database, and I can't think of why that might be, it seems to me that this is amiss. My guess is that you got yourself confused and decided to try to use concatenation dots within the string. You probably want this instead:

Code: Select all
$query .= 'first LIKE \'%' . $first. '%\' AND ';

Or, if you insist on making PHP parse variables inside strings, like this:

Code: Select all
$query .= "first LIKE '%$first%' AND ";

Let me know if that helps.

(As a matter of trivia, though the second one looks simpler than the first, it causes PHP to do some additional processing and also makes your code harder to read.)
User avatar
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Brumbrum » Wed Jul 16, 2003 11:59 pm

try it with this corrections:

Code: Select all
$query .= "last LIKE '%$last%' AND ";

without .'nts. I do it without and it went without problems!

and the secound, you write:

Code: Select all
if ($phone2 !== '')

Don't you mean:

Code: Select all
if ($phone2 != "")
New php-forum User
New php-forum User
Posts: 9
Joined: Wed Jul 16, 2003 3:31 am

Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.