Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2007
    Location
    england
    Posts
    536
    Tokens
    0

    Question There are X amount of entries

    I have the following code, how could I make it so above the entries, it would say "There are a total of XX entries".

    Is it possible?
    Heres my code:
    PHP Code:
    <?php
    // The database connetcion
    include "config.php";

    $sql "SELECT * FROM petition";
    $check mysql_query("SELECT name, grade, comment FROM petition") or die("Sorry, the data couldn't be displayed. Please check back later.");
    // The above variables will be used to check our connection to MySQL.

    while ($display mysql_fetch_array($check)) {

        
    $name $display['name'];
        
    $grade $display['grade'];
        
    $comment $display['comment'];

        
    // Above are variables defined for our Name, Gradeand Comment.

        
    echo "
    <strong>Name:</strong> 
    $name 
    <br> 
    <strong>Grade / Other:</strong> 
    $grade
    <br>
    <strong>Comment:</strong><br>
    $comment
    <br>
    ____________________________________________________________<br /><br />
    "
    ;

    }
    ?>


    Selling DJ/Habbo layout, more info here.


  2. #2
    Join Date
    Apr 2007
    Location
    england
    Posts
    536
    Tokens
    0

    Default

    Anybody?


    Selling DJ/Habbo layout, more info here.


  3. #3
    Join Date
    Jan 2007
    Location
    West Yorkshire
    Posts
    384
    Tokens
    0

    Default

    I didnt really know what you meant but maybe this will work

    PHP Code:

    $query 
    mysql_query("SELECT * FROM petition");
    $entries mysql_num_rows($query);
    echo(
    "There are $entries entries."); 

    “two players, two sides.
    one is light, one is dark.”
    - John Locke

  4. #4
    Join Date
    Jul 2005
    Posts
    1,653
    Tokens
    50

    Latest Awards:

    Default

    What entries? Total petitions? Total comments?

    Either way..
    $query = mysql_query("select count(*) from petition");
    $result = mysql_result($query, 0);
    echo $result;

    Don't use the suggestion above, not being mean to him but whilst it'll work, it isn't kind to the mysql load.

  5. #5
    Join Date
    Sep 2006
    Location
    Hobart, Australia
    Posts
    593
    Tokens
    0

    Default

    I wouldn't use either. You're already querying the database once, there isn't a need to do so a second time.

    PHP Code:
    <?php
    // The database connetcion
    include "config.php";

    $check mysql_query("SELECT name, grade, comment FROM petition") or die("Sorry, the data couldn't be displayed. Please check back later.");

    $num mysql_num_rows($check);

    // The above variables will be used to check our connection to MySQL.

    while ($display mysql_fetch_array($check)) {

        
    $name $display['name'];
        
    $grade $display['grade'];
        
    $comment $display['comment'];

        
    // Above are variables defined for our Name, Gradeand Comment.

        
    echo "
    <strong>Name:</strong> 
    $name 
    <br> 
    <strong>Grade / Other:</strong> 
    $grade
    <br>
    <strong>Comment:</strong><br>
    $comment
    <br>
    ____________________________________________________________<br /><br />
    "
    ;

    }
    ?>
    That way, $num holds the amount of rows returned.

Posting Permissions

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