0

is it possible to sends two values in

 <option value="<?=$halls['id']?>"> 

I want to send like this

 <option value="<?=$halls['id']?><?=$halls['rang_from']?>">

here is the code.

 <?php

    //var_dump($_POST);

    $location=$_POST['location'];
    $hall_query=mysqli_query($connection,"select * from halls where location='$location' and status='enabled'");
    while($halls=mysqli_fetch_assoc($hall_query))
    {
        ?>
        <option value="<?=$halls['id']?>"><?=$halls['rang_from']?> To <?=$halls['rang_to']?></option>
    <?php
    }

    ?>
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • Depends on how you want your `select` element to be constructed. I am failing to understand what you are trying to achieve by sending `two` values to the `option` element – progrAmmar Oct 04 '18 at 05:43
  • 1
    Possible duplicate of [How to post two values in an option field?](https://stackoverflow.com/questions/8027163/how-to-post-two-values-in-an-option-field) – Nigel Ren Oct 04 '18 at 05:47

4 Answers4

1

use separator like '|@|' for example

const SEPARATOR = '|@|';

in form:

<select name="select_name">
    ....
    <option value="<?=$halls['id'] . SEPARATOR . $halls['rang_from']?>"><?=$halls['rang_from']?> To <?=$halls['rang_to']?></option>
    ....
</select>

and when receive:

list($id, $rang_from) = explode(SEPARATOR, $_REQUEST['select_name']);

echo "id is $id, rang_from is $rang_from";

id is 21, rang_from is home

soredive
  • 795
  • 1
  • 9
  • 25
0

you can do by add two values into the one value by separate like this in your server side explode the value like this explode('@@',$value) by explode function

<option value="<?=$halls['id'].'@@'.$halls['rang_from']?>">
<?=$halls['rang_from']?> To <?=$halls['rang_to']?></option>
Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
0

passing option value as an JSON array

<option 
     value="<?= json_encode(['id' => $halls['id'], 'rang_from' => $halls['rang_from']]) ?>">
     <?=$halls['rang_from']?> To <?=$halls['rang_to']?>
</option>

Then use json_decode to fetch the posted array.

noufalcep
  • 3,446
  • 15
  • 33
  • 51
0

Place both values into the value attribute, separated by "/"

<option value="<?=$halls['id'] . '/' . $halls['rang_from'] . '/' .  $halls['rang_to']?>"><?= $halls['rang_from']?> To <?=$halls['rang_to']?>
    </option>

And When if you want to Recieve It Then Write

list($hall_id, $rang_from, $range_to) = explode('/', $_REQUEST['hall']);

for Checking that values comes or Not... Write

echo $rang_from; exit;
Syed Waqas Ahmad
  • 134
  • 1
  • 14