Re: array question
| From: | Philip Olson | Date: | Thu, 19 Jul 2001 18:50:29 +0000 |
| Subject: | Re: array question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-58767@lists.php.net to get a copy of this message | ||
Simple change :
mysql_fetch_object
to :
mysql_fetch_array or
mysql_fetch_row
By default, mysql_fetch_array will allow for :
$row[2] and $row['fieldname']
And mysql_fetch_row will allow for :
$row[2]
And as you know, mysql_fetch_object allows for :
$row->fieldname
See the manual for examples and explanation :
http://php.net/manual/en/function.mysql-fetch-array.php
Also, consider using print or echo as opposed to printf. And lastly, you
really don't need to use mysql_free_result, PHP does this automagically
after the script dies. Sorry for picking on you, you may have your
reasons. ;-)
regards,
Philip
James W Greene wrote:
> Hi All,
> I am trying to pull info out of a table and assign a var name to each
> field... I seem to be having trouble. I have tried to do $var = $row[0]
> but that does not seem to do it. I have included what is working below.
> I would like to have each element of the array stored in a seperate
> variable
> for use on a web page. Thanks
> JG
>
> <?php
> $stmt = 'SELECT * FROM custdata WHERE UserName like "fred"';
> mysql_connect($localhost,test,testme);
> $result = mysql_db_query("test",$stmt) ;
> while($row = mysql_fetch_object($result)) {
> //** doing this now**//
> printf("%s",
> $row->UserName) ;
> // **Would like to do something like**//
> // $user = $row[0]; //
>
> }
> mysql_free_result($result);
> ?>
>