Converting PDO resultset array to string Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!PHP: Displaying table data using fetchall()PHP: Delete an element from an arrayConvert HTML + CSS to PDF with PHP?Get the first element of an arrayConvert PHP object to associative arrayHow do I check if a string contains a specific word?Session Not Posting Immediately in ModX EvoPHP assign multiple arrays to $_SESSIONCannot display HTML stringphp session array add an element if same IDPHP select row from session[a] array to store session[b]

Network Switch Upgrade Planning questions

Import keychain to clean macOS install?

How do I overlay a PNG over two videos (one video overlays another) in one command using FFmpeg?

Can I ask an author to send me his ebook?

Is it OK if I do not take the receipt in Germany?

When does Bran Stark remember Jamie pushing him?

Protagonist's race is hidden - should I reveal it?

Why did Israel vote against lifting the American embargo on Cuba?

Why do people think Winterfell crypts is the safest place for women, children & old people?

Putting Ant-Man on house arrest

Can Deduction Guide have an explicit(bool) specifier?

How can I introduce the names of fantasy creatures to the reader?

What's the connection between Mr. Nancy and fried chicken?

Weaponising the Grasp-at-a-Distance spell

Does the Pact of the Blade warlock feature allow me to customize the properties of the pact weapon I create?

Is "ein Herz wie das meine" an antiquated or colloquial use of the possesive pronoun?

Trying to enter the Fox's den

Do chord progressions usually move by fifths?

Can this water damage be explained by lack of gutters and grading issues?

Converting a text document with special format to Pandas DataFrame

Can the van der Waals coefficients be negative in the van der Waals equation for real gases?

What is the evidence that custom checks in Northern Ireland are going to result in violence?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

What were wait-states, and why was it only an issue for PCs?



Converting PDO resultset array to string



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!PHP: Displaying table data using fetchall()PHP: Delete an element from an arrayConvert HTML + CSS to PDF with PHP?Get the first element of an arrayConvert PHP object to associative arrayHow do I check if a string contains a specific word?Session Not Posting Immediately in ModX EvoPHP assign multiple arrays to $_SESSIONCannot display HTML stringphp session array add an element if same IDPHP select row from session[a] array to store session[b]



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a class that retrieves a result set from a database. The result is wrapped in arrays which are then stored as session variables as shown in the code



 $days = array();
$amount = array();
$commission = array();

