You are here: Re: An extra last empty field in an 'mysql_fetch_array' result array? « PHP Programming Language « IT news, forums, messages
Re: An extra last empty field in an 'mysql_fetch_array' result array?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация