Jump to content

MySQL query syntax


Recommended Posts

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.

Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...