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
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
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…
<? 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>';
?>
Hello LeonardChallis
thank you for your quick reply and help
ok I put them together like this:
<?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
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 ?>
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.
OK all fixed
I removed the <? from line 261
261<? if ($item_details[‘item_condition’]==0) { echo MSG_ITEM_CHOOSE_CONDITION; }
thank you LeonardChallis