SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    Wigan, UK
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with an if statement

    i want to display a graphic according to wether or not a value (currently_available) equals y or n in the database e.g.
    PHP Code:
    if ($currently_unavailble=y)
       {
       echo 
    "<IMG SRC=yes.jpg>";
       }
       else
       {
       echo 
    "<IMG SRC=no.jpg>";   

    for some reason i cant get the code to work. any idea's?
    This post is brought to you in association with Carling - The UK's Premier Lager

  2. #2
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you need to enclose the Y with quotes?

    if ($currently_unavailble="y")

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    Wigan, UK
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ive tried that and it didnt work
    This post is brought to you in association with Carling - The UK's Premier Lager

  4. #4
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what about your = sign i'm not sure if php needs the double == or not..

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by platinum
    what about your = sign i'm not sure if php needs the double == or not..
    Exactly, "=" assigns a value. "==" is a comparison operator.

    so $currently_unavailable="y", sets the variable to "y". Where == will compare the contents of the variable against "y" and return a result.

    Kix

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank God you jumped in there, kix... Anyways, yeah, that = needs to be ==

    Way to be proactive, Gav...you'll get PHP yet.

    Sketch
    Aaron Brazell
    Technosailor



  7. #7
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oy -- I got it right first

  8. #8
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aaron Brazell
    Technosailor



  9. #9
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    Wigan, UK
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    putting a == doesnt work either for some reason.

    heres the code im using (sorry if its too much to post)

    PHP Code:
    mysql_select_db("lapdancers");
      
    $query "select dancerID, name, age, nationality,  picture, currently_available from dancers";
      
    $result mysql_query($query);

      
    $num_results mysql_num_rows($result);

      echo 
    "<FONT SIZE=2>";

      echo 
    "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>";
      echo 
    "<TR><TD></TD><TD><FONT FACE=Verdana SIZE=2 COLOR=#1591F1>NAME</TD><TD><FONT FACE=Verdana SIZE=2 COLOR=#1591F1>AGE</TD><TD><FONT FACE=Verdana SIZE=2 COLOR=#1591F1>NATIONALITY</TD><TD></TD><TD></TD></TR>";

         echo 
    "<TR><TD COLSPAN=7>";
         echo 
    "<HR WIDTH=100% COLOR=#1591F1 SIZE=1>";
         echo 
    "</TD></TR>";

      for (
    $i=0$i <$num_results$i++)
      {
         
    $row mysql_fetch_array($result);
         echo 
    "<TR>";

         echo 
    "<TD WIDTH=20>";

    if (
    $currently_available=="y")
        {
        echo 
    "<IMG SRC=yes.jpg>";
        }
        else
        {
        echo 
    "<IMG SRC=no.jpg>";
        }

         echo 
    "</TD>";

         echo 
    "<TD WIDTH=150><FONT SIZE=2>";
         echo 
    stripslashes($row["name"]);
         echo 
    "</TD><TD WIDTH=70><FONT SIZE=2>";
         echo 
    stripslashes($row["age"]);
         echo 
    "</TD><TD WIDTH=150><FONT SIZE=2>";
         echo 
    stripslashes($row["nationality"]);
         echo 
    "</TD><TD WIDTH=60><FONT SIZE=2>";
         echo 
    "<A HREF=";
         echo 
    stripslashes($row["picture"]);
         echo 
    " TARGET=_blank>Picture</A>";
         echo 
    "</TD><TD WIDTH=65><FONT SIZE=2>";
         echo 
    "<A HREF=girls.php?dancerID=";
         echo 
    stripslashes($row["dancerID"]);
         echo 
    ">";
         echo 
    "More Info</A>";

         echo 
    "</TD></TR>";
         echo 
    "<TR><TD COLSPAN=7>";
         echo 
    "<HR WIDTH=100% COLOR=#1591F1 SIZE=1>";
         echo 
    "</TD></TR>";

      }
      echo 
    "</TR></TABLE>";

    ?> 
    This post is brought to you in association with Carling - The UK's Premier Lager

  10. #10
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    at which point did you initialize $currently_available?
    as in:

    Code:
    $currently_available = $row["currently_available"];
    Or to something else? I don't see you setting that variable but you're using it in a comparison.

    kix

  11. #11
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    Wigan, UK
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats were i screwed up, got it working now, cheers guys
    This post is brought to you in association with Carling - The UK's Premier Lager


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
  •