SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can if statement be used in while...?

    Please find the coding I wish to use below...

    //display hotel comments...
    echo("<table border=1 width=100%><tr><td>&nbsp;</td><td align=center>Hotel</td><td align=center>Resort</td></tr>");
    while ( $row = mysql_fetch_array($result) ) {
    echo("<tr><td>");


    if ($approved == 1) {
    echo("<font>" . $row["approved"] . "</font>");
    } else {
    echo("?");
    }


    echo("</td><td><font size=3><a href=\"hotel.php?hot_id=" . $row["hotid"] . "&ban=" . $row["hotid"] . "&name=" . $row["hotname"] . "&are=" . $row["area"] . "&reso=" . $row["res"] . "\">" . $row["hotname"] . "</a></font></td>");
    echo("<td><font size=3>" . $row["area"] . "</font></td></tr>");

    }
    echo("</table>");

    In the if statement above I am attempting to either return the value of "approved" if that value is 1 or a ? if the value of approved is not 1 ie 0 as this is the only other otion available...

    However on running the script all listings are set as ? If I change the if statement to 0 instead of 1 then the value of approved is return regardless of its content ie 1 and 0 returned in the table and no ?'s...

    Is there a coding error you can see?
    Or is the if statement not allowed within a while statement...??

    TIA

    Vanlaywan

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change

    PHP Code:
    if ($approved == 1) { 
    to

    PHP Code:
    if ($row["approved"] == 1) { 
    I could be misunderstanding you, but I think that should do the trick.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thaks very much...

    That fixed it...


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
  •