Sign in to follow this  
Followers 0
Uncle Argyle

MySQL query syntax

6 posts in this topic

Hi all,

I am trying to query a database using the following...

$varsearch = _Query($dbsearch, "SELECT * FROM apps WHERE g1first = '" & $searchfirst & "' OR g2first = '" & $searchfirst & "'")

I am trying to retrieve all the rows that contain $searchfirst in either column 'g1first' OR 'g2first...all I get is a single row, when I run the SQL query from phpmyadmin I get three rows...is there anything wrong with my syntax? (I know it's tough to see the single and double quotes)

If I don't try and search the second column, I get 2 rows returned (as I should)

$varsearch = _Query($dbsearch, "SELECT * FROM apps WHERE g1first = '" & $searchfirst & "'")

thanks,

Mike.

Share this post


Link to post
Share on other sites



looks correct.

havn't myself tried the OR or || function in mysql, perhaps it's not recognized in the UDF ?

does

$varsearch = _Query($dbsearch, "SELECT * FROM apps WHERE g2first = '" & $searchfirst & "'")
work ? (the second column)...

> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

Yep, the second half works on it's own as well...It's got me stumped. Thanks for looking at it for me, I needed a fresh pair of eyes.

Mike.

Share this post


Link to post
Share on other sites

I looked at the MySQL UDF and there doesn't seem to be any reason that it shouldn't work...the query function itself is pretty straight forward. Again, thanks for any help.

Func _Query($oConnectionObj, $sQuery)
    If IsObj($oConnectionObj) Then
        Return $oConnectionobj.execute ($sQuery)
    EndIf
    If @error Then
        SetError(1)
        Return 0
    EndIf
    
EndFunc  ;==>_Query

Share this post


Link to post
Share on other sites

OK, I figured out my own problem. The issue came from when I was counting the # of rows returned.

$rows = _Query($dbsearch, "SELECT COUNT(*) num FROM apps WHERE g1first = '" & $searchfirst & "' OR g2first = '" & $searchfirst & "' GROUP BY 'g1first'")

;Should be

$rows = _Query($dbsearch, "SELECT COUNT(*) num FROM apps WHERE g1first = '" & $searchfirst & "' OR g2first = '" & $searchfirst & "'")

I removed the GROUP BY parameter and the row count returned the correct # of rows. Sorry I didn't include this in my original post, but my script is rather long and I assumed that the problem was in the query and not in the counting of the rows returned by the query. Not sure why the GROUP BY piece isn't working...the syntax for that seems correct as well...but for now I am happy.

Thanks again,

Mike.

Share this post


Link to post
Share on other sites

all is well then, glad it worked out... mySQL ftw!


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0