SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed correcting this code

    Hello,

    I have been attempting to get this code below correct, yet I am lost!

    help appreciated

    PHP Syntax Check: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in your code on line 5

    PHP Code:

    PHP Code:
    <?php
      
    echo '<tr class="c1">
     <td><b>'
    MSG_ITEM_CONDITION'</b></td>
     <td>
     <? if ($item_details['
    item_condition']==0) { 'MSG_ITEM_CHOOSE_CONDITION' } 
        else if ($item_details['
    item_condition']==1) { 'MSG_ITEM_NEW' } 
        else if ($item_details['
    item_condition']==2) { 'MSG_ITEM_VERY_GOOD' } 
        else if ($item_details['
    item_condition']==3) { 'MSG_ITEM_GOOD'} 
        else if ($item_details['
    item_condition']==4) { 'MSG_ITEM_AVERAGE' } 
        else if ($item_details['
    item_condition']==5) { 'MSG_ITEM_POOR' } 
        else if ($item_details['
    item_condition']==6) { 'MSG_ITEM_DEFECTIVE'></td>
        </tr>'
    ;
        
    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by RayWilk View Post
    PHP Code:
    <?php
      
    echo '<tr class="c1">
     <td><b>'
    MSG_ITEM_CONDITION'</b></td>
     <td>
     <? if ($item_details['
    item_condition']==0) { 'MSG_ITEM_CHOOSE_CONDITION' } 
        else if ($item_details['
    item_condition']==1) { 'MSG_ITEM_NEW' } 
        else if ($item_details['
    item_condition']==2) { 'MSG_ITEM_VERY_GOOD' } 
        else if ($item_details['
    item_condition']==3) { 'MSG_ITEM_GOOD'} 
        else if ($item_details['
    item_condition']==4) { 'MSG_ITEM_AVERAGE' } 
        else if ($item_details['
    item_condition']==5) { 'MSG_ITEM_POOR' } 
        else if ($item_details['
    item_condition']==6) { 'MSG_ITEM_DEFECTIVE'></td>
        </tr>'
    ;
        
    ?>
    Notice that the echo doesn't have a closing quote, so PHP thinks that the <? is part of the string. When it gets to the single quote in $item_details[' is sees that as the end of the string and expects a semi-colon to end the string, or a comma to add another string to the echo, which is why you get that error.

    To fix it you need to end the string properly, by adding a single quote and semi-colon to the end of <td> on line 4, as so:

    PHP Code:
    <?php 
      
    echo '<tr class="c1"> 
     <td><b>'
    MSG_ITEM_CONDITION'</b></td> 
     <td>'
    ;
    Because you have to end that string there you must also begin it again inside the if/else statements...

    PHP Code:
     <? if ($item_details['item_condition']==0) { echo MSG_ITEM_CHOOSE_CONDITION; }  
        else if (
    $item_details['item_condition']==1) { echo MSG_ITEM_NEW; }  
        else if (
    $item_details['item_condition']==2) { echo MSG_ITEM_VERY_GOOD; }  
        else if (
    $item_details['item_condition']==3) { echo MSG_ITEM_GOOD; }  
        else if (
    $item_details['item_condition']==4) { echo MSG_ITEM_AVERAGE; }  
        else if (
    $item_details['item_condition']==5) { echo MSG_ITEM_POOR; }  
        else if (
    $item_details['item_condition']==6) { echo MSG_ITEM_DEFECTIVE; }

    echo 
    '</td> 
        </tr>'

        
    ?>

  3. #3
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello LeonardChallis

    thank you for your quick reply and help

    ok I put them together like this:

    PHP Code:
    <?php 
      
    echo '<tr class="c1"> 
     <td><b>'
    MSG_ITEM_CONDITION'</b></td> 
     <td>'

    <? if (
    $item_details['item_condition']==0) { echo MSG_ITEM_CHOOSE_CONDITION; }  
        else if (
    $item_details['item_condition']==1) { echo MSG_ITEM_NEW; }  
        else if (
    $item_details['item_condition']==2) { echo MSG_ITEM_VERY_GOOD; }  
        else if (
    $item_details['item_condition']==3) { echo MSG_ITEM_GOOD; }  
        else if (
    $item_details['item_condition']==4) { echo MSG_ITEM_AVERAGE; }  
        else if (
    $item_details['item_condition']==5) { echo MSG_ITEM_POOR; }  
        else if (
    $item_details['item_condition']==6) { echo MSG_ITEM_DEFECTIVE; }
        echo 
    '</td> 
        </tr>'

        
    ?>
    yet a new Error code:

    Parse error: syntax error, unexpected '<' in /home/a1740368/public_html/themes/ultra/templates/auction_details.tpl.php on line 261

    PHP Code:
    257<?php 
    258  
    echo '<tr class="c1"> 
    259 <td><b>'
    MSG_ITEM_CONDITION'</b></td> 
    260 <td>'

    261<? if ($item_details['item_condition']==0) { echo MSG_ITEM_CHOOSE_CONDITION; } 
    262    else if ($item_details['item_condition']==1) { echo MSG_ITEM_NEW; }  
    263    else if ($item_details['item_condition']==2) { echo MSG_ITEM_VERY_GOOD; }  
    264   else if ($item_details['item_condition']==3) { echo MSG_ITEM_GOOD; }  
    265    else if ($item_details['item_condition']==4) { echo MSG_ITEM_AVERAGE; }  
    266    else if ($item_details['item_condition']==5) { echo MSG_ITEM_POOR; }  
    267    else if ($item_details['item_condition']==6) { echo MSG_ITEM_DEFECTIVE; }
    268    echo '</td> 
    269    </tr>'

    270   ?>

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My bad - remove that <? on line 5.

    By the way, is this using a template system, as sometimes the template systems have custom syntax that will work that isn't native PHP, so bear that in mind.

  5. #5
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK all fixed

    I removed the <? from line 261

    261<? if ($item_details['item_condition']==0) { echo MSG_ITEM_CHOOSE_CONDITION; }

    thank you LeonardChallis

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem


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
  •