Jump to content


Photo

How to show entries in a table


  • Please log in to reply
6 replies to this topic

#1 hustler

hustler
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 19 October 2006 - 06:56 PM

How can we count the number of entries in the table

For example i have a member table, where all the data for members is stored

I want to display in the admin panel that we have this number of members!

How to do it.

#2 Solarpitch

Solarpitch
  • Members
  • PipPipPip
  • Advanced Member
  • 708 posts
  • LocationDublin, Ireland

Posted 19 October 2006 - 07:00 PM

Hi,

I think the select statement would be something like...

$sql = "SELECT COUNT(*) as Num FROM tablename";

Gerard
Welcome to 9AM Monday, the furthest point away from 5PM Friday.

#3 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 19 October 2006 - 07:01 PM

SELECT COUNT(*) FROM `members`

More info here:
SQL COUNT :)

Orio.
Think you're smarty?

(Gone until 20 to November)

#4 hustler

hustler
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 19 October 2006 - 07:13 PM

Thanx for you replies
sorry for being silly
<?php
$query='SELECT COUNT(*) FROM `members`';
$result= mysql_query($query);
echo $result;
?>

but will this do?

#5 hustler

hustler
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 19 October 2006 - 07:15 PM

when i use this i get a output in my page=
Resource id #9

#6 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 19 October 2006 - 07:18 PM

you need to retrieve the query.

<?php
$query='SELECT COUNT(*) FROM `members`';
$result= mysql_query($query);
$r = mysql_fetch_array($result);
echo $r[0];
?>

Ray


#7 hustler

hustler
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 19 October 2006 - 07:32 PM

Thanx Mate that worked!

the next question is
We have a member list in the admin where the admin can see all the active members.
At the moment it displays as a list and we can edit and delete them.

What i want at the top is search box where we can enter surname of the member and it display us only ones with that surname.

current code is
<?php
require_once("includes/class.member.php");
$objMember=new Member();        
$arrMemberList=$objMember->getMembers($req_isActive);
if(count($arrMemberList)>0){
?>
    <form method=post>
        <input type=hidden name="form_action" value="delete">
        
        <table cellspacing=0 cellpadding=0 width=90% border=1>
            <tr>
                <td>&nbsp;</td>
                <td><font face=verdana size=3><b>Name</td>
                <td><font face=verdana size=3><b>Email</td>
                <td><font face=verdana size=3><b>Contact</td>
                <td><font face=verdana size=3><b>Username</td>
                <td><font face=verdana size=3><b>Postcode</td>
            </tr>
<?php while($member=array_pop($arrMemberList)){ ?>
            <tr>
                <td>
                    <input type=checkbox name=id[] value="<?php echo $member["id"];?>">
                    <a href='admin.php?c=editMember&mid=<?php echo $member["id"];?>'>Edit</a>
                </td>
                <td>
                    <font face=verdana size=2>
                        <?php echo $member["firstname"]." ".$member["lastname"];?>&nbsp;
                    </font>    
                </td>
                <td>
                    <font face=verdana size=2>
                        <?php echo $member["email"];?>&nbsp;
                    </font>    
                </td>                
                <td><font face=verdana size=2><?php echo $member["contact"];?>&nbsp;</td>
                <td><font face=verdana size=2><?php echo $member["username"];?>&nbsp;</td>
                <td><font face=verdana size=2><?php echo $member["postcode"];?>&nbsp;</td>
            </tr>
<?php } ?>            
            <tr>            
                <td colspan=6 align=center><input type=submit value="Delete Selected"></td>
            </tr>                
        </table>
    </form>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users