Reply to Re: An extra last empty field in an 'mysql_fetch_array' result array?

Your name:

Reply:


Posted by windandwaves on 10/14/05 00:23

"Marcel Brekelmans" <marcel@marcel-art.com> wrote in message
news:29udnWsDMpJDW9PenZ2dnUVZ8qKdnZ2d@giganews.com...
.....
>$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?

Hoi Marcel

This is the function I use:

function getdata($sql) {
$result = @mysql_query($sql) or die("Error: " . mysql_error()." sql was
".$sql);
$ret = array();
while($row = mysql_fetch_assoc($result)) {
$ret[] = $row;
}
mysql_free_result($result);
return $ret;
}

then, in my code, I used:

$sql = "SELECT ID from tblName WHERE Name='Jane'";
$data = getdata($sql)
foreach ($data as $ds) {
echo $ds["Name"];
}

Once you use it a few times, it just makes life really easy, especially
because you refer to fields by name rather than position (e.g.$ds[0]).

Having said that, I am not sure what you are doing wrong ;-) I think that
you only fetch one row. A better way to do this is

while($row = mysql_fetch_row($query)) {

}

Note the single "is teken".

- Nicolaas

[Back to original 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

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