user13695235
user13695235

Reputation:

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>

Upvotes: 0

Views: 69

Answers (1)

Abdullah Ubaid
Abdullah Ubaid

Reputation: 33

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>

Upvotes: 1

Related Questions