0

So I have a mysql table for the charges of a hospital. My program currently only gets the price of the checked procedure. But now, I also want to get the procedure name when it is checked.

while($row = mysql_fetch_array($result)){

            echo '
            <tr>
                <td>'.$row[0].'</td>
                <td>'.$row[1].'</td>
                <td>'.$row[2].'</td>';
                $price=$row['price'];
            echo '<td><input type="checkbox" name="er[]" value="'.$price.'"></td>';
            echo "</tr>";

        }
        echo '</table>';

So basically I need to edit this part of the code:

$price=$row['price'];
echo '<td><input type="checkbox" name="er[]" value="'.$price.'">

It only gets the row for price. Can the value attribute have two values? I can't just make another checkbox cause that would be inappropriate.

2 Answers 2

1

change the code like this

<?
while($row = mysql_fetch_array($result)){

            echo '
            <tr>
                <td>'.$row[0].'</td>
                <td>'.$row[1].'</td>
                <td>'.$row[2].'</td>';
                $price=$row['price'];
        $procedure_name=$row['$procedure_name'];
            echo '<td><input type="checkbox" name="er" value="'.$price.','.$procedure_name.'"></td>';
            echo "</tr>";

        }
        echo '</table>';
?>

Then use explode()

Sign up to request clarification or add additional context in comments.

1 Comment

It says: Warning: explode() expects parameter 2 to be string, array I forgot to mention i have two files. One for the checkbox form and then a php file after submission. So I have to POST the variables used in the first file. And the er[] value has two values, the procedure name and the price.
1

You could simply put the name in another attribute (like title) and whenever you need to get the name you can use some javascript to retreive it.

$price=$row['price'];
echo '<td><input type="checkbox" name="er[]" value="'.$price.'" title="'.$name.'">

1 Comment

Can't you retrieve it using simple POST method on php?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.