Uncle Argyle Posted October 8, 2006 Share Posted October 8, 2006 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 More sharing options...
jinxter Posted October 9, 2006 Share Posted October 9, 2006 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 More sharing options...
Uncle Argyle Posted October 9, 2006 Author Share Posted October 9, 2006 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. Link to comment Share on other sites More sharing options...
Uncle Argyle Posted October 9, 2006 Author Share Posted October 9, 2006 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 More sharing options...
Uncle Argyle Posted October 9, 2006 Author Share Posted October 9, 2006 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 More sharing options...
jinxter Posted October 10, 2006 Share Posted October 10, 2006 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now