Not signed in (Sign In)

Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorboblennon
    • CommentTimeAug 1st 2010
     
    I'm a newbie to both plogger and this forum, but the configuration information for the albums and pictures in the gallery
    is saved in the gallery database in separate tables.

    Since you want to display the album and image count on a separate page, you might consider making
    up a couple of simple queries like:

    SELECT * FROM `plogger_albums` and SELECT * FROM `plogger_pictures`

    These queries will make the gallery configurations available and the counts can then be determined by
    using the mysql_num_rows() function since each of the album and picture configurations are stored as rows in the corresponding tables.

    Here's what the code might look like embedded in an html page (with a php extension of course):

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html >
    <head>
    <title>Counting Albums and Pictures</title>
    </head>
    <body>
    <?php //Connect to Database
    $dbname = 'My-DB-Name';
    $link = mysql_connect("mysql512.ixwebhosting.com","My-DB-User-Name","My-DB-Password") or die("Couldn't make connection.");
    $db = mysql_select_db($dbname, $link) or die("Couldn't select database");
    // Count Albums in Gallery
    $query = "SELECT * FROM `plogger_albums`; ";
    $result = mysql_query($query);
    echo "Number of albums: ". mysql_num_rows($result)."<br />"; // Display number of albums in database on html page
    // Count Pictures
    $query = "SELECT * FROM `plogger_pictures`; ";
    $result = mysql_query($query);
    echo "Number of pictures: ". mysql_num_rows($result); // Display number of pictures in database on html page
    ?>
    </body>
    </html>
    • CommentAuthorchewbears
    • CommentTimeAug 9th 2010
     
    Also in addition, for next time. If you want something from one page to another. GO to that page, and see what is making that element tick and copy it. Everything in plogger is based off the plog-functions so all code is easily transferable from 1 page to another. Also get firebug in a firefox browser and inspect elements and you will be able to troubleshoot a ZILLION times better : P

    gl!
    • CommentAuthormadhippo
    • CommentTimeSep 8th 2010 edited
     
    Can I make a suggestion - if you use "select count(*)" rather than "select *" MySQL will have a lot less work to do. For example, altering the code above would look something like this:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html >
    <head>
    <title>Counting Albums and Pictures</title>
    </head>
    <body>
    <?php //Connect to Database
    $dbname = 'My-DB-Name';
    $link = mysql_connect("mysql512.ixwebhosting.com","My-DB-User-Name","My-DB-Password") or die("Couldn't make connection.");
    $db = mysql_select_db($dbname, $link) or die("Couldn't select database");
    // Count Albums in Gallery
    $query = "SELECT count(*) as NumOfAlbums FROM `plogger_albums`; ";
    $result = mysql_query($query);

    while ($row=mysql_fetch_array($result))
    {
    $NumOfAlbums=$row['NumOfAlbums'];
    }



    echo "Number of albums: ". $NumOfAlbums."<br />"; // Display number of albums in database on html page
    // Count Pictures
    $query = "SELECT count(*) as NumOfPics FROM `plogger_pictures`; ";
    $result = mysql_query($query);
    while ($row=mysql_fetch_array($result))
    {
    $NumOfPics=$row['NumOfPics'];
    }

    echo "Number of pictures: ". $NumOfPics; // Display number of pictures in database on html page
    ?>
    </body>
    </html>
    • CommentAuthorboblennon
    • CommentTimeSep 11th 2010
     
    Thanks madhippo. Much better code! And that's why the count function is in the language. I just wanted to make a simple reply and lost my focus on the code.
    • CommentAuthormadhippo
    • CommentTimeSep 14th 2010
     
    No problemo. Your solution would work fine for small databases, just when it gets bigger you'd sit there waiting for it.
    • CommentAuthorboblennon
    • CommentTimeSep 14th 2010
     
    Sorry to disagree madhippo, but using the count function on a high population plogger schema is not necessarily better than using mysql_num_rows() to determine album and image counts with the plogger database if it is done right.

    The prevailing thought behind using count() on an external SQL server is that it will distribute the search work to the remote server and only the count result needs to be sent back to the PHP localhost. The localhost then provides better response to the user because it only has to process the count answer.

    However it seems to me that issuing an PHP mySQL query like:

    $calc_rows = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM $table LIMIT 1");
    $result = mysql_query("SELECT FOUND_ROWS()");
    $total = mysql_fetch_row($result);

    only requires a single row response and might be even more effective than the count() because it could isolate itself from the SQL server load and is more portable to most typical websites which have an integral mySQL database.

    Population notwithstanding, I think your suggestion of using the SQL Count function surely makes the code more readable.
    • CommentAuthormadhippo
    • CommentTimeSep 16th 2010
     
    Interesting.. I hadn't thought of doing it that way.

    I'll have to have a play with that! Cheers.