RE: Could get all data from MYSQL using Mysql_fetch_array!!
| From: | Andrew Chase | Date: | Wed, 29 Aug 2001 18:06:28 +0000 |
| Subject: | RE: Could get all data from MYSQL using Mysql_fetch_array!! | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-11960@lists.php.net to get a copy of this message | ||
You did fetch all the data by using '*' in your query, but you can't use
'*'
as a wildcard when referring to an associative array (which is what $row
is) - you need to step through each key in the array:
while ($row= mysql_fetch_array($result,MYSQL_ASSOC))
{
$fields = array_keys($row);
foreach($fields as $key){
print ("{$".row[$key]."}");
}
}
Or you could do it longhand -
while ($row= mysql_fetch_array($result,MYSQL_ASSOC))
{
print ("{$row["Reason"]}");
print ("{$row["OtherField1]}");
print ("{$row["OtherField2]}");
}
Longhand might even be more useful if you want to format your results
nicely.
HTH,
-Andy
> -----Original Message-----
> From: Jack [mailto:jack@nedcor.com]
> Sent: Wednesday, August 29, 2001 8:13 AM
> To: php-db@lists.php.net
> Subject: Could get all data from MYSQL using Mysql_fetch_array!!
>
>
> Dear all
> I was trying to fetch all the data from one of my table
> "leaverequest", but
> i couldn't fetch all the data if i use the * .
> here is my program, this one is only fetch the Reason field, but
> what i want
> is all the data.
>
> <?
> $dblink=mysql_pconnect("microsoft","console","edshk");
> mysql_select_db("nedcorhk",$dblink);
> $query = "select * from leaverequest";
> $result=mysql_query($query,$dblink);
>
> while ($row= mysql_fetch_array($result,MYSQL_ASSOC))
> {
> print ("{$row["Reason"]}");
> }
> ?>
>
> But can i do it like that way to get all the data? (Showing below) :
>
> <?
> $dblink=mysql_pconnect("microsoft","console","edshk");
> mysql_select_db("nedcorhk",$dblink);
> $query = "select * from leaverequest";
> $result=mysql_query($query,$dblink);
>
> while ($row= mysql_fetch_array($result,MYSQL_ASSOC))
> {
> print ("{$row["*"]}");
> }
> ?>
>
>
> Pls help me!!
>
> Thx
> jack
> jack@nedcor.com
> jackps1@speed-link.com.hk
>
>
>
>