SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    New project need help getting it started

    I have a little script started, its just taking records from a database and displaying them into tables ( going to be a forum stats page when im done)
    The first table works fine but the second one does not display the data
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <link href="stats.css" rel="stylesheet" type="text/css" />
    </head>
    <?php
    //connection 

    // (...)

    $sql 'SELECT user_posts,username,user_warnings FROM phpbb_users ORDER BY user_posts DESC LIMIT 10;';
    $result mysql_query($sql);


    ?>

    <body>
    <div id="wrapall">
    <div id="topstats">
      <p>Tops stats will go here</p>
      <p>&nbsp;</p>

    </div>
    <div id="left">
    <table width="450" border="1">
      <tr>
        <td width="100">Username</td>
        <td width="100">Posts </td>
        <td width="100">Warnings</td>
        <td></td>
      </tr>
      </table>
    <?php

    while($rows mysql_fetch_assoc($result)) {

    ?>



    <table width="450" border="1">

      <tr>
        <td width="100"><?php echo htmlentities($rows['username']); ?></td>
        <td width="100"><?php echo htmlentities($rows['user_posts']); ?></td>
        <td width="100"><?php echo htmlentities($rows['user_warnings']); ?></td>
        <td></td>
      </tr>
    </table>
    <?php
    }
    ?>
    </div>
    <div id="right">
    <table width="450" border="1">
      <tr>
        <td width="100">Forum name</td>
        <td width="100"># of topics </td>
        <td width="100"># of posts</td>
        <td></td>
      </tr>
      </table>
    <?php

    $sql 
    'SELECT forum_name,forum_topics,forum_posts,forum_id FROM phpbb_forums ORDER BY forum_id DESC;';
    $result mysql_query($sql);

    while(
    $rows mysql_fetch_assoc($result)) {

    ?>



    <table width="450" border="1">

      <tr>
        <td width="100"><?php echo htmlentities($row['forum_name']); ?></td>
        <td width="100"><?php echo htmlentities($row['forum_topics']); ?></td>
        <td width="100"><?php echo htmlentities($row['forum_posts']); ?></td>
        <td></td>
      </tr>
    </table>
    <?php
    }
    ?>
    </div>
    <div class="clear"></div>

    </div>
    </body>
    </html>

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You wrote your $rows as $row (singular) in the second table.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Damn i had $rows instead of $row

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    When developing, before publishing a script, have these 2 lines at the top of the page:
    PHP Code:
    <?php
    ini_set
    ('display_errors'1);
    error_reportingE_ALL );

    ...
    comment them out when you publish, that'll help you find basic errors.

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    You wrote your $rows as $row (singular) in the second table.
    haha yeah just posted the same thing rite when you did i guess


    Thanks

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    When developing, before publishing a script, have these 2 lines at the top of the page:
    PHP Code:
    <?php
    ini_set
    ('display_errors'1);
    error_reportingE_ALL );

    ...
    comment them out when you publish, that'll help you find basic errors.
    awesome i will do that, i learn so much on this site haha

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have another one for you cup's ( or anyone)

    how would you go about taking all the values in 1 table, adding them up and displaying the resaults?

    IE.

    if i have a table with all posts in each forum

    230
    503
    2222
    2303

    and i want to display the total posts for the full forum.

    would i have to make a variable?

    $total = $row['posts'] + $row['posts']

  8. #8
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT SUM(posts) AS totalPosts FROM table;
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  9. #9
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SilverBulletUK View Post
    Code:
    SELECT SUM(posts) AS totalPosts FROM table;
    Awesome worked perfect, thanks

  10. #10
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have another one already, sorry for all my questions

    I want to do this

    Code:
    $sql = 'SELECT SUM(forum_topics,forum_posts) AS totaltopics,totalposts FROM phpbb_forums;';
    but that does not work

    aka. i am trying to get total posts and total topics and place them in the same table

    this works perfect but only displays posts

    Code:
    $sql = 'SELECT SUM(forum_posts) AS totalposts FROM phpbb_forums;';

  11. #11
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT SUM(topics) AS totalTopics, SUM(posts) AS totalPosts FROM table
    No?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  12. #12
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SilverBulletUK View Post
    Code:
    SELECT SUM(topics) AS totalTopics, SUM(posts) AS totalPosts FROM table
    No?
    worked perfect

    thanks again

  13. #13
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    edit : scratch that
    Last edited by iansteeze; Jan 22, 2009 at 17:03.


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
  •