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!


Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default How would i do this in PHP?

    Hey

    I have a small question...

    In PHP how would I add an extra value to the outputted while functions?


    example:
    PHP Code:
    <?php $slide mysql_query("SELECT * FROM `slider` ORDER BY `id` DESC LIMIT 10");
    while(
    $val mysql_fetch_object($slide)){
        echo 
    "<a href=\"" $val->url "\"><img src=\"" $val->img_link "\" alt=\"" $val->alt "\" width=\"580\" height=\"282\" rel=\"<h3>" $val->rel_title "</h3>" $val->rel_desc "\"/></a>";
    ?>
    I have this already, but for my jquery script to work correctly I need to define the first image.. so I need this to be shown first, then after show thr above. So I want it to look like this...

    PHP Code:
    <?php $slide mysql_query("SELECT * FROM `slider` ORDER BY `id` DESC LIMIT 10");
    while(
    $val mysql_fetch_object($slide)){
        echo 
    "<a href=\"" $val->url "\"><img src=\"" $val->img_link "\" alt=\"" $val->alt "\" width=\"580\" height=\"282\" rel=\"<h3>" $val->rel_title "</h3>" $val->rel_desc "\"/></a>";
    ?>

    <?php $slide mysql_query("SELECT * FROM `slider` ORDER BY `id` DESC LIMIT 10");
    while(
    $val mysql_fetch_object($slide)){
        echo 
    "<a href=\"" $val->url "\" class=\"show\"><img src=\"" $val->img_link "\" alt=\"" $val->alt "\" width=\"580\" height=\"282\" rel=\"<h3>" $val->rel_title "</h3>" $val->rel_desc "\"/></a>";
    ?>
    I hope you under stand...

    Thanks + REP

    Lew.
    Im not here to be loved, I love to be hated :-}


  2. #2
    Join Date
    Nov 2008
    Location
    Cambridge, UK
    Posts
    901
    Tokens
    100

    Default

    A real hacky way to do this would be defining a var as 0, then adding 1 per iteration. If the var is 0, it's the first iteration of the loop, so do the first thing.
    we're smiling but we're close to tears, even after all these years

  3. #3
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    I don't quite get what you're wanting o.O

  4. #4
    Join Date
    Jan 2007
    Location
    Wales
    Posts
    2,432
    Tokens
    141

    Latest Awards:

    Default

    I really don't understand what you're trying to do here, can you explain a little more please?
    Free Online Games And Videos:
    http://www.vincesgames.com



  5. #5
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Right, basically, Im outputting values from the database. And I want the first outputted values to have something added to it. so I want it to do this...

    PHP Code:
    <?php $slide mysql_query("SELECT * FROM `slider` ORDER BY `id` DESC LIMIT 10"); 
    while(
    $val mysql_fetch_object($slide)){ 
        echo 
    "<a href=\"" $val->url "\" class=\"show\"><img src=\"" $val->img_link "\" alt=\"" $val->alt "\" width=\"580\" height=\"282\" rel=\"<h3>" $val->rel_title "</h3>" $val->rel_desc "\"/></a>"
    ?>
    <?php $slide 
    mysql_query("SELECT * FROM `slider` ORDER BY `id` DESC LIMIT 10"); 
    while(
    $val mysql_fetch_object($slide)){ 
        echo 
    "<a href=\"" $val->url "\"><img src=\"" $val->img_link "\" alt=\"" $val->alt "\" width=\"580\" height=\"282\" rel=\"<h3>" $val->rel_title "</h3>" $val->rel_desc "\"/></a>"
    ?>
    Notice, the top one had <a href="" class="show"></a>

    Thanks

    Lew.
    Im not here to be loved, I love to be hated :-}


  6. #6
    Join Date
    Nov 2008
    Location
    Cambridge, UK
    Posts
    901
    Tokens
    100

    Default

    The way I said would work fine..
    we're smiling but we're close to tears, even after all these years

  7. #7
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by MattFr View Post
    The way I said would work fine..
    My head's gone blank, any examples pls +REP

    Lew.
    Im not here to be loved, I love to be hated :-}


  8. #8
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    PHP Code:
    <?php
        $i 
    0;
        
    $slide mysql_query"SELECT * FROM `slider` ORDER BY `id` DESC LIMIT 20" ); 
        while( 
    $val mysql_fetch_object$slide ) ){ 
            
            
    $class = ( $i <= 10 ) ? "class=\"show\"" "";
            
    $i++; 
            
            echo 
    "<a href=\"" $val->url "\" " $class "><img src=\"" $val->img_link "\" alt=\"" $val->alt "\" width=\"580\" height=\"282\" rel=\"<h3>" $val->rel_title "</h3>" $val->rel_desc "\"/></a>";
        }
    ?>
    Something like that?
    Last edited by Moh; 08-11-2010 at 10:10 AM.

  9. #9
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Moh View Post
    PHP Code:
    <?php
        $i 
    0;
        
    $slide mysql_query"SELECT * FROM `slider` ORDER BY `id` DESC LIMIT 20" ); 
        while( 
    $val mysql_fetch_object$slide ) ){ 
            
            
    $class = ( $i <= 10 ) ? "class=\"show\"" "";
            
    $i++; 
            
            echo 
    "<a href=\"" $val->url "\" " $class "><img src=\"" $val->img_link "\" alt=\"" $val->alt "\" width=\"580\" height=\"282\" rel=\"<h3>" $val->rel_title "</h3>" $val->rel_desc "\"/></a>";
        }
    ?>
    Something like that?
    And that will only add class="show" to the very first output?

    Lew.
    Im not here to be loved, I love to be hated :-}


  10. #10
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by Lewiie15 View Post
    And that will only add class="show" to the very first output?

    Lew.
    To the first 10, simply edit the 10 to 1 if you only want the first to show.

    Also, if you want the others to have class="hide"

    $class = ( $i <= 10 ) ? "class=\"show\"" : "class=\"hide\"";

Page 1 of 2 12 LastLast

Posting Permissions

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