Jump to content

rodrj

New Members
  • Posts

    1
  • Joined

  • Last visited

rodrj's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have a code on `page1.php` where I have an array of checkbox populated with mysql data through a query. I can successfully submit the value of the checked checkbox to the `page2.php`. But I want to submit it according to the sequence the checkbox was checked by the user. I´ve tried some javascript, but i´m not familiar to it. My intention is to show on `page2.php` what the user selected, on a specific order, from the `page1.php` form Any help will be appreciated. Thanks Here is my clean code. **page1.php** <?php $query = "SELECT * FROM imoveis"; $result = mysql_query($query,$conn); ?> <form action="page2.php" method="post"> <input type="submit" value="Create" id="enviarButton"/></td> <br><br> <table border="1"> <? $i = 0; echo "<tr>"; while($imovel = mysql_fetch_array($result)){ $name = $imovel['empreendimento']; $id = $imovel['id']; ?> <td> <?=$name;?><br> <input type="checkbox" name="op_imovel[]" value="<?=$id;?>"> </td> <? $i++; if(($i % 3) == 0){ echo "</tr><tr>"; } } mysql_close(); ?> </table> </form> **page2.php** <?php $checkbox = $_POST['op_imovel']; if (is_array($checkbox) && count($checkbox) > 0){ $res = ''; $tot = count($checkbox) - 1; for ($y = 0; $y <= $tot; $y++) { $res .=$checkbox[$y]; if ($y < $tot) $res .= ","; } } $query = "SELECT * FROM emps WHERE id IN ($res)"; $result = mysql_query($query,$conn); ?> <br> <div align="center"> <table border="1"> <? $i = 0; echo "<tr>"; if (is_array($checkbox) && count($checkbox) > 0){ while($imovel = mysql_fetch_array($result)){ $name = ($imovel['emp']); ?> <td> <p> <?= $name;?> </p> </td> <? $i++; if(($i % 3) == 0){ echo "</tr><tr>"; } } } ?> </div> <? mysql_close(); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.