Reputation: 766
Originally,Regardless of the type of language,three columns will be display in the table, each display different languages of message, each saved into different column in the database
<td><textarea name="traditionalmessage[]" ><?php echo $row['traditionalmessage'];?></textarea> </td>
<td><textarea name="simplifiedmessage[]" ><?php echo $row['simplifiedmessage'];?></textarea> </td>
<td> <textarea name="engmessage[]"><?php echo $row['engmessage'];?></textarea> </td>
Now on the display page, i want to display only one column depends on the type of language in the db eg.if the language is ENG, only the eng message will be shown, and other column will be hidden, can it be done with php if else or does it invloves jquery
I have tried the if else,but it doesnt work.Any thoughts. Thanks
<td><textarea name="traditionalmessage[]"><?php
if($row['language']=='tra'){
echo $row['traditionalmessage'];}?></textarea>
<textarea name="simplifiedmessage[]"><?php
if($row['language']=='sim'){
echo $row['simplifiedmessage'];}?></textarea>
<textarea name="engmessage[]" ><?php
if($row['language']=='ENG'){
echo $row['engmessage'];?></textarea> </td>
Upvotes: 1
Views: 106
Reputation: 33933
This PHP code below find $row['language']
content ("tra","sim" or "eng") in the $possibleLang
array and gets the index back in $index
.
This index makes the relationship between the "short language name" and the "long" one.
<?php
$possibleLang = ["tra","sim","eng"];
$testAreaField = ["traditionalmessage","simplifiedmessage","engmessage"];
$treatmentName = ["treatmentname1","treatmentname2","treatmentname3"];
$treatmentNameSuffix = ["下一個注射期為","下一个注射期为","Next injection period will be"];
$index = array_search($row['language'],$possibleLang);
?>
<td>
<textarea name="<?php echo $testAreaField[$index]; ?>[]" data-value="<?php echo $row[$treatmentName[$index]] . $treatmentNameSuffix[$index]; ?>">
<?php echo $row[$testAreaField[$index]]; ?>
</textarea>
</td>
Upvotes: 1
Reputation: 148
<td>
<?php if($row['language']=='tra'){ ?>
<textarea name="traditionalmessage[]"><?php echo $row['traditionalmessage'];}?></textarea>
<?php } ?>
<?php if($row['language']=='sim'){?>
<textarea name="simplifiedmessage[]"><?php echo $row['simplifiedmessage'];}?></textarea>
<?php } ?>
<?php if($row['language']=='ENG'){?>
<textarea name="engmessage[]" ><?php echo $row['engmessage'];?></textarea>
<?php } ?>
</td>
Upvotes: 0