2 Replies - 6485 Views - Last Post: 03 July 2009 - 10:14 PM Rate Topic: -----

#1 yemi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-November 08

Selecting multiple data from database with checkbox

Posted 03 July 2009 - 09:42 AM

<---probem to sovle--->

Selecting multiple data from the Database with
checkbox and print/echo selected item.

This is how it goes, From the check_box.php page,
there are some date being retrieve from the database and bind with the check box,
so the check box is reference with id from the data then i create a repeat region to print more data on the table,
so after checking more than one check box from the data in the table. the order Action takes place in the select_chk.php page_script
i want to what to or how to create an array or loop that will accept this data so that it can be insert into another table

//Create Database
Create database chkboxes

//Create table
Create table tbl1

//Column of the table
Msgid
From
To
Message
<-----Below are the line of code----->

//check_box.php
<?php
$con = mysql_connect('localhost','root','')or die(mysql_error());
$db = mysql_select_db('chkboxes',$con)or die(mysql_error());
$query = mysql_query("SELECT * FROM tbl1")or die(mysql_error());
?><form Method="post" Action="select_chk.php" >
<?php  
while($result = mysql_fetch_assoc($query))
{
$i++;
?>
	  <tr>
		<td width="20%" align="center">
		<input name="<?php echo $result['Msgid']?>" type="checkbox" id="<?php echo $result['Msgid']?>" value="<?php echo $result['Msgid']?>">
		</label></td>
		<td width="20%" align="center"><?php echo $result['tFrom']?></td>
		<td width="20%" align="center"><?php echo $result['tTo']?></td>
		<td width="20%" align="center"><?php echo $result['Subject']?></td>
		<td width="20%" align="center"><?php echo $result['Message']?> </td>
	  </tr>
<?php
}
?>
	  <tr>
		<td align="center"><input type="submit" name="Submit" value="Submit" /></td>
<td align="center"> </td>
		<td align="center"> </td>
		<td align="center"> </td>
		<td align="center"> </td>
	  </tr>
	</table>
  </form>



//select_chk.php
<?php
$con = mysql_connect('localhost','root','duduyemi')or die(mysql_error());
$db = mysql_select_db('chkboxes',$con)or die(mysql_error());
$query = mysql_query("select * from tbl1");

$i=0;
while($r = mysql_fetch_array($query))
{
$msg = $r['Msgid'];
if(isset($_POST[$msg])!=NULL)
{
$i++;
mysql_query("select * from tbl1 Where Msgid=$msg")or die(mysql_error());
}
}
echo "Result".$i['tFrom']
?>



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: Selecting multiple data from database with checkbox

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Selecting multiple data from database with checkbox

Posted 03 July 2009 - 10:05 PM

Here is your select_chk.php
<?php
$con = mysql_connect('localhost','root','')or die(mysql_error());
$db = mysql_select_db('chkboxes',$con)or die(mysql_error());
$query = mysql_query("SELECT * FROM tbl1")or die(mysql_error());
$x = NULL;
while($fetch = mysql_fetch_assoc($query))
{
	$x++;
	if(isset($_POST[$x]))
	{
		echo $_POST[$x];
		// Here you can run querys to get data from one table and insert it into another table		
	}
}
?>

Was This Post Helpful? 0
  • +
  • -

#3 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Selecting multiple data from database with checkbox

Posted 03 July 2009 - 10:14 PM

also this tutorial will help you
http://www.dreaminco...topic108410.htm
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1