0

If the website id 0 I would like to add $this->lang->line('text_default'); otherwise does not show that lang line. Currently it shows on all of them.

How can I get it to only display $this->lang->line('text_default) if $website['website_id'] = number 0

For some reason it thinks 0 is false.

<?php if ($website['website_id'] = 0) {?>
<td class="text-left"><?php echo $website['name'];?> </td>
<?php } else { ?>
<td class="text-left"><?php echo $website['name'] . $this->lang->line('text_default'); ?> </td>
<?php } ?>
Rasclatt
  • 12,498
  • 3
  • 25
  • 33

2 Answers2

1

Try making a double equal sign:

FROM: ($website['website_id'] = 0)

TO: ($website['website_id'] == 0)

<?php if ($website['website_id'] == 0) {?>
<td class="text-left"><?php echo $website['name'];?> </td>
<?php } else { ?>
<td class="text-left"><?php echo $website['name'] . $this->lang->line('text_default'); ?> </td>
<?php } ?>

StackOverflow regarding operators: Reference - What does this symbol mean in PHP?

Community
  • 1
  • 1
Rasclatt
  • 12,498
  • 3
  • 25
  • 33
0

First of all:

<?php if ($website['website_id'] = 0) { ?>

This is wrong, use a comparisation operator instead of an assignment.

<?php if ($website['website_id'] == 0) {?>

You overwrote your $website["website_id"] with 0 and same turn you forced your if-expresion to be always true.

This happens when you place only one "=", a very common beginner mistake.

However I cannot tell you wether 0 is right or wrong because I dont know codeigniter and what is stored in $website["website_id"], or even if its always filled. Incase its still not working analyze the variable with

var_dump($website['website_id']); 

and do different page calls.

Steini
  • 2,753
  • 15
  • 24