massive with ckeckbox
Moderator: General Moderators
massive with ckeckbox
I have massive with checkbox on a table.
If i check a lot of checkbox and submit take data on the each rows and insert into ready ..... after that delete from request.
If i check a lot of checkbox and submit take data on the each rows and insert into ready ..... after that delete from request.
sorry
feyd | Please use
when i select one or more checkboxs i want to execute this, but how?:
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
sorry but my english isn't very good.
I have this code:Code: Select all
<?php
$groupe = mysql_query("SELECT * FROM `grupa` WHERE `office`='".$users['office']."' and `idgrupa`='".$users['grupa']."' ORDER BY `id` DESC;");
while($row_list=mysql_fetch_assoc($groupe)){
$sql = mysql_query("SELECT * FROM `request` WHERE `office`='".$users['office']."' and `kurier`='".$row_list['imecur']."' and `date`='".date("d.m.Y")."' ORDER BY `id` DESC;");
while($row=mysql_fetch_array($sql)){
?>
<tr class="initial" onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
<td width="15%" onclick="document.location.href='move.php?id=<?php print($row['id']); ?>'" style="cursor: pointer"><center><?php print (stripslashes(htmlspecialchars($row['name']))); ?></center></td>
<td width="18%"><center><?php print (stripslashes(htmlspecialchars($row['address']))); ?></center></td>
<td width="14%"><center><?php print (stripslashes(htmlspecialchars($row['gsm']))); ?></center></td>
<td width="15%"><center><?php print (stripslashes(htmlspecialchars($row['chas']))); ?></center></td>
<td width="12%"><center><?php print (stripslashes(htmlspecialchars($row['kurier']))); ?></center></td>
<td bgcolor="#DFE8F2" width="9%" onclick="window.open('edit.php?id=<?php print($row['id']); ?>','mywindow','width=350,height=360')" style="cursor: pointer"><center><img alt="" src="files/edit.png"><center></td>
<td bgcolor="#DFE8F2" width="9%" style="cursor: pointer" onclick="document.location.href='delete.php?id=<?php print($row['id']); ?>'"><center><img alt="" src="files/delete.png"><center></td>
<td width="12%"><center><input type="checkbox" name="C1" value="ON"></center></td>
</tr>
<?
}
}
?>Code: Select all
$id = (isset($_GET['id']))?(int)$_GET['id']:null;
$client = mysql_fetch_array(mysql_query("SELECT * FROM `request` WHERE `id`='".$id."'"));
$sql = "INSERT INTO `gotovi` (`id`, `office`, `name`,`address`, `gsm`,`chas`,`kurier`,`date`) VALUES (NULL,'".$client['office']."','".$client['name']."','". $client['address']."','".$client['gsm']."','". $client['chas']."','".$client['kurier']."','".$client['date']."');";
mysql_query($sql) or print(mysql_error());
mysql_query("DELETE FROM `request` WHERE `id`='".$id."' LIMIT 1;");
Header("Refresh: 0.01; URL= listclient.php");
echo '<script>alert("Request is comp.");</script>';feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]use array names
name your checkboxes like so
When you submit the data you will get an array with all the selections. Then call your code
use
print_r($_POST) or ($_GET) depending on your form
so you can see what you get
Code: Select all
<input type="checkbox" value="A" name="mchk1[]" />label a<br />
<input type="checkbox" value="B" name="mchk1[]" />label b<br />
<input type="checkbox" value="C" name="mchk1[]" />label c<br />use
print_r($_POST) or ($_GET) depending on your form
so you can see what you get
this is my form
I edit the checkbox this:
And value get the id on the table row.
What i write in moves.php to execute this script:
Code: Select all
<form action='moves.php?id=<?php print_r($_POST); ?>' method='post'>Code: Select all
<td width="12%"><center><input type="checkbox" name="mchk1[]" value="<?=strval( $row['id'] );?>"></center></td>What i write in moves.php to execute this script:
Code: Select all
$client = mysql_fetch_array(mysql_query("SELECT * FROM `request` WHERE `id`='".$id."'"));
$sql = "INSERT INTO `gotovi` (`id`, `office`, `name`,`address`,`gsm`,`chas`,`kurier`,`date`) VALUES (NULL,'".$client['office']."','".$client['name']."','".$client['address']."','". $client['gsm']."','".$client['chas']."','". $client['kurier']."','".$client['date']."');";
mysql_query($sql) or print(mysql_error());
mysql_query("DELETE FROM `request` WHERE `id`='".$id."' LIMIT 1;");sample code
This is a very simple example of how that works
in one page
and the in the move.php you will have something like this
in one page
Code: Select all
<form action="move.php" method="post">
<input type="checkbox" name="idchk[]" value="1" />
<input type="checkbox" name="idchk[]" value="2" />
<input type="checkbox" name="idchk[]" value="3" />
<input type="submit" name="movebtn" value="Move" />
</form>Code: Select all
foreach($_POST['idchk'] as $id)
{
echo 'THe selected id is' . $id . '<br />';
//DO ANY SQL PER ID
}