Date: 04/16/01
- Next message: b21xr_1idy <email protected>: "[PHP-DEV] 純商業辦公室出租"
- Previous message: dieter <email protected>: "[PHP-DEV] PHP 4.0 Bug #8828 Updated: mktime using mday<=0"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
ID: 10341
Updated by: mathieu
Reported By: francis <email protected>
Old-Status: Open
Status: Closed
Bug Type: MySQL related
PHP Version: 4.0.4pl1
Assigned To:
Comments:
You're using mysql_fetch_object(). This function
returns an object where its members are named after its corresponding column names.
CREATE TABLE test (
id int4,
name varchar(20) );
Using this table, you would use the following code to
retrieve its data:
$row_obj = mysql_fetch_object($qry_result);
echo $row_obj->name . ' (' . $row_obj->id . ')';
If you want to use numbers to access the columns please use
mysql_fetch_row().
And please, do take a closer look at that manual.
-- Mathieu
Previous Comments:
---------------------------------------------------------------------------
[2001-04-15 20:26:28] francis <email protected>
The script:
mysql_pconnect ($dbhost, $dbuser, $dbpass);
$result = mysql_db_query ("database", "select * from tablename");
while ($row = mysql_fetch_object ($result, MYSQL_NUM)) {
echo $row->0;
echo $row->1;
}
mysql_free_result ($result);
Generates the error:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'{'' or `'$'' in d:/htdocs/assets/includes/hs~form_functions.php on line 31
The script below works but not for the general case (different column names):
mysql_pconnect ($dbhost, $dbuser, $dbpass);
$result = mysql_db_query ("database", "select * from tablename");
while ($row = mysql_fetch_object ($result, MYSQL_ASSOC)) {
echo $row->columnone;
echo $row->columntwo;
}
mysql_free_result ($result);
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=10341&edit=2
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: b21xr_1idy <email protected>: "[PHP-DEV] 純商業辦公室出租"
- Previous message: dieter <email protected>: "[PHP-DEV] PHP 4.0 Bug #8828 Updated: mktime using mday<=0"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

