🐘 PHP Mga IT Gods Need your help

Status
Not open for further replies.
nakikita mo yung "All"
pindutin mo yon
1656263347367.webp
 
solve na?

<td>
<p class="m-0">
<?php
if($row['type'] == 1){
echo = "Administrator";
}
if($row['type'] == 2){
echo = "Staff";
}
if($row['type'] == 3){
echo = "Process Owner";
}
if($row['type'] == 4){
echo = "Auditor";
}
if($row['type'] == 5){
echo = "Auditor Lead";
}
if($row['type'] == 6){
echo = "QAH";
}
if($row['type'] == 7){
echo = "Team Management";
}
if($row['type'] == 8){
echo = "Human Resource";
}

?>
</p>
</td>

try this
 
solve na?

<td>
<p class="m-0">
<?php
if($row['type'] == 1){
echo = "Administrator";
}
if($row['type'] == 2){
echo = "Staff";
}
if($row['type'] == 3){
echo = "Process Owner";
}
if($row['type'] == 4){
echo = "Auditor";
}
if($row['type'] == 5){
echo = "Auditor Lead";
}
if($row['type'] == 6){
echo = "QAH";
}
if($row['type'] == 7){
echo = "Team Management";
}
if($row['type'] == 8){
echo = "Human Resource";
}

?>
</p>
</td>

try this
ahahahah ganyan nga mas madali e kaso gusto niya ternary operation HAHAHA
 
Huwag ka mag daisy chain ng if/else. Either mag-map ka ng array or switch() kung walang choice.

Mag declare ka ng array na yung number ang key tapos yung value yung role string. Tapos gamitin mo yung $row['type'] as key ng bagong gawang $roles array.

Code:
<?php
    $roles = [
        1 => 'Administrator',
        2 => 'Staff',
        3 => 'Process Owner',
        4 => 'Auditor',
        5 => 'Auditor Lead',
        6 => 'QAH',
        7 => 'Team Management',
        8 => 'Human Resource'
    ];
?>

<td ><p class="m-0"><?php echo( $roles[$row['type']] ) ?></p></td>
 
Try mo yung akin, mas maiksi. Bad newbie habit yang mahabang if-else kung pwede naman mag reference sa array of values, wag mong sanayin sarili mo sa spaghetti coding.
 
Status
Not open for further replies.

About this Thread

  • 116
    Replies
  • 5K
    Views
  • 13
    Participants
Last reply from:
Lianhua

Trending Topics

Online now

Members online
753
Guests online
1,389
Total visitors
2,142

Forum statistics

Threads
2,272,154
Posts
28,940,554
Members
1,238,032
Latest member
Yoshitsu
Back
Top