473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

stdClass Object output to a list

Hello,
i would like to know how i can get better output from a foreach.

this code:
Expand|Select|Wrap|Line Numbers
  1.     $x = $wpdb->get_results("SELECT * FROM " . WP_PLAATJES);
  2.     foreach ($x as $y) {
  3.     print_r($y);
  4.     var_dump( $y ); 
outputs:

stdClass Object ( [plaatjes_ID] => 1 [plaatjes_name] => Screenie [plaatjes_images] => \screenshot.png [plaatjes_status] => 1 )
object(stdClass)[3]
public 'plaatjes_ID' => string '1' (length=1)
public 'plaatjes_name' => string 'Screenie' (length=8)
public 'plaatjes_images' => string '\screenshot.png' (length=15)
public 'plaatjes_status' => string '1' (length=1)


what i would like to see is a normal list of 'plaatjes_name' and it's image, like:
name: screenie
image: \screenshot.png

Thanks in advance.
~muckymuck
Dec 22 '09 #1

✓ answered by muckymuck

nevermind, found it.

echo $y->{'plaatjes_name'};

6 4481
nevermind, found it.

echo $y->{'plaatjes_name'};
Dec 22 '09 #2
kovik
1,044 Expert 1GB
echo $y->plaatjes_name works just as well, and likely faster.
Dec 22 '09 #3
Dormilich
8,658 Expert Mod 8TB
curly braces are useful, if you don’t know the name before runtime.
Expand|Select|Wrap|Line Numbers
  1. public function func($name)
  2. {
  3.     // some code
  4.     return $this->{'do' . $name}();
  5. }
Dec 22 '09 #4
kovik
1,044 Expert 1GB
But if you don't know that name before run time, how will you know it's validity?

Expand|Select|Wrap|Line Numbers
  1. public function func($name) {
  2.     // some code
  3.     if (method_exists($this, "do{$name}")) {
  4.         return $this->{"do{$name}"}();
  5.     }
  6.     return "FAIL!";
  7. }
I see your code and raise you one control statement. :3
Dec 22 '09 #5
Dormilich
8,658 Expert Mod 8TB
I see your code and raise you one control statement. :3
that’s what the
Expand|Select|Wrap|Line Numbers
  1. // some code
was for
Dec 22 '09 #6
kovik
1,044 Expert 1GB
Got me there.
Dec 22 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: red | last post by:
If I use PEAR to produce an accociative array from a mysql table, and display the array with print_r, it says it is an array and it displays values like a regular array: Array ( => 1 =>...
11
by: C++fan | last post by:
Suppose that I define the following class: class example_class{ public: example_class(); void funtion_1(); void function_2(); protected:
2
by: juglesh | last post by:
hello, i have a d/l'd class that gives an array which prints like this: stdClass Object ( ] => stdClass Object ( => text => => fisrt name => yes
4
by: Skrol29 | last post by:
Hello, It can be very usefull to code: $obj = new stdClass; Unfortunately the few that the documentation officially tells about this class is: ****************************** The name stdClass...
6
by: learning | last post by:
I am trying to learn STL but got stuck in for_each(). What I intend to do in the following is to make a list with each element as a string. add the string elements to the list until it has 10...
5
by: JamesG | last post by:
Hi, I have the following object, I need to extract the SysMessage property. stdClass Object ( =stdClass Object ( =Your consignment could not be found on our system ) ) I could do this:
2
by: Jean Marie | last post by:
Hi, i have a problem with the usage of stdClass. From a SOAP based web service i get a code list as an array of stdClass instances: array ( 0 => stdClass::__set_state(array(
9
ebcovert3
by: ebcovert3 | last post by:
Ok, I really need help. I am running EE (an older version admittedly) but this just started happening. I noticed a lot of spam accounts being requesting authorization to my website. I went in to the...
1
by: electronik | last post by:
Hello! My var_export() from $object says: stdClass::__set_state(array( 'event_id' => '21', 'test' => 5, 'anode' => NULL, )) I want to access 'anode'.
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.