Jump to content

proper use of MySQL Resource


niche
 Share

Recommended Posts

This works, but is it a proper use of a MySQL Resource?

include_once "connect_to_mysql.php";$result = mysql_query("SELECT * FROM location ORDER BY locname") or die(mysql_error()); $var = (mysql_num_rows($result ));

Edited by niche
Link to comment
Share on other sites

Yes - Mysql result resources are used by other Mysql functions for operations specific to that particular query. Why did you think it may have been am improper use?

Link to comment
Share on other sites

I thought that I should have tried to use mysql_fetch_array() in some way to get what I needed though I got what I needed without it. I just needed to make sure that I wasn't invoking unintended consequences. Thanks Synook,Niche

Link to comment
Share on other sites

If the only thing you're trying to get is the count, it's more efficient to have MySQL do the counting instead of returning all of the rows:

$result = mysql_query("SELECT COUNT(*) AS num FROM location") or die(mysql_error()); $row = mysql_fetch_assoc($result);$count = $row['num'];

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

×
×
  • Create New...