473,378 Members | 1,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

selecting som table row

Hi everybody.

Suppose to have a table dinamically created in a form where I show
some
information of a set of row selected in a db-table:

.......
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td> <inputtype=\"checkbox\"name=\"checkbox$cnt\"value= \"checkbox\"
</td>";

echo "<td>".$row["ID"]."</td>";
echo "<td>".$row["field1"]."</td>";
echo "<td>".$row["email"]."</td>";
echo "</tr>";
}

after the table is showed, the user must select some rows checking the
related checkbox and then push a button to submit the form; at this
point I must start another page where I must do some work only on the
rows of the db-table referred by the ID where the checkbox is checked.

Can someone help me in solving this problem?

Thank you from Franco in Italy
Jul 17 '05 #1
4 3698
Franco Fellico' wrote:

Hi Franco
Hi everybody.

Suppose to have a table dinamically created in a form where I show
some
information of a set of row selected in a db-table:

......
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td> <inputtype=\"checkbox\"name=\"checkbox$cnt\"value= \"checkbox\"
what is $cnt here? Is it increased somewhere?
And the value you attach to your checkbox is checkbox. ????

I think you should put some number (ID or Primary key or something unique)
in there.

Also use spaces between the different attributes!

SO this would be better:
echo "<td> <inputtype='checkbox' name='ID[]' value='<?= $row["ID"] ?>'>";

Now the script that receives the posting can retrieve the checked ID's like
this:

$id = $_POST["id"];

Now $id is an array containing all the id's that were checked.
Just loop through it and do your stuff with the database.
regards,
Erwin Moller

</td>";

echo "<td>".$row["ID"]."</td>";
echo "<td>".$row["field1"]."</td>";
echo "<td>".$row["email"]."</td>";
echo "</tr>";
}

after the table is showed, the user must select some rows checking the
related checkbox and then push a button to submit the form; at this
point I must start another page where I must do some work only on the
rows of the db-table referred by the ID where the checkbox is checked.

Can someone help me in solving this problem?


which problem? ;-)

Thank you from Franco in Italy


Jul 17 '05 #2
Hi Erwin.

I learn a lot of things from your suggestions. I am programnming with
PHP from short time so I am not expert as you are (you said: where is
the problem? Yes for me that was a problem); but I am sure that son I
will improve my skill with the help of people as you. So many thanks.

I solved my "problem". Instead of a numeric ID I have used a string
and I was able to pass an array of strings where the checkbox was
checked! The PHP is very powerful! Also I appreciated your suggestion
about the use of ' instead of \" but in that I have had the following
problem:

echo "<td> <inputtype='checkbox' name='ID[]'
value='".$row["email"]."'> </td>";

echo "<td> <input type=\"checkbox\" name=\"ID[]\"
value=\"".$row["email"]."\"> </td>";

The first statement don't work (I don't have parse error but the
checkbox don't appears); the second one work ok, so for now I am still
using the second form of statement.

If you can understand why this happens, it will be interesting for me
to know the reason.

Again many thanks and a Happy New Year to you and all your family.
Franco from Gaeta in Italy.
Erwin Moller <si******************************************@spam yourself.com> wrote in message news:<3f*********************@news.xs4all.nl>...
Franco Fellico' wrote:

Hi Franco
Hi everybody.

Suppose to have a table dinamically created in a form where I show
some
information of a set of row selected in a db-table:

......
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td> <inputtype=\"checkbox\"name=\"checkbox$cnt\"value= \"checkbox\"


what is $cnt here? Is it increased somewhere?
And the value you attach to your checkbox is checkbox. ????

I think you should put some number (ID or Primary key or something unique)
in there.

Also use spaces between the different attributes!

SO this would be better:
echo "<td> <inputtype='checkbox' name='ID[]' value='<?= $row["ID"] ?>'>";

Now the script that receives the posting can retrieve the checked ID's like
this:

$id = $_POST["id"];

Now $id is an array containing all the id's that were checked.
Just loop through it and do your stuff with the database.
regards,
Erwin Moller

</td>";

echo "<td>".$row["ID"]."</td>";
echo "<td>".$row["field1"]."</td>";
echo "<td>".$row["email"]."</td>";
echo "</tr>";
}

after the table is showed, the user must select some rows checking the
related checkbox and then push a button to submit the form; at this
point I must start another page where I must do some work only on the
rows of the db-table referred by the ID where the checkbox is checked.

