Newbie: How to get and display counts?

This is a discussion on Newbie: How to get and display counts? within the MySQL Database forums, part of the Database Forums category; I have a web page in which I want to display the count of records in a particular table. For ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-05-2006
deko
 
Posts: n/a
Default Newbie: How to get and display counts?

I have a web page in which I want to display the count of records in a
particular table.

For example:

<?php
@ $db = mysql_connect('localhost','username','password');
if (!$db)
{
exit;
}
mysql_select_db('wp21');

$qryblog21_posts = "select count(*) -1 as ct from wp01_posts";
$qryblog21_comments = "select count(*) -1 as ct from wp01_comments";

$result21_posts = mysql_query($qryblog21_posts);
$result21_comments = mysql_query($qryblog21_comments);

$array21_posts = mysql_fetch_array($result21_posts);
$array21_comments = mysql_fetch_array($result21_comments);

mysql_close;

if ($array21_posts && $array21_comments)
{
echo $array21_posts[0];
echo "</br>";
echo $array21_comments[0];
}
?>

This seems to work, and I think I can figure out how to get those two variables
into a table for the purpose of displaying them. But is this the right way to
go about this? Or am I missing something?

Thanks in advance.


Reply With Quote
  #2 (permalink)  
Old 05-09-2006
Hakan Kuecuekyilmaz
 
Posts: n/a
Default Re: Newbie: How to get and display counts?

deko wrote:
> I have a web page in which I want to display the count of records in a
> particular table.
>
> For example:
>
> <?php
> @ $db = mysql_connect('localhost','username','password');
> if (!$db)
> {
> exit;


Do you really want to stop your script here? I would ask myself: Is it
crucial to have the numbers for posts and comments? If yes, then exit.
If the numbers are not crucial, then set them to '0' and go on with your
script.

> }
> mysql_select_db('wp21');
>
> $qryblog21_posts = "select count(*) -1 as ct from wp01_posts";
> $qryblog21_comments = "select count(*) -1 as ct from wp01_comments";
>
> $result21_posts = mysql_query($qryblog21_posts);
> $result21_comments = mysql_query($qryblog21_comments);
>
> $array21_posts = mysql_fetch_array($result21_posts);
> $array21_comments = mysql_fetch_array($result21_comments);
>
> mysql_close;
>
> if ($array21_posts && $array21_comments)
> {
> echo $array21_posts[0];
> echo "</br>";
> echo $array21_comments[0];
> }
> ?>
>
> This seems to work, and I think I can figure out how to get those two
> variables into a table for the purpose of displaying them. But is this
> the right way to go about this? Or am I missing something?


The rest of your script looks ok.

Bye, Hakan
--
Hakan Kuecuekyilmaz
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:12 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0