Bing Du wrote:
apparently $rec[0] is a php object - try the following lines to
find out what's inside:

echo '<pre>';
print_r($rec[0]);
echo '<pre>';

that will probably give you a clue as to how to extract some
useful info from the object.


Excellent!  Yes, it now does give me a clue to see what's actually in the
object.  print_r($rec[0]) shows:

stdClass Object ( [year] => 2005 [month] => 8 [day] => 31 [hour] => 0
[minute] => 0 [second] => 0 [fraction] => 0 )

I've never dealt with object in PHP.  Something new learnt today.  I'm now
able to use get_object_vars($rec[0]) to extract the info from the object. There is one thing I don't understand though.

Is there anything wrong with the follow code snippet?  The result of echo
is 'using list, year is" rather than 'using list, year is 2005'.

==
list($year,$month,$day,$hour,$minute,$second,$fraction) =
get_object_vars($rec[0]);
echo "using list, year is $year<br>";
==

This one works.  But I prefer using list.

I hate list. each to his own :-)

try this (untested):

list($year,$month,$day,$hour,$minute,$second,$fraction) = 
array_values(get_object_vars($rec[0]));

no go and read the manual about what list does exactly and do some digging
as to the wonders of php arrays (there are numeric indexes and there are 
associative indexes,
and they can be mixed) as penance.

then learn to love associative arrays (e.g. what get_object_vars() returns)
because:

a. they are everywhere in php.
b. they are lovely (thats a fact - as stalin would say)

;-)


==
$arr = get_object_vars($rec[0]);
echo "year is $arr[year]<br>";

oh and quote your keys when using associative arrays:

echo "year is {$arr['year']}<br>";

or

echo "year is $arr['year']<br>";

or

echo "year is ",$arr['year'],"<br>";

why you ask? turn on error reporting to full and or read the manual to
find out.


==

Thanks,

Bing


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to