Can someone help me in solving this problem?


which problem? ;-)

Thank you from Franco in Italy

Jul 17 '05 #3
correction:
echo "<td> <inputtype='checkbox' name='ID[]' value='<?= $row["ID"] ?>'>";

Now the script that receives the posting can retrieve the checked ID's
like this:

$id = $_POST["id"];

Is wrong.
In the name='ID[]' i used capitals, and when I read them out I use id.

Just sloppy.
They should be the same. :-)

But you probably figured that out.
Jul 17 '05 #4
Franco Fellico' wrote:
Hi Erwin.

Hi Franco,
I learn a lot of things from your suggestions. I am programnming with
PHP from short time so I am not expert as you are (you said: where is
the problem? Yes for me that was a problem); but I am sure that son I
will improve my skill with the help of people as you. So many thanks.
Thanks!
It is nice to hear you appreciate the help. That is why most of us help in
the first place. :-)

I solved my "problem". Instead of a numeric ID I have used a string
and I was able to pass an array of strings where the checkbox was
checked! The PHP is very powerful! Also I appreciated your suggestion
about the use of ' instead of \" but in that I have had the following
problem:

echo "<td> <inputtype='checkbox' name='ID[]'
value='".$row["email"]."'> </td>";

echo "<td> <input type=\"checkbox\" name=\"ID[]\"
value=\"".$row["email"]."\"> </td>";

The first statement don't work (I don't have parse error but the
checkbox don't appears); the second one work ok, so for now I am still
using the second form of statement.
The first one doesn't work?
Strange.
2 'solutions':
1) I use the name ID[] , maybe that name is not well choosen because it is
used in other contexts in HTML.
You could try to replace it by another name, eg myid

2) In general: Check the HTML produced by PHP.
It is very easy to 'loose' yourself in the PHP.
It is often wise just to check the HTML produced by PHP and check it for
errors. If you find an error in your HTML, it is often easy to correct it.
A common mistake is this one (I fell for it many times myself):
If you use dynamic content, like you do, it is possible that dynamic content
contains itself characters that end a HTML-string. EG: If your
$row["email"] contains a " or a ' it could confuse the webbrowser because
the result would be this:

this statement:
echo "<td> <inputtype='checkbox' name='ID[]' value='".$row["email"]."'>
</td>";

produces:
<td> <inputtype='checkbox' name='ID[]' value='someemail'bad'></td>

when $row["email"] contains: someemail'bad

Please notice that the extra ' makes the HTML bad.

I don't expect that to happen to all your emailfields by the way. Just a
warning.

So please check your HTML that PHP produced and find the mistake in there
first.

If you can understand why this happens, it will be interesting for me
to know the reason.

Again many thanks and a Happy New Year to you and all your family.
Franco from Gaeta in Italy.
Thanks!
Same to you! Let me know how you proceed.

Regards,
Erwin Moller


Jul 17 '05 #5

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

Similar topics

4
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...
2
by: John | last post by:
Hello, I have a table called BUILDREQUESTS which I want to select from, depending on the project ID of each record. The Project ID field is indexed. (A) This query runs almost instantly: ...
5
by: Axial | last post by:
Question: How to select columns from Excel-generated XML when some cells are empty. I've found examples where rows are to be selected, but I can't seem to extrapolate from that to selecting...
2
by: Robert | last post by:
Hi All, I'm trying to solve this for a few days now and I just can't figure it out... I have three tables set up, I'll simplify them for this question: Table 1: HOTELS Columns: HOTEL_ID,...
1
by: hristov.milen | last post by:
Hi, Is there a way to restrict selecting from a table.. I have problem with one check, I have select and after this insert based on the select. If it happen in one time .. I can insert...
4
by: Doslil | last post by:
I have a form which has a subform.In the main form I have only one field (this is a drop down list and has a query attached to it) which selects empno,Name from the EmployeeInformation table. ...
1
by: Ramesh | last post by:
hi, I am selecting fields from three table for manupulating data and i want to display total number of records selected. But i am always getting -1 value, eventhough 1000 of records are selected....
6
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I...
2
by: Will Newton | last post by:
I have attached some SQL which produces what to me, at least, is rather unexpected results. Selecting real columns into double precision columns loses some precision. Is this expected or documented...
3
by: saddist | last post by:
Hello, I have an access table with fields: ID, Name, Surname, Training. I would like to select every single row in this table to operate on it. Alghoritm would look something like that: i = 1 to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.