469,268 Members | 1,019 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

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 3540
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by webhigh | last post: by
5 posts views Thread by Axial | last post: by
1 post views Thread by hristov.milen | last post: by
6 posts views Thread by aaj | last post: by
2 posts views Thread by Will Newton | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.