MySQL Forums
Forum List  »  PHP

Output showing as Array rather than Objects in row
Posted by: Brenna Hansen
Date: October 13, 2020 09:10AM

I've created this code and the output isn't what I'm wanting. Rather than a long string of messy data like I currently get, I'd like to see it displayed in rows, or even better like a table. In this example I do know the column names but I may not always know them as the query is based on a view.

Here is my code:


// Create a new query object.
$query = $db->getQuery(true);


// Create the base select statement.

// Select all records from the view.
$query->select('*')
->from($db->quoteName('corp_view6'));

// Set the query and load the result.
$db->setQuery($query);

$result = $db->loadObjectList();

// Set the query and load the result.
$items["ITEMNAME"]["value"]=$result;
print_r($result);

// Tried below and it only displayed one word, Array
//echo $result;


Here's an example of what I see:
Array ( [0] => stdClass Object ( [Name_exp_1] => John Smith [user_id] => [created] => [created_by] => [modified_user_id] => [modified] => [modified_by] => ) [1] => stdClass Object ( [Name_exp_1] => Sally Smith [user_id] => [created] => [created_by] => [modified_user_id] => [modified] => [modified_by] => ) [2] => stdClass Object ( [Name_exp_1] => Jane Doe [user_id] => [created] => [created_by] => [modified_user_id] => [modified] => [modified_by] => ) [3] => stdClass Object ( [Name_exp....


Here's what I'd ideally want but could settle for something similar, even without the field name at top:

Name_exp_1
John Smith
Sally Smith
Jane Doe

Options: ReplyQuote


Subject
Written By
Posted
Output showing as Array rather than Objects in row
October 13, 2020 09:10AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.