Make an IF statment on table text?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Breana
    New Member
    • Aug 2007
    • 117

    Make an IF statment on table text?

    Ok, what i want to do is make it if the users gender is Female, it will echo the Female.png and if its Male, echo the Male.png is this possible?

    The table gender dont have any values like M, 1 just (Male, Female, Hidden)
    Can this be done easily?
  • gregerly
    Recognized Expert New Member
    • Sep 2006
    • 192

    #2
    Originally posted by Breana
    Ok, what i want to do is make it if the users gender is Female, it will echo the Female.png and if its Male, echo the Male.png is this possible?

    The table gender dont have any values like M, 1 just (Male, Female, Hidden)
    Can this be done easily?
    Ok, here's what I understand about your post:

    You are collecting user data somehow, registration form, login, etc...and you have access to their gender. The gender is stored in the Gender table.

    If the above is accurate then you would need to query for gender, and then load an appropriate img based on gender. Here is how I would do this:

    [PHP]<?php

    //query for the gender, your sql will vary based on table fields
    $sql="SELECT gender_tbl.gend er FROM gender_tbl WHERE gender_tbl.user id = $userid";
    $result=@mysql_ query($sql);
    list($gender)=@ mysql_fetch_row ($result);

    //create a variable to load proper variable
    $loadImg=($gend er=="male")?"ma le.png":"female .png";

    ?>[/PHP]
    Then when you need to load the the img

    [PHP]<img src='./path/to/img/<?=$loadImg; ?>' alt='Your alt text' />[/PHP]

    Comment

    • Breana
      New Member
      • Aug 2007
      • 117

      #3
      Thanx for the reply, i allready solved it im bad i wont post help in tell i am stuck lol i just made it so when they signed up and selected there gender it saved the image code instead of the text lol..

      But you can maybe awnser this for me i cant do it i have been trying all day..
      How can i limit the number of results to 10 and have a Next >> button appear or << Back on the bottom if there is more than 10 users?

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Check out this post.

        And please try to post new questions in new threads.

        Comment

        Working...