Page 1 of 1
massive with ckeckbox
Posted: Tue Dec 04, 2007 2:47 pm
by the_power
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.
Posted: Tue Dec 04, 2007 3:37 pm
by waradmin
Please re-word the question, in its current state it is nearly impossible to help you.
sorry
Posted: Tue Dec 04, 2007 5:09 pm
by the_power
feyd | Please use 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>
<?
}
}
?>
when i select one or more checkboxs i want to execute this, but how?:
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
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
Posted: Tue Dec 04, 2007 6:17 pm
by yacahuma
name your checkboxes like so
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 />
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
Posted: Wed Dec 05, 2007 3:05 am
by the_power
this is my form
Code: Select all
<form action='moves.php?id=<?php print_r($_POST); ?>' method='post'>
I edit the checkbox this:
Code: Select all
<td width="12%"><center><input type="checkbox" name="mchk1[]" value="<?=strval( $row['id'] );?>"></center></td>
And value get the id on the table row.
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;");
More Info
Posted: Wed Dec 05, 2007 4:47 am
by yacahuma
Do you want to move all at one time?
or
Do you want to move one at a time?
What is your main language? (spanish?)
sample code
Posted: Wed Dec 05, 2007 5:01 am
by yacahuma
This is a very simple example of how that works
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>
and the in the move.php you will have something like this
Code: Select all
foreach($_POST['idchk'] as $id)
{
echo 'THe selected id is' . $id . '<br />';
//DO ANY SQL PER ID
}
thanks
Posted: Wed Dec 05, 2007 5:45 am
by the_power
No, I'm from Bulgaria.
Yes i want to move all at one time.Your example is very good.
Thanks for example.