473,732 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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"><s pan
class="style2"> Select</span></div></td>
<td width="91"><spa n class="style2"> Question No </span></td>
<td width="527"><sp an class="style2"> Question</span></td>
<td width="42">path </td>
<td width="42"><spa n class="style2"> Type</span></td>
<td width="256"><sp an class="style2"> Image</span></td>
</tr>
<tr>
<?php
while($row =& mysql_fetch_ass oc($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 18763
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*****@exampl e.invalid> wrote in message
news:pa******** *************** *****@example.i nvalid...
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*****@exampl e.invalid> wrote in message
news:pa******** *************** *****@example.i nvalid...
On Tue, 04 Oct 2005 16:49:37 +0000, Ian Davies wrote:

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


Use

name="checkbo x[]"

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("S ELECT * 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_ass oc($filtered);
extract($filter edrow);

// Display the text of each Question in a paragraph

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

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

"JDS" <je*****@exampl e.invalid> wrote in message
news:pa******** *************** *****@example.i nvalid...
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("S ELECT * 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("S ELECT * FROM Questions WHERE QuestionNo IN ( " .
join(",", $_REQUEST['checkbox']) . " )";


---
Steve

Oct 8 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3665
by: webhigh | last post by:
Iım not sure if this a PHP question or an MySQL question but here it goes. I have a repeat region of a table called userid What Iım trying to accomplish is being able to edit the record and then update it by clicking a submit button on the same line. Iım doing it this way so the user can quickly update a number of records one at a time. I know I could do this by passing the userid info to a detail page but really want to do it the way...
3
5192
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers using check boxes. For example, a question such as
2
16070
by: ImraneA | last post by:
Hi there Application : Access v2K/SQL 2K Jest : Using sproc to append records into SQL table Jest sproc : 1.Can have more than 1 record - so using ';' to separate each line from each other.
3
1841
by: William Gill | last post by:
I can't help but think I'm re-inventing the wheel if I have to code my own interface! Isn't there some script, php code, or something (modifiable / customizable) available that lets me select records from two or more related tables and edit them. As mentioned in a previous post, I'm currently selecting a record from table 1; editing it, selecting the related record(s) from table 2; editing them, and so on. This is nuts, not to mention...
2
453
by: Danny | last post by:
How to allow users to select a set of records and then let them change a field for all these records at once? I would like to do this in code on a form. I will have a form with tabular view of records, and I guess they will select more than one record with the SHIFT key, then they can modify a whole bunch of records at once. Thanks
2
1021
by: B-Dog | last post by:
What is the best way to check for new records in the database. I have a form in a multi-user environment connected to an access database but I need to update the information onscreen as it is inserted or at a regular interval. Should I just put a timer and check every so often or is there a way to detect new records and then reload the dataset? Thanks
7
14995
by: wk6pack | last post by:
Hi, How do I check datatable.select(filter) in the following: for each dtrow in datatable.select(filter) .... next I've also tried:
0
8855
debasisdas
by: debasisdas | last post by:
This thread contains some useful tips for using External tables. USING EXTERNAL TABLE ======================= 1.THE TABLE POINTS TO EXTERNAL FILE. IF DATA IS ALTERED IN THE EXTERNAL FILE,DATA IN THE TABLE WILL ALSO CHANGE. 2.EXTERNAL TABLES CAN BE QUERIED IN THE SAME WAY AS STANDARD TABLES IN JOINS,VIEWS.....AND CAN USE ALL TYPES OF FUNCTION ON THE EXTERNAL TABLE. 3.TO GET INFO REGARDING EXTERNAL TABLES QUERY THE "USER_EXTERNAL_TABLES"...
2
1914
by: Hamayun Khan | last post by:
Hi all I am using the following query to select records for table Select JobTitle,JobDesc,Scraped,logoimage,JobPostID,SchoolID,web,MemType,InstitutionName,PayScale,LEA,Contract as ContractType,HoursAbl,StartDate,ClosingDate,asap from tblJobScrap Where ((JobTitle like '% Art %' OR JobTitle like '% Art and Design %' OR JobTitle like '% Art & Design %')) This query return the records having no keywords like Art ,Art and Design or Art &...
2
3613
by: rkferguson | last post by:
Hi Folks, I have a table that captures information about documents that leave the office. Some of those documents may get a signature and then return to the office. Need away to query the table and select records that have a field called "expected return" = "Yes", then to compare the date the document left the office to the current date and then, if the Date Returned is blank/empty/null, select that record as a part of a report or...
0
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9445
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.