Hi,
I'm trying to set up a conditional if/else statement based upon testing whether or not a MySQL query yielded any results. Specifically, I'm running a query to determine if an item is in the database: if it is not, I insert a record and set the count field to 1; if the item exists, I retrieve the count and increment it by 1 then update the database record.
Sounds easy enough. However, I cannot figure out how to code the conditional. For example, I tried If empty($query) with no luck. I tried If ($query == 0), no luck. What did work is:
If (!mysql_fetch_row($query))
However, having coded ASP, this seems wasteful bloated code, specifically, it appears to run a query to test a query. Is this the only way to test if the $query is an empty result set?
Also, in the else statement, if the $query result set is not empty, I would like to pull out the single count value. However the $query seems to be empty and I have to run the query again: is there a simple way to refresh the $query result set? In ASP it was .MoveFirst but I tried reset($query) per PHP manual but that didn't work.
Any ideas and experiences would be much appreciated! Thank you!
Tim