RE: [PHP] MySQL - field names
| From: | o dot cook at etoncollege dot org dot uk | Date: | Tue, 15 Aug 2000 11:48:26 +0000 |
| Subject: | RE: [PHP] MySQL - field names | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-11783@lists.php.net to get a copy of this message | ||
D'oh! :)
So close! Thank you!
Ollie
-----Original Message-----
From: Robin Vickery [mailto:robin@planet-three.co.uk]
Sent: 15 August 2000 12:44
To: php-general@lists.php.net
Subject: Re: [PHP] MySQL - field names
o.cook@etoncollege.org.uk writes:
> Typically when making a MySQL query I will do something similar to:
>
> $sql = "SELECT DISTINCT type FROM accttypes WHERE id=$requested_id";
> $result = mysql_query($sql,$conn);
> while ( ($rs = mysql_fetch_array($result)) ) {
> $accttype = $rs[0];
> }
>
> This strikes me as a bit clumsy, especially when lots of fields are
returned
> (I forever find myself counting forward from 0 to get the correct number
for
> a specific field!). I would much rather be able to access the record set
> pieces by their field name? Something like $accttype = $rs.type as per the
> above example?
You're already using the right function - mysql_fetch_array, just
use the fieldname instead of the number in your array like so:
$sql = "SELECT DISTINCT type FROM accttypes WHERE id=$requested_id";
$result = mysql_query($sql,$conn);
while ( ($rs = mysql_fetch_array($result)) ) {
$accttype = $rs['type'];
}
--
Robin Vickery...............................................
Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK
Email: robin@planet-three.net Phone: +44 (0)794 670 6395
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net