.oO(RGNelson)
>Thanks for working with me on this!
> Where do I put the brackets?
> I'm not using a form.
Ah, OK. But doing that by hand can be a bit ... fiddly ...
> I'm using a link;
> mypage.php?id=1&id=3&id-4
>
> These don't work for me:
> mypage.php?id[]=1&id[]=3&id[]=4
> mypage.php?id=1[]&id=3[]&id=4[]
The brackets have to be witten after the variable name and be
URL-
encoded, %5B%5D should do it (a simple hex-encoding of
ASCII-codes).
You also have to encode the ampersands in your HTML. So a
link to the
target page should look something like
<a
href="mypage.php?id%5B%5D=1&id%5B%5D=3&id%5B%5D=4">link</a>
Now the PHP script should be able to receive the data and
correctly
store it as an array in $_GET['id'].
> Do I need to put the brackets in my recordset?
If you have to rely on DW's behaviours, then someone else has
to jump
in - I always write my own code.
Here's a little code snippet for doing the dirty work, maybe
you can
make some use of it:
// check if there are any IDs at all in the URL
if (!empty($_GET['id'])) {
// fetch all submitted IDs as numeric values, which is an
// easy way to prevent SQL-injection in this specific case;
// the array_diff() call filters out 0-IDs
$ids = array_diff(array_map('intval', $_GET['id']),
array(0));
// if there's something left, saddle up for the DB query
if (!empty($ids)) {
// turn the ID-array into a comma-separated string
$ids = implode(', ', $ids);
// build the query, use the IN operator to match the
selected IDs
$query = "
SELECT someField, anotherField
FROM yourTable
WHERE recordId IN ($ids)";
// execute query, fetch result, print it out, have a break
// ...
}
}
Micha