PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,404 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,622 people online right now. Registration is fast and FREE... Join Now!




Selecting multiple data from database with checkbox

 

Selecting multiple data from database with checkbox

yemi

3 Jul, 2009 - 08:42 AM
Post #1

New D.I.C Head
*

Joined: 6 Nov, 2008
Posts: 9

<---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
CODE

<-----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.gif

Thanks,
PsychoCoder smile.gif

User is offlineProfile CardPM
+Quote Post


noorahmad

RE: Selecting Multiple Data From Database With Checkbox

3 Jul, 2009 - 09:05 PM
Post #2

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
Here is your select_chk.php
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
}
}
?>

User is online!Profile CardPM
+Quote Post

noorahmad

RE: Selecting Multiple Data From Database With Checkbox

3 Jul, 2009 - 09:14 PM
Post #3

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
also this tutorial will help you
http://www.dreamincode.net/forums/showtopic108410.htm
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:33PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month