telophase: (Princess Tutu - OMG TEH DRAMA!)
telophase ([personal profile] telophase) wrote2010-06-11 04:51 pm

Drviging me NUUUUTS

edit: FIXED!

Also: For some reason, print_f(array) left the underscores between the two words in the two-word keys out, while print_r(array) showed them, so they're actually post_author, post_date, etc. GAH TWO HOURS OF MY LIFE WASTED
=====================================================
SO. I'm using PHP.

I have a multi-dimensional associative array named $most_recent_posts that looks much like this:
Array (
     [0] => stdClass Object (
          [ID] => 4
          [post author] => 3
          [post date] => 2010-06-11 19:37:46
     )
     [1] => stdClass Object (
          [ID] => 5
          [post author] => 12
          [post date] => 2010-06-08 12:34:56
     )
)


SO

echo $most_recent_posts[0]["ID"]; SHOULD print out "4", should it not? Because right now all it's doing is halting the entire damn script.

[identity profile] tprjones.livejournal.com 2010-06-11 10:15 pm (UTC)(link)
I've not done much work with that specific type of data structuring there, so this may be totally wrong. But try this:

echo $most_recent_posts[0]->ID;

[identity profile] telophase.livejournal.com 2010-06-11 10:20 pm (UTC)(link)
Yay, that works unlike EVERY SINGLE EXAMPLE I COULD FIND ONLINE.

ALthough I'm now trying to figure out what to do with the two-word keys, because post author, "post author," 'post author,' [post author], and (post author) don't seem to work.

edit: FIXED. For some reason, print_f(array) left the underscores between the two words in the two-word keys out, while print_r(array) showed them, so they're actually post_author, post_date, etc. GAH TWO HOURS OF MY LIFE WASTED
Edited 2010-06-11 22:52 (UTC)

[identity profile] tprjones.livejournal.com 2010-06-12 01:11 am (UTC)(link)
If it helps, here's the page I ended up at that showed the way to make it work right (first section, and the page before this one talks about the structure itself):

http://www.databasejournal.com/features/php/article.php/10898_1485971_3/PHP-and-Working-with-Databases-for-the-Lazy-Sod.htm

Maybe there's other goodies at that site that can help you with your particular chosen data structures.