472,101 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

Using check box in table to select records

Hello all
I have the following PHP script to place records from my MySql db into a
table. However I now wish users to beable to select the multiple records
from the table and on clicking a button the selected records are stored to
another table in my db. I have started by including a check box in the first
column but dont know the code necessary to check all the row in the table
and copy the records of those boxes thats ticked
Can anyone help?
Thanks
Ian
*****************************************
<table width="1022" border="2" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="48"><div align="left"><span
class="style2">Select</span></div></td>
<td width="91"><span class="style2">Question No </span></td>
<td width="527"><span class="style2">Question</span></td>
<td width="42">path</td>
<td width="42"><span class="style2">Type</span></td>
<td width="256"><span class="style2">Image</span></td>
</tr>
<tr>
<?php
while($row =& mysql_fetch_assoc($result)) {
extract($row);

if ($i%2) {
$class = 'row1';
} else {
$class = 'row2';
}

$i += 1;

if ($ImagePath) {
//$Image = WEB_ROOT . 'images/PupilTester/' . $ImagePath;
$Image = 'images/PupilTester/' . $ImagePath;
} else {
$Image ='images/PupilTester/nopicture.bmp';
}

?>
?>

<tr class="<?php echo $class; ?>">
<td>
<div align="center">
<input type="checkbox" name="checkbox" value="checkbox">
</div></td>
<td><?php echo $QuestionNo; ?>&nbsp;</td>
<td><?php echo $Question; ?></td>
<td><?php echo $ImagePath; ?></td>
<td><?php echo $TypeID; ?> <div align="center"></div></td>
<td><img src=<?php echo $Image; ?>></td>
</tr>
<?php
*************************************
Oct 4 '05 #1
6 18649
JDS
On Tue, 04 Oct 2005 16:49:37 +0000, Ian Davies wrote:
<input type="checkbox" name="checkbox" value="checkbox">


Use

name="checkbox[]"

and

value="<? echo $TypeID?>"

Read the following:
http://us2.php.net/manual/en/faq.htm...aq.html.arrays

ask more questions when you get stuck

later...

--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Oct 4 '05 #2
Thanks for your reply

Looking at your code and reading the article it seems that some sort of
array is created. How would I then APPEND this list to a table, Im OK with
the SQL but which part of the php script would be used in the APPEND
statement.
or alternatively how could I use the array as a WHERE clause in a SELECT
statement.

Ian

"JDS" <je*****@example.invalid> wrote in message
news:pa****************************@example.invali d...
On Tue, 04 Oct 2005 16:49:37 +0000, Ian Davies wrote:
<input type="checkbox" name="checkbox" value="checkbox">


Use

name="checkbox[]"

and

value="<? echo $TypeID?>"

Read the following:
http://us2.php.net/manual/en/faq.htm...aq.html.arrays

ask more questions when you get stuck

later...

--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Oct 6 '05 #3
In the example Jeffrey gave, the name ends in [].
This would automatically cause an array to be created. As checkboxes are
only passed back to the server when they are set, you should end up with
an array of checked items on the server. You can use the implode
function to convert it to a comma separated list if you want to.

Best regards

Ian Davies wrote:
Thanks for your reply

Looking at your code and reading the article it seems that some sort of
array is created. How would I then APPEND this list to a table, Im OK with
the SQL but which part of the php script would be used in the APPEND
statement.
or alternatively how could I use the array as a WHERE clause in a SELECT
statement.

Ian

"JDS" <je*****@example.invalid> wrote in message
news:pa****************************@example.invali d...
On Tue, 04 Oct 2005 16:49:37 +0000, Ian Davies wrote:

<input type="checkbox" name="checkbox" value="checkbox">


Use

name="checkbox[]"

and

value="<? echo $TypeID?>"

Read the following:
http://us2.php.net/manual/en/faq.htm...aq.html.arrays

ask more questions when you get stuck

later...

--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/


Oct 7 '05 #4
JDS
On Fri, 07 Oct 2005 08:33:51 +0200, Dikkie Dik wrote:
an array of checked items on the server. You can use the implode
function to convert it to a comma separated list if you want to.


Example[1]:

$sql = "SELECT * FROM boogers WHERE booger_id IN ( "
. join(",", $_REQUEST['booger_ids']) . " )";

(Note that that is all one line of PHP).

You can use implode() instead of join() -- they are functionally identical.
[1] Change "booger" to "bogie" for those from the UK. :)
--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Oct 7 '05 #5
Thanks for all the feedback

