Re: Undefined Index ...confusion
| From: | Peter Ford | Date: | Thu, 23 Jul 2009 14:29:07 +0000 |
| Subject: | Re: Undefined Index ...confusion | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-295753@lists.php.net to get a copy of this message | ||
Miller, Terion wrote:
> I keep getting this error while trying to use the field 'ID' to pass in a url.. And
> it's odd because the query is pulling everything BUT the ID which is the first field...
>
> code:
> <a href="view.php?ID=<?php echo
> $_SESSION['fullRestaurantList']['ID']?>"><?php echo
> htmlspecialchars(stripslashes($_SESSION['fullRestaurantList'][$i]['name']));
> ?>
What's the query?
I find (I use PostgreSQL rather than the mySQL that many on this list use) that
unless you explicitly ask for a field called ID (using SELECT "ID" ... ) you
get a returned field in lower case
So
$resource = pg_query("SELECT ID, Foo FROM MyTable WHERE Foo='Bar'");
$data = pg_fetch_all($resource)
gives me an array $data of rows like
$data[0]['id'] = '1'
$data[0]['foo'] = 'Bar'
To make sure $data[] has fields named ID and Foo I would have to do
$resource = pg_query("SELECT ID AS \"ID\", Foo AS \"Foo\" FROM MyTable
WHERE
Foo='Bar'");
--
Peter Ford phone: 01580 893333
Developer fax: 01580 893399
Justcroft International Ltd., Staplehurst, Kent