简体   繁体   中英

How do I pass multiple variables to function within PHP statement?

Trying to call function Sel_item and pass it the fieldname1 variable as well as the id . The passing of the id works fine, but as soon as I try to pass the fieldname1 , it dies. Basically trying to pass the id and the name of the person in mysql database to another function.

$id = $row["id"];
$fieldname1 = $row["person_name"];
$fieldname2 = $row["check_in_butt"];
$fieldname3 = $row["date_time"];
$str = "";
if($fieldname2 == true) $str = "checked";
 
echo '<tr> 
  <td>'.$fieldname1.'</td>
  <td><input type="checkbox"'.$str. 'onclick="Sel_item('.$id.,.$fieldname1.')" </td>

I usually make it like this. Work for me

<?php
$id = $row["id"];
$fieldname1 = $row["person_name"];
$fieldname2 = $row["check_in_butt"];
$fieldname3 = $row["date_time"];
$str = "";
if($fieldname2 == true) $str = "checked";
?>

<tr> 
    <td><?= $fieldname1 ?></td>
    <td><input type="checkbox" <?= $str ?> onclick="Sel_item('<?= $id ?>', '<?= $fieldname1 ?>')"></td>
</tr>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM