Jump to content


Photo

Retrieving array value


  • Please log in to reply
3 replies to this topic

#1 sdaspen

sdaspen
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 06 June 2006 - 04:13 PM

I have an array that I can view if i print_r($uroutput) (see results below).
How do I grab the [rating] value of 2 to be displayed elsewhere on the page.

Thanks,



stdClass Object
(
[result] => Resource id #20
[numrows] => 1
[rows] => Array
(
[0] => Array
(
[id] => 32
[userid] => sdaspen32@aol.com
[portal_id] => 286
[channel_id] => 761
[package_id] => 2252
[rating] => 2
)

)

[statuscode] => 1
)

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 06 June 2006 - 04:32 PM

I am not sure, but I believe "echo($urooutput[0][rating]);" Will do the job :) (It's a nested Array, right?)


But if it's a mysql result, use:

$output=mysql_result($uroutput,"0","rating");
echo($output);

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 06 June 2006 - 11:39 PM

According to the output, it's an object

stdClass Object
(
    [result] => Resource id #20
    [numrows] => 1
    [rows] => Array
    (
        [0] => Array
        (
            [id] => 32
            [userid] => sdaspen32@aol.com
            [portal_id] => 286
            [channel_id] => 761
            [package_id] => 2252
            [rating] => 2
        )

    )

    [statuscode] => 1
)

so probably

$rating = $uroutput->rows[0]['rating'];

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 sdaspen

sdaspen
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 June 2006 - 06:32 AM

Thanks Orio and Barand for your quick responses. I greatly appreciate it. Barand your solution was the one that solved it for me. Thanks again.



so probably

$rating = $uroutput->rows[0]['rating'];
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users