SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A simple if { } statement -- can't find the syntax error -- HELP

    Hey--

    PHP Code:
    // Display the text in the table
    while ( $row mysql_fetch_array($result) ) {
    $ID $row["ID"];
    $priority $row["priority"];
    $subject $row["subject"];
    $details $row["details"];
    echo( 
    "<tr style='background-color: #" . ($i++ & 'CED6E1' 'EBEEF3') . "'>" .
    "<td align='center'>" .
    if (
    $priority "1") {
    echo (
    "<img src='images/low.gif'>");
    }
    if (
    $priority "2") {
    echo (
    "<img src='images/med.gif'>");
    }
    if (
    $priority "3") {
    echo (
    "<img src='images/high.gif'>");
    } . 
    "</td>" .
    "<td align='center'>$subject</td>" .
    "<td align='center'>$details</td>" .
    "<td align='center'><a href='$PHP_SELF?tododone=$ID'>Done</a> | <a href='edittodo.php?ID=$ID'>Edit</a></td></tr>");
    }
    ?> 
    Error: Parse error: parse error in c:\phpdev\www\hw_tests\index.php on line 206

    Line 206 (from above):
    PHP Code:
    if ($priority "1") { 
    Last edited by Adam P.; Sep 1, 2002 at 13:46.
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  2. #2
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo( "<tr style='background-color: #" . ($i++ & 'CED6E1' 'EBEEF3') . "'>" .
    "<td align='center'>" .
    if (
    $priority "1") { 
    You aren't closing the 'echo'. Not with a ')', nor with a ';'. Instead you're using the string concatenation operator ('.') which flows into the if-statement. That's not going to work.

    Note, BTW, that you can write your echo-statement like this:

    PHP Code:
    echo '<tr style="background-color: #', ($i++ & 'CED6E1' 'EBEEF3'), '"><td align="center">'
    By not using parentheses, you're making clear echo is not a normal function (which it isn't). Also, using ',' instead of '.' is a lot faster. Finally, not only does the HTML standard say that you ought to prefer double quotes instead of single quotes for attributes (so align="center" instead of align='center'), as you're not doing any string substitutions, single quotes for PHP output are a better option (they're slightly faster).

    Vincent

  3. #3
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are not comparing values you are assigning them

    PHP Code:
    if ($priority "3") { 
    and the others if statements should be

    PHP Code:
    if ($priority == 3) { 


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
  •