Professional Web Applications Themes

Newbie: How to get and display counts? - MySQL

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 ...

  1. #1

    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.


    deko Guest

  2. #2

    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
    Hakan Kuecuekyilmaz Guest

Similar Threads

  1. Newbie, how to display a messagebox always on top
    By verci in forum ASP.NET Building Controls
    Replies: 2
    Last Post: September 13th, 08:59 AM
  2. Multiple counts in a repeat region
    By P the S Sr. in forum Dreamweaver AppDev
    Replies: 1
    Last Post: May 19th, 01:17 PM
  3. Newbie needs help with diary display
    By deckard2 in forum Macromedia ColdFusion
    Replies: 2
    Last Post: April 4th, 07:30 AM
  4. Newbie needs to read CSV or TSV value and display in a web page
    By Brent Atkerson in forum PERL Beginners
    Replies: 0
    Last Post: October 21st, 02:01 PM
  5. flash frame counts
    By JKLea webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 4
    Last Post: October 8th, 04:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139