Jump to content

count rows


gwolff2005

Recommended Posts

Hi guys,

 

I want to count the number of rows in a table and want to display them.

However that field stays empty. Everythign else works. What do I do wrong?

 

<?php
//$sql="SELECT * FROM $tbl_name ORDER BY user_id";
$sql="SELECT * from sp_users,sp_schools where sp_users.user_id=sp_schools.school_id";
$result=mysql_query($sql);
$num_rows=mysql_num_rows($result);
?>
<style type="text/css">
<!--
.style2 {font-weight: bold}
.style3 {
font-family: Arial, Helvetica, sans-serif;
color: #000000;
}
.style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; }
-->
</style>

<title>User overview</title><table width="779" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600">
<tr>
<td width="777">
  
    <div align="left">
      <table width="779" border="1" cellspacing="0" cellpadding="3">
        <tr>
          <td colspan="6" align="center"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users </strong></div></td>
          </tr>
        <tr>
          <td width="25" align="center"><span class="style2">No.</span></td>
          <td width="62" align="center"><span class="style2">Name</span></td>
          <td width="104" align="center"><span class="style2">Lastname</span></td>
          <td width="130" align="center"><span class="style2">Email</span></td>
          <td width="342" align="center"><span class="style2">school</span></td>
          <td width="64" align="center"><span class="style2">Update</span></td>
        </tr>
        <?php
while($rows=mysql_fetch_array($result)){
?>
        <tr>
          <td><span class="style10"><? echo $rows['num_rows']; ?></span></td>
          <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td>
          <td><span class="style10"><? echo $rows['user_surname']; ?></span></td>
          <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td>
          <td><span class="style10"><? echo $rows['school_name']; ?></span></td>
          <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td>
        </tr>
        <?php
}
?>

Link to comment
Share on other sites

Oh yeah sorry.  I don't think you want to use a COUNT or num_rows function here.  You would either want to use a variable that increments its value in the loop or the user_id from your table.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.