Jump to content

Archived

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

scheols

mysql_num_rows

Recommended Posts

how does this actually work because i thought it can count rows from database tables or is that possible?

well im asking can someone show me an example on how this works and if it can count tables show me how i can count how many topics i have in my DB thanks.

Share this post


Link to post
Share on other sites
http://ca.php.net/manual/en/function.msql-num-rows.php

It gets the number of rows [b]in the query result[/b].

Share this post


Link to post
Share on other sites
ive read that and its no help like i said in first post can you give me an example

Share this post


Link to post
Share on other sites
[code]$query = "SELECT * from my_table_name";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
$numrows = mysql_num_rows($result);[/code]

Share this post


Link to post
Share on other sites
[code]<?php
$q = "select * from yourtablename";
$rs = mysql_query($q) or die("Problem with the query: $q <br>".mysql_error());
echo "There are " . mysql_num_rows($rs) . " in the table yourtablename";
?>[/code]

Ken

Edit: Beaten by 1 second by AndyB (GMTA)

Share this post


Link to post
Share on other sites
Yes. Just like it says in the manual.

Share this post


Link to post
Share on other sites
^ Yes, you can. Like so...

$result = mysql_query("SELECT * FROM users WHERE username='user'");
if (mysql_num_rows($result) == 1) {
  echo 'You are in the database!';
}
else {
  echo 'Could not find ya.';
}

Share this post


Link to post
Share on other sites
cool thanks i got my topics on index to rise thanks yalls :)
[code=php:0]
$s1 = mysql_query("SELECT * FROM topics WHERE fid='$s'");

$count = mysql_num_rows($s1);
mysql_query("UPDATE forums SET topics='$count' WHERE id='$s' ");
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.