Jump to content


Photo

mysql_num_rows


  • Please log in to reply
9 replies to this topic

#1 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 01 August 2006 - 01:11 AM

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.
Dont Piss me Off today

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 01 August 2006 - 01:15 AM

http://ca.php.net/ma...ql-num-rows.php

It gets the number of rows in the query result.
Legend has it that reading the manual never killed anyone.
My site

#3 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 01 August 2006 - 01:18 AM

ive read that and its no help like i said in first post can you give me an example
Dont Piss me Off today

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 01 August 2006 - 01:21 AM

$query = "SELECT * from my_table_name";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
$numrows = mysql_num_rows($result);

Legend has it that reading the manual never killed anyone.
My site

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 01 August 2006 - 01:22 AM

<?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";
?>

Ken

Edit: Beaten by 1 second by AndyB (GMTA)

#6 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 01 August 2006 - 01:23 AM

so it gets the rows in that tables? basically the number?
Dont Piss me Off today

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 01 August 2006 - 01:26 AM

Yes. Just like it says in the manual.
Legend has it that reading the manual never killed anyone.
My site

#8 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 01 August 2006 - 01:35 AM

can u do WHERE in the query also?
Dont Piss me Off today

#9 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 01 August 2006 - 01:45 AM

^ 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.';
}

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#10 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 01 August 2006 - 01:58 AM

cool thanks i got my topics on index to rise thanks yalls :)
$s1 = mysql_query("SELECT * FROM topics WHERE fid='$s'");

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

Dont Piss me Off today




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users