I have here a code wherein I have an array of checkbox populated with mysql data through a query. I can successfully submit the value of the checked checkbox into a table in a database. But what I want to do is to save it according to the sequence the checkbox was checked by the user. I was told that I can achieve this through javascript but unfortunately, I’m not familiar with javascript at all. If possible, can you provide steps on achieving this through PHP only? If not, can you please guide me on how to achieve this using javascript since I’m a newbie. Here’s my sample code to let you imagine what I’m trying to do..
<?php
require("aacfs.php");
echo"<div align= center >
<table width=300 border= 1 align= right><tr><th align=center bgcolor=silver><font face=consolas>Choose Itinerary</font></th></tr>
<tr>
<td></br>
<form method=post>";
$result=mysql_query(" select * from itinerary group by location");
$y=mysql_affected_rows();
for($i=0;$i<$y;$i++)
{$row=mysql_fetch_array($result);
$pr=$row['icode'];
$n=$row['location'];
$l=$row['btime'];
echo"<table border=1 align=center width=250>
<tr><td width=15><input name=prod[] type=checkbox value='$pr'></td><td>$n</td></tr>
</table>";
$t=$_POST[prod];
}
echo"</td></tr></table>";
echo"
<table width= 664 border= 1 align= left >
<tr><td height= 282 ><p align= center class= style77>
<p align= right ><h4>$d</h4></p>
<p align= center ><font face=consolas><b>Itinerary List</b></font></p>
<p align=center><font face=consolas>To change your itinerary list, choose again.</font></p>
<br>
<center><input name=add type= submit value='Add to Itinerary List'></center>
<br>
<table width=654 border= 1>
<tr bgcolor = silver align=center>
<td>Itinerary</td>
<td>Block Time</td>
</tr></form>";
if(isset($_POST['add']))
{
if(isset($_POST[prod]))
{ foreach($t as $k)
{$result=mysql_query("select * from itinerary where icode='$k'");
$y=mysql_affected_rows();
for($x=0;$x<$y;$x++)
{$row=mysql_fetch_array($result);
$r=array($row['icode']);
$n=$row['location'];
$p=$row['btime'];
echo"<form method=post><tr>
<td>$n</td>
<td>$p</td>
</tr>";
$a=$_POST[pro];
$stat1='Not Submitted';
foreach($r as $a=>$l)
{
$kdot=mysql_query("select max(reservno) as 'maxr' from reservation") or die(mysql_error());
$row2=mysql_fetch_array($kdot);
$fi=$row2['maxr'];
mysql_query("insert into location_list(reservno, icode, location, status) values('$fi', '$l', '$n', '$stat1')") or die(mysql_error());
}
}}}
}
Clarifications are most welcome. Hope you can help me! Thanks a lot!
Got the detection of checked checkbox sequence through this code:
I’m binding it in my checkbox.
Then output it in a textarea.
I can save it in my database through this:
Thank you all for your help! God bless!