Forum Moderators: coopster
I can run a query and use print_r to get a very ugly output. I'm wanting to do a bit more but am having problems. Here is the situation.
I assign the returned array result to $result. Now, I can do vardump and get everything out of there, but I can't seem to access anything else.
For example, using vardump, it shows one of the keys as "endIndex".
So I try and access $result["endIndex"] but get nothing even though I know it is set.
Even...
If(IsSet($result["endIndex"]))
brings back a false.
All of the search results are in the [resultElements] array inside of $results in the form
$result["resultElements"][0]["URL"]
but I can't access those either.
I've worked with multi-dimensional arrays with no problems so I know I must be doing something stupid that I'm not seeing.
Any thoughts?
It's primarily the info in the ["resultElements"] key I am after, but I just cant seem to figure out where I'm screwin up.
object(stdClass)(11) {
["directoryCategories"]=>
string(1) "
"
["documentFiltering"]=>
bool(false)
["endIndex"]=>
int(10)
["estimateIsExact"]=>
bool(false)
["estimatedTotalResultsCount"]=>
int(43100)
["resultElements"]=>
array(10) {
[0]=>
&object(stdClass)(9) {
["URL"]=>
string(38) "http://www.example.de/blog/"
["cachedSize"]=>
string(3) "90k"
["directoryCategory"]=>
&object(stdClass)(2) {
["fullViewableName"]=>
string(0) ""
["specialEncoding"]=>
string(0) ""
}
["directoryTitle"]=>
string(0) ""
["hostName"]=>
string(0) ""
["relatedInformationPresent"]=>
bool(true)
["snippet"]=>
string(159) "Friday, April 23. 2004. Babylon 5 - Season 4 DVD Box Set. My "Babylon 5 - Season 4 DVD Box Set" just arrived. Posted by sb in movies ... "
["summary"]=>
string(0) ""
["title"]=>
string(29) "my weblog"
}
[edited by: jatar_k at 2:50 am (utc) on April 27, 2004]
[edit reason] generalized urls [/edit]
You should have said oops, instead of uh oh. ;)
OOP - Object Oriented Programming
If you look at the var dump a little closer, you see that the type of variable is an object, not an array.(object(stdClass)(11) {)
Now I'm no OOP guy, but I'm figuring that access to the data can be acheived like this:
print $result->endIndex;
Here's a read on PHP OOP [liquidpulse.net]. Hope it helps out some.
Added: Just reread you first post and see that you want resultElements, which is an array. Those values would be accessed a little differently, I think.
$result_array = $result->resultElements;
$count = count($result_array);
for ($i=0; $i<$count; $i++) print "<p>".$result_array[$i]."</p>";
Or maybe just:
$count = count($result->resultElements);
for ($i=0; $i<$count; $i++) print "<p>".$result->resultElements[$i]."</p>";
[edited by: Birdman at 4:30 pm (utc) on April 27, 2004]