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 9 of 9

Thread: PHP Help +rep

  1. #1
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default PHP Help +rep

    Hello,

    I'm using this code to make a list of content in a table on a MySQL database:

    Code:
          $query = mysql_query("SELECT * FROM `staff`");
    
          while($row = mysql_fetch_array($query)){
    It's building a table and each entry goes in its own <td>. However, I want it to go onto a new line on the table (a new <tr>) every 4 mysql table rows (people).

    How would I do this?

    +rep to first correct/best solution.

    Thank you.
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


  2. #2
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    I think you should just revise the stuff you post before you keep opening new threads

    PHP Code:
    <?php
    $query 
    mysql_query("SELECT * FROM `staff`");
    $number 0;
    while(
    $row mysql_fetch_array($query))
    {
        if ( 
    $number <= )
        {
            echo ( 
    '<td></td>');
        }
        elseif ( 
    $number === )
        {
            echo ( 
    '<tr>' );
        }
        else
        {
            echo ( 
    '<tr>' );
            
    $number 0;
        }
    echo ( 
    $lala );
    $number++;
    }


    ?>
    I think thats what your looking for.
    Last edited by Protege; 06-07-2008 at 02:06 PM.
    Hi, names James. I am a web developer.

  3. #3
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default

    Hmm... I might be not using that correctly but it doesn't seem to be making a difference.
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


  4. #4
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?php
    $query 
    mysql_query("SELECT * FROM `staff`") or die( mysql_error() );
    echo (
    "<table>");
        while(
    $row mysql_fetch_array($query)){
            echo (
    "<tr><td>" $row['x'] . "</td><td>" $row['x'] . "</td></tr>");
        }
    echo (
    "</table>");
    ?>
    $row['x'] are the col names of the table, you need to change them
    Last edited by Decode; 06-07-2008 at 02:22 PM.
    Lets set the stage on fire, and hollywood will be jealous.

  5. #5
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default

    Thanks but I don't think you quite understood what I meant. I've done that, and I've got it coming out fine but all the entries go onto one <tr> - I want only 4 entries per line. This is the full code:

    PHP Code:
    <?php  

          $query 
    mysql_query("SELECT * FROM `staff`");

          while(
    $row mysql_fetch_array($query)){
          
          echo 
    '
    <td><center><img src=http://www.habbo.co.uk/habbo-imaging/avatarimage?user=' 
    $row['name'] . '&action=0&direction=3&head_direction=3&img_format=gif&gesture=0&size=s><br><font face="Verdana" size="1"><b>' $row['name'] . '</b></font><br><font face="Verdana" size="1"><i>DJ ' $row['username'] . '</i></font></center></td>';
          } 
    ?>
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


  6. #6
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    Sorry, i read it wrong Try this.

    PHP Code:
     <?php  
    $query 
    mysql_query("SELECT * FROM `staff`");
    echo 
    '<div class="container">';
        while(
    $row mysql_fetch_array($query)){
            echo 
    '<div class="box">';
            echo 
    '<img src=http://www.habbo.co.uk/habbo-imaging/avatarimage?user=' $row['name'] . '&action=0&direction=3&head_direction=3&img_format=gif&gesture=0&size=s>';
            echo 
    '<br><b>' $row['name'] . '</b><br><font face="Verdana" size="1"><i>DJ ' $row['username'] . '</i></div>';
        }
    echo 
    '</div>';
    ?>
    And add this to the head section;


    Code:
    <style type="text/css">
    .box        {width: 200px;
            float: left;
            font-family: verdana;
            font-size: 12px;
             text-align: center;
            }
    .container    {width: 800px;
            }
    </style>
    Last edited by Decode; 06-07-2008 at 02:39 PM.
    Lets set the stage on fire, and hollywood will be jealous.

  7. #7
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default

    Now nothing is appearing. Also, surely it must contain a "4" somewhere in the code and be more like Protege's?
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


  8. #8
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    Fixed it
    Lets set the stage on fire, and hollywood will be jealous.

  9. #9
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default

    Getting somewhere now. But, the first one that comes out, the font is size 2 instead of size 1 for some reason and the first one on the second row, when it's by itself, is under the 2nd one from the first row, and it should be under the 1st one on first row.... if that makes sense?

    Note to self, I owe you 2 +rep.

    Edit: fixed it - thanks so much. will write in signature to remind myself.

    (edited Css
    Code:
    <style type="text/css">
    .box        {width: 200px;
            float: left;
            font-family: verdana;
            font-size: 10px;
             text-align: center;
            }
    .container    {width: 800px;
            }
    </style>
    Last edited by iUnknown; 06-07-2008 at 02:45 PM.
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


Posting Permissions

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