SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with conditions in while loops...

    example:

    PHP Code:
    $getinfo mysql_query("SELECT * FROM information");
     
    while (
    $info mysql_fetch_array($getinfo)) {
    $age $info['age'];
     
    print 
    $age;
    print 
    '<br>';
    print 
    $abc;

    That's just a very very quick example I've thrown together. Now what I want to do is make it so:

    if the age is above 20, $abc = 'above 20';
    if the age is 20, $abc = 'is 20';
    if the age is below 20, $abc = 'below 20';

    Would just putting if statements in the loop work or is there something else that I can do?

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Middle / East TN
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $getinfo mysql_query("SELECT * FROM information" );
     
    while (
    $info mysql_fetch_array($getinfo)) {
        
    $age $info['age'];
        if (
    $age 20)
            
    $abc 'above 20';
        else if (
    $age == 20)
            
    $abc 'is 20';
        else
            
    $abc 'below 20';
        print 
    $age '<br>' $abc;

    There are 10 kinds of people in this world,
    those who can read binary and those who can't.

  3. #3
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm that's really quite simple so i was right in thinking it could be done like that. Thanks for the confirmation and help .


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
  •