|
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]
|