foreach ($result as $row) {
array_push($days,$row['sales_day']);
array_push($amount,$row['sales_total']);
array_push($commission,$row['sales_comm']);
$_SESSION['days'] = $days;
$_SESSION['amount'] = $amount;
$_SESSION['commission'] = $commission;


I then attempt to display the data in HTML table as in this code:



<tr>
<td><label><?php print_r($_SESSION['days']); ?></label></td>
<td><label><?php print_r ($_SESSION['amount']); ?></label></td>
<td><label><?php print_r($_SESSION['commission']); ?></label></td>
</tr>


The problem is that the output is something like: array[0] => 1. But I want only the values retrieved from the database to display and not the array indices.










share|improve this question
























  • If print_r shows that, it means that's what $row['sales_day'] (and others) contained to begin with. You're gonna have to show more code than that.

    – Jeto
    Mar 3 at 7:13







  • 2





    print_r is intended to output the structure of data, not as a user friendly table output. You'll need to iterate the data to output the individual values, probably each in their own <td>, like done here. NB: the use of session variables seems irrelevant to your question?

    – trincot
    Mar 3 at 7:30

















0















I have a class that retrieves a result set from a database. The result is wrapped in arrays which are then stored as session variables as shown in the code



 $days = array();
$amount = array();
$commission = array();

foreach ($result as $row) {
array_push($days,$row['sales_day']);
array_push($amount,$row['sales_total']);
array_push($commission,$row['sales_comm']);
$_SESSION['days'] = $days;
$_SESSION['amount'] = $amount;
$_SESSION['commission'] = $commission;


I then attempt to display the data in HTML table as in this code:



<tr>
<td><label><?php print_r($_SESSION['days']); ?></label></td>
<td><label><?php print_r ($_SESSION['amount']); ?></label></td>
<td><label><?php print_r($_SESSION['commission']); ?></label></td>
</tr>


The problem is that the output is something like: array[0] => 1. But I want only the values retrieved from the database to display and not the array indices.










share|improve this question
























  • If print_r shows that, it means that's what $row['sales_day'] (and others) contained to begin with. You're gonna have to show more code than that.

    – Jeto
    Mar 3 at 7:13







  • 2





    print_r is intended to output the structure of data, not as a user friendly table output. You'll need to iterate the data to output the individual values, probably each in their own <td>, like done here. NB: the use of session variables seems irrelevant to your question?

    – trincot
    Mar 3 at 7:30













0












0








0








I have a class that retrieves a result set from a database. The result is wrapped in arrays which are then stored as session variables as shown in the code



 $days = array();
$amount = array();
$commission = array();

foreach ($result as $row) {
array_push($days,$row['sales_day']);
array_push($amount,$row['sales_total']);
array_push($commission,$row['sales_comm']);
$_SESSION['days'] = $days;
$_SESSION['amount'] = $amount;
$_SESSION['commission'] = $commission;


I then attempt to display the data in HTML table as in this code:



<tr>
<td><label><?php print_r($_SESSION['days']); ?></label></td>
<td><label><?php print_r ($_SESSION['amount']); ?></label></td>
<td><label><?php print_r($_SESSION['commission']); ?></label></td>
</tr>


The problem is that the output is something like: array[0] => 1. But I want only the values retrieved from the database to display and not the array indices.










share|improve this question
















I have a class that retrieves a result set from a database. The result is wrapped in arrays which are then stored as session variables as shown in the code



 $days = array();
$amount = array();
$commission = array();

foreach ($result as $row) {
array_push($days,$row['sales_day']);
array_push($amount,$row['sales_total']);
array_push($commission,$row['sales_comm']);
$_SESSION['days'] = $days;
$_SESSION['amount'] = $amount;
$_SESSION['commission'] = $commission;


I then attempt to display the data in HTML table as in this code:



<tr>
<td><label><?php print_r($_SESSION['days']); ?></label></td>
<td><label><?php print_r ($_SESSION['amount']); ?></label></td>
<td><label><?php print_r($_SESSION['commission']); ?></label></td>
</tr>


The problem is that the output is something like: array[0] => 1. But I want only the values retrieved from the database to display and not the array indices.







php html resultset






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 13:59









marc_s

586k13011281273




586k13011281273










asked Mar 3 at 7:07









ZeekstemZeekstem

266




266












  • If print_r shows that, it means that's what $row['sales_day'] (and others) contained to begin with. You're gonna have to show more code than that.

    – Jeto
    Mar 3 at 7:13







  • 2





    print_r is intended to output the structure of data, not as a user friendly table output. You'll need to iterate the data to output the individual values, probably each in their own <td>, like done here. NB: the use of session variables seems irrelevant to your question?

    – trincot
    Mar 3 at 7:30

















  • If print_r shows that, it means that's what $row['sales_day'] (and others) contained to begin with. You're gonna have to show more code than that.

    – Jeto
    Mar 3 at 7:13







  • 2





    print_r is intended to output the structure of data, not as a user friendly table output. You'll need to iterate the data to output the individual values, probably each in their own <td>, like done here. NB: the use of session variables seems irrelevant to your question?

    – trincot
    Mar 3 at 7:30
















If print_r shows that, it means that's what $row['sales_day'] (and others) contained to begin with. You're gonna have to show more code than that.

– Jeto
Mar 3 at 7:13






If print_r shows that, it means that's what $row['sales_day'] (and others) contained to begin with. You're gonna have to show more code than that.

– Jeto
Mar 3 at 7:13





2




2





print_r is intended to output the structure of data, not as a user friendly table output. You'll need to iterate the data to output the individual values, probably each in their own <td>, like done here. NB: the use of session variables seems irrelevant to your question?

– trincot
Mar 3 at 7:30





print_r is intended to output the structure of data, not as a user friendly table output. You'll need to iterate the data to output the individual values, probably each in their own <td>, like done here. NB: the use of session variables seems irrelevant to your question?

– trincot
Mar 3 at 7:30












1 Answer
1






active

oldest

votes


















1














I've considered that you need to save data in a part of your code and print them somewhere else.



if at the first step you want to save all items into $_SESSION and then show them in next steps, use this code:



the first step:



$merged_data = array();
foreach ($result as $row)
$merged_data[] = array(
'sales_day' => $row['sales_day'],
'sales_total' => $row['sales_total'],
'sales_comm' => $row['sales_comm']
);

$_SESSION['merged_data'] = $merged_data;


the second step: (somewhere else in your code)



<?php foreach ($_SESSION['merged_data'] as $data) ?>
<td><label><?= $data['days']; ?></label></td>
<td><label><?= $data['amount']; ?></label></td>
<td><label><?= $data['commission']; ?></label></td>
<?php ?>





share|improve this answer























  • Thanks a lot @sohiel. I used your code as is and it worked perfectly. But note that the variables in $data are: sales_day, sales_amount, sales_comm. Thanks again. I am very grateful

    – Zeekstem
    Mar 3 at 8:49











  • @Zeekstem your welcome, you can select the answer as the accepted answer if it solved your problem

    – soheil yo
    Mar 4 at 14:51












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54966433%2fconverting-pdo-resultset-array-to-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I've considered that you need to save data in a part of your code and print them somewhere else.



if at the first step you want to save all items into $_SESSION and then show them in next steps, use this code:



the first step:



$merged_data = array();
foreach ($result as $row)
$merged_data[] = array(
'sales_day' => $row['sales_day'],
'sales_total' => $row['sales_total'],
'sales_comm' => $row['sales_comm']
);

$_SESSION['merged_data'] = $merged_data;


the second step: (somewhere else in your code)



<?php foreach ($_SESSION['merged_data'] as $data) ?>
<td><label><?= $data['days']; ?></label></td>
<td><label><?= $data['amount']; ?></label></td>
<td><label><?= $data['commission']; ?></label></td>
<?php ?>





share|improve this answer























  • Thanks a lot @sohiel. I used your code as is and it worked perfectly. But note that the variables in $data are: sales_day, sales_amount, sales_comm. Thanks again. I am very grateful

    – Zeekstem
    Mar 3 at 8:49











  • @Zeekstem your welcome, you can select the answer as the accepted answer if it solved your problem

    – soheil yo
    Mar 4 at 14:51
















1














I've considered that you need to save data in a part of your code and print them somewhere else.



if at the first step you want to save all items into $_SESSION and then show them in next steps, use this code:



the first step:



$merged_data = array();
foreach ($result as $row)
$merged_data[] = array(
'sales_day' => $row['sales_day'],
'sales_total' => $row['sales_total'],
'sales_comm' => $row['sales_comm']
);

$_SESSION['merged_data'] = $merged_data;


the second step: (somewhere else in your code)



<?php foreach ($_SESSION['merged_data'] as $data) ?>
<td><label><?= $data['days']; ?></label></td>
<td><label><?= $data['amount']; ?></label></td>
<td><label><?= $data['commission']; ?></label></td>
<?php ?>





share|improve this answer























  • Thanks a lot @sohiel. I used your code as is and it worked perfectly. But note that the variables in $data are: sales_day, sales_amount, sales_comm. Thanks again. I am very grateful

    – Zeekstem
    Mar 3 at 8:49











  • @Zeekstem your welcome, you can select the answer as the accepted answer if it solved your problem

    – soheil yo
    Mar 4 at 14:51














1












1








1







I've considered that you need to save data in a part of your code and print them somewhere else.



if at the first step you want to save all items into $_SESSION and then show them in next steps, use this code:



the first step:



$merged_data = array();
foreach ($result as $row)
$merged_data[] = array(
'sales_day' => $row['sales_day'],
'sales_total' => $row['sales_total'],
'sales_comm' => $row['sales_comm']
);

$_SESSION['merged_data'] = $merged_data;


the second step: (somewhere else in your code)



<?php foreach ($_SESSION['merged_data'] as $data) ?>
<td><label><?= $data['days']; ?></label></td>
<td><label><?= $data['amount']; ?></label></td>
<td><label><?= $data['commission']; ?></label></td>
<?php ?>





share|improve this answer













I've considered that you need to save data in a part of your code and print them somewhere else.



if at the first step you want to save all items into $_SESSION and then show them in next steps, use this code:



the first step:



$merged_data = array();
foreach ($result as $row)
$merged_data[] = array(
'sales_day' => $row['sales_day'],
'sales_total' => $row['sales_total'],
'sales_comm' => $row['sales_comm']
);

$_SESSION['merged_data'] = $merged_data;


the second step: (somewhere else in your code)



<?php foreach ($_SESSION['merged_data'] as $data) ?>
<td><label><?= $data['days']; ?></label></td>
<td><label><?= $data['amount']; ?></label></td>
<td><label><?= $data['commission']; ?></label></td>
<?php ?>






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 3 at 7:58









soheil yosoheil yo

3431126




3431126












  • Thanks a lot @sohiel. I used your code as is and it worked perfectly. But note that the variables in $data are: sales_day, sales_amount, sales_comm. Thanks again. I am very grateful

    – Zeekstem
    Mar 3 at 8:49











  • @Zeekstem your welcome, you can select the answer as the accepted answer if it solved your problem

    – soheil yo
    Mar 4 at 14:51


















  • Thanks a lot @sohiel. I used your code as is and it worked perfectly. But note that the variables in $data are: sales_day, sales_amount, sales_comm. Thanks again. I am very grateful

    – Zeekstem
    Mar 3 at 8:49











  • @Zeekstem your welcome, you can select the answer as the accepted answer if it solved your problem

    – soheil yo
    Mar 4 at 14:51

















Thanks a lot @sohiel. I used your code as is and it worked perfectly. But note that the variables in $data are: sales_day, sales_amount, sales_comm. Thanks again. I am very grateful

– Zeekstem
Mar 3 at 8:49





Thanks a lot @sohiel. I used your code as is and it worked perfectly. But note that the variables in $data are: sales_day, sales_amount, sales_comm. Thanks again. I am very grateful

– Zeekstem
Mar 3 at 8:49













@Zeekstem your welcome, you can select the answer as the accepted answer if it solved your problem

– soheil yo
Mar 4 at 14:51






@Zeekstem your welcome, you can select the answer as the accepted answer if it solved your problem

– soheil yo
Mar 4 at 14:51




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54966433%2fconverting-pdo-resultset-array-to-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript