Re: counting check boxes
| From: | Paul Chvostek | Date: | Sat, 10 May 2003 18:55:14 +0000 |
| Subject: | Re: counting check boxes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147139@lists.php.net to get a copy of this message | ||
On Sat, May 10, 2003 at 08:35:25PM +0200, Ryan A wrote:
>
> I have run into a little problem, its hard to explain so am giving you the
> whole code below:
> I am getting a string to countchecks.php which is like:
> countchecks.php?id=154&id=198&id=505&id=809&id=1100
Ugh.
If you're stuck with this format, then you're going to have to parse
$_SERVER['QUERY_STRING'] manually, because repetitions of the same
variable will overwrite each other. So $_GET['id'] will be 1100, and
the other values will be lost.
> taking that I have to format it into
>
> select * from asdf where id=154 and id=198 and id=505 and id=809 and
> id=1100;
>
> How can i do that?
Why would you want to? How can 'id' have multiple values?
Anyway, it would be something like:
foreach (explode('&',$_SERVER['QUERY_STRING']) as $this) {
list($junk,$value)=explode('=',$this);
if ($junk=="id") $q.=" AND id=$value";
}
$q="SELECT * FROM asdf WHERE" . substr($q,5) . ";";
> Below is the form that i am using...
...
It's an ugly form. You'd have an easier time if you put the checkbox
entities into an array, with:
<form method="get">
...
<input type="checkbox" name="id[]" value="154">154
<input type="checkbox" name="id[]" value="198">198
<input type="checkbox" name="id[]" value="202">202
<input type="checkbox" name="id[]" value="505">505
<input type="checkbox" name="id[]" value="809">809
<input type="checkbox" name="id[]" value="1100">1100
<input type="submit" name="Submit" value="Submit form">
</form>
and processed it with:
foreach ($id as $value) {
$q.=" AND id=" . $value;
}
$q="SELECT * FROM asdf WHERE" . substr($q,5) . ";";
--
Paul Chvostek <paul@it.ca>
Operations / Abuse / Whatever
it.canada, hosting and development http://www.it.ca/