|
Posted by Justin Koivisto on 10/14/05 17:25
Please... post in plain text & do it only once (there are 6 identical
messages)
Marcel Brekelmans wrote:
> I seem to get an extra empty field in every 'mysql_fetch_array' command
> I issue. For example:
>
> I have a simple table 'tblName':
>
> ID Name
> 1 Jane
> 2 Joe
> 2 Doe
>
> The following code:
>
> $oCursor = mysql_query("SELECT ID from tblName WHERE Name='Jane'");
> if (!$oCursor)
> {
> $bGo = false;
> }
> else
> {
> $aRow = mysql_fetch_array($oCursor);
> }
>
> results in:
>
> count($aRow) = 2;
>
> $aRow[0] = 1;
> $aRow[1] = '';
>
> Am I missing something, doing something wrong, a wrong PHP setting?
What is actually set is the following:
Array
(
[0] => 1
[ID] => 1
)
That is because mysql_fetch_array by default returns by column name and
by number...
Use mysql_fetch_array($oCursor,MYSQL_NUM) or
mysql_fetch_array($oCursor,MYSQL_ASSOC) instead.
http://us2.php.net/manual/en/function.mysql-fetch-array.php
(see "Return Values" section)
--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
Navigation:
[Reply to this message]
|