However I am still confused. Let me

In QUESTION.PHP I have records displayed from a MySQL database table in an
HTML table and a check box for each record as follows

************************************************** ***********

<input type="checkbox" name="checkbox[]" value="<? echo
$QuestionNo?>"
************************************************** ***************

I also have a form and a button as follows, which is suposed to run
FILTER.PHP

************************************************** ********

<form name="form1" method=post action="Filter.php">

<input type="submit" name="Submit" value="Submit">

************************************************** ***********

I am unsure of the script to use in the SQL of FILTER.PHP to filter records
based on the ticked checkboxs

FILTER.PHP has the following SQL (which is obviously wrong). Basically I am
not sure how to use the array from QUESTION.PHP to filter records in
FILTER.PHP

************************************************** ****

<?php

$filtered = @mysql_query("SELECT * FROM Questions WHERE QuestionNo IN ( " .
join(",", $_REQUEST['$QUESTION_NOS_FROM_THE_ARRAY']) . " )";

if (!$filtered) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
$filteredrow = mysql_fetch_assoc($filtered);
extract($filteredrow);

// Display the text of each Question in a paragraph

//while ($filteredrow = mysql_fetch_array($filtered)) {
// echo '<p>' . $filteredrow['QuestionNo'] . '</p>';
//}
?>

***********************************************

"JDS" <je*****@example.invalid> wrote in message
news:pa****************************@example.invali d...
On Fri, 07 Oct 2005 08:33:51 +0200, Dikkie Dik wrote:
an array of checked items on the server. You can use the implode
function to convert it to a comma separated list if you want to.
Example[1]:

$sql = "SELECT * FROM boogers WHERE booger_id IN ( "
. join(",", $_REQUEST['booger_ids']) . " )";

(Note that that is all one line of PHP).

You can use implode() instead of join() -- they are functionally

identical.

[1] Change "booger" to "bogie" for those from the UK. :)
--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Oct 8 '05 #6
In QUESTION.PHP I have records displayed from a MySQL database table in an
HTML table and a check box for each record as follows <input type="checkbox" name="checkbox[]" value="<? echo
$QuestionNo?>" I also have a form and a button as follows, which is suposed to run
FILTER.PHP <form name="form1" method=post action="Filter.php">

<input type="submit" name="Submit" value="Submit">
First point, the <input /> fields should be declared INSIDE the <form>
so that when the submit button is clicked the current values of the
selected items are sent to your processing script. Declared outside, as
you show above, means that they are purely cosmetic rather than
functional.
FILTER.PHP has the following SQL (which is obviously wrong). Basically I am
not sure how to use the array from QUESTION.PHP to filter records in
FILTER.PHP $filtered = @mysql_query("SELECT * FROM Questions WHERE QuestionNo IN ( " .
join(",", $_REQUEST['$QUESTION_NOS_FROM_THE_ARRAY']) . " )";
Nearly there, but what is '$QUESTION_NOS_FROM_THE_ARRAY'? Instead of
that, modify Jeff's example to match your field name, 'checkbox[]':
$filtered = @mysql_query("SELECT * FROM Questions WHERE QuestionNo IN ( " .
join(",", $_REQUEST['checkbox']) . " )";


---
Steve

Oct 8 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by webhigh | last post: by
2 posts views Thread by B-Dog | last post: by
7 posts views Thread by wk6pack | last post: by
debasisdas
reply views Thread by debasisdas | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.