Jump to content

proper use of MySQL Resource


niche

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 ));

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...