Jump to content

Number of Rows in Results


dcole.ath.cx

Recommended Posts

If I have something like this:

$query  = 'SELECT message, response FROM $groupsconvert[$o]';$result = mysql_query($query);

How can I count how many rows I have? I'm trying to pick a value of a random row. I really don't want to use a while loop and count it. I think I could use:

$countresult = count(mysql_fetch_row($result));

But will that could just the current string or is that going to count the number of rows in result?

Link to comment
Share on other sites

You can use mysql_num_rows(), e.g.

$query  = 'SELECT message, response FROM $groupsconvert[$o]';$result = mysql_query($query);echo mysql_num_rows($result);

Link to comment
Share on other sites

  • 3 years later...

Or if you want to SELECT a distinct value from a table where that value might occur more than once, you could do this:

SELECT COUNT(DISTINCT column_name) AS num FROM table

Link to comment
Share on other sites

Gah, niche, you've resurrected a really old thread :). We're happy that you found a solution from the archives, but it'll continue to exist even if you don't bump it.t_closed.gif

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...