Results 1 to 6 of 6

Thread: [PHP] Stcuk

  1. #1
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default [PHP] Stcuk

    I'm stuck!

    I'm just coding the frontend of my new site and I've hit my first error.

    I want my news articles to alternate between three header colours. I can't do it, the colours alternate correct but three of each article comes out.

    How would I make the colours alternate like that (green, blue, orange_ but only have one of each article come up?

    Here's the code I'm using:
    PHP Code:
    <?php
    include "config.php";

    $check mysql_query("SELECT title, author, content, date FROM news ORDER BY id DESC LIMIT 0, 5") or die("nothing to display at the moment.");

    while (
    $display mysql_fetch_array($check)) {

        
    $title $display['title'];
        
    $author $display['author'];
        
    $content $display['content'];
        
    $date $display['date'];
        echo 
    "<h1>$title - by $author</h1>
        
    $content<br />
    <i>Posted on 
    $date</i>

    <h2>
    $title - by $author</h2>
        
    $content<br />
    <i>Posted on 
    $date</i>

    <h3>
    $title - by $author</h3>
        
    $content<br />
    <i>Posted on 
    $date</i>";
        }
    ?>
    +rep to all help.

  2. #2
    Join Date
    Oct 2006
    Posts
    2,918
    Tokens
    946
    Habbo
    Verrou

    Latest Awards:

    Default

    I'd just add an id column to the sql table and have it repeat 01, 02, 03 and then use PHP to check what id the article is. Eg: 01 = Green, 02 = Blue, 03 = Orange.
    Quote Originally Posted by Special-1k View Post
    How do you uninstall an internet? I want to uninstall my Google Chrome and
    get firefox but I never really got rid of an internet my dad usually did it for me.
    If you know how post below so I can do this.

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

    Latest Awards:

    Default

    It's not possible if you're gonna show 5 news items but only want 3 colours and dont want them to duplicate.

  4. #4
    Join Date
    Jan 2007
    Posts
    651
    Tokens
    0

    Default

    Yes it is ryan, Verrous idea was perfect...
    James


    Connected to reality through a proxy server.

  5. #5
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Quote Originally Posted by loserWILL View Post
    I'm stuck!

    I'm just coding the frontend of my new site and I've hit my first error.

    I want my news articles to alternate between three header colours. I can't do it, the colours alternate correct but three of each article comes out.

    How would I make the colours alternate like that (green, blue, orange_ but only have one of each article come up?

    Here's the code I'm using:
    +rep to all help.
    Dunno if this is what you want but whatever.

    PHP Code:
    <?php
    include "config.php";

    $check mysql_query("SELECT title, author, content, date FROM news ORDER BY id DESC LIMIT 0, 5") or die("nothing to display at the moment.");
    $i 0;
    while (
    $display mysql_fetch_array($check)) {

    $colour = ($i 2) ? "background-color: #whatever" "background-color: #a different whatever";
        
    $title $display['title'];
        
    $author $display['author'];
        
    $content $display['content'];
        
    $date $display['date'];
        echo 
    "<div style=\"$colour\"><h1>$title - by $author</h1>
        
    $content<br />
    <i>Posted on 
    $date</i>

    <h2>
    $title - by $author</h2>
        
    $content<br />
    <i>Posted on 
    $date</i>

    <h3>
    $title - by $author</h3>
        
    $content<br />
    <i>Posted on 
    $date</i></div>";
    $i++;
        }
    ?>


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  6. #6
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default

    Okay, I tried adding a third colour, but it gave me an error:
    Parse error: syntax error, unexpected ':' in /home/kolzy/public_html/index.php on line 220
    Here's the PHP
    PHP Code:
    $color = ($i 3) ? "blue" "green" "orange"

Posting Permissions

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