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
|