Php if condition inside if condition not working

I am trying to write the below script inside my php file. Its giving me error. Something is wrong pls help.
There seems to be problem with syntax, in echo

											<?php if(!empty($alter_details)){ $total = 0;?> <?php foreach ($alter_details as $list) {?>
												<tr>
													<td><?php echo $list->status?></td>
													<td>
														 
														
														<?php if($list->order_status == 5){echo <a href="javascript:void(0);" onclick="add_alter_details('<?php echo $list->details_id;?>')">Alter</a>;}elseif($list->order_status == 0){echo "Pending";}?>
														
														</td>
														
												</tr>
											<?php $total = $total + $list->amount; } ?>
										<?php } ?>
<?php if($list->order_status == 5){echo <a href="javascript:void(0);" onclick="add_alter_details('<?php echo $list->details_id;?>')">Alter</a>;}elseif($list->order_status == 0){echo "Pending";}?>

echo needs to echo a variable (started with a $ sign) or a string (surrounded with '' or ""). Your first echo does neither of those. It looks like you’re probably trying to do the following:

<?php
if ($list->order_status == 5) {
    echo '<a href="javascript:void(0);" onclick="add_alter_details(' . $list->details_id . ')">Alter</a>';
} elseif ($list->order_status == 0) { 
    echo 'Pending';
}
?>

Note the new quote marks in your first echo statement.

Trying to do too much on a single line will often trip you up like this.

As an aside, you should include any errors you receive when asking questions; it will help people help you.

1 Like

Thank you so much. Thats indeed perfect.
You helped me to learn this .

Sponsor our Newsletter | Privacy Policy | Terms of Service