0

I want to store 2 variables in a value, but I not sure with the syntax. The scenario: I want to store $boothAlias and $day2 into checkbox value to be pass to other page.

<input name='totalDay[]' type='checkbox' value='$boothAlias.$day2'/>

My code segment

while($rows = mysql_fetch_array($result2)){
  $boothAlias=$rows['boothAlias'];
  $totalDay=$rows['totalDay'];
  echo "<tr><td>$boothAlias</td>";
  for ($day2 = 1; $day2 <= $totalDay; ++$day2) {
    echo "<td><input name='totalDay[]' type='checkbox' value='$boothAlias.$day2'/></td>";
  }
  echo "</tr>";
}

3 Answers 3

2

The easiest thing would be to use some sort of delimeter.

"<td><input name='totalDay[]' type='checkbox' value='$boothAlias|$day2'/></td>";

Notice the "|" delimeter.

Then in your PHP code, to get the two values:

$totalDays = $_POST['totalDay'];
$value = explode("|",$totalDays[0]);
echo $value[0];
echo $value[1];
//this would output
boothAlias_value
day2_value

Not sure if that made total sense, but the idea to store multiple values in a string, is to use a delimeter, and then to convert to an array in PHP.

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

Comments

1

I think you would be better off using hidden form fields to pass data like that to your processing script. The checkbox form object is really designed for returning checked/unchecked (true/false). Depending on the value of the checkbox you can process the code and variables accordingly.

Comments

0
<input name='totalDay[$boothAlias]' type='checkbox' value='$day2'/>

Comments

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.