title: Creating arrays from columns in database that I can echo in html
body: <p>Im sorry if this has been answered before but I am new to PHP and MySQL and I can't figure this out. </p>
  
  <p>Pretty much every time I alter my code to include an array I get a fatal error. What I am trying to do is display all the data in 3 columns from my table. </p>
  
  <p>I have my site set up where you log in and I store that user's name as a "code" in a session. I have a table that has multiple user form entries that are differentiated by the user's code because in my form, I grab the code as a hidden field and add it to the entry in the table. </p>
  
  <p>So far I have been able to isolate those entries by the users code, in one column I have the sum of all of the user's numerical data and I am able to echo this as a total. </p>
  
  <p>I want the other 3 columns to display all the values in their columns and for each value have a line break in between them. And I am trying to print or echo these results in specific parts on a confirmation page.</p>
  
  <p>I have seen examples with PDO using fetch_all and other examples of storing arrays but I can't seem to figure it out with my existing code.</p>
  
  <p>Here is my existing code:</p>
  
  <pre><code>&lt;?php
  $user = *****;
  $pass = *****;
  $dbh = new PDO('mysql:host=localhost;dbname=*****', $user, $pass);
  
  $stmt = $dbh-&gt;prepare("SELECT sum(price),part_number,location,price FROM products WHERE code = :usercode");
  $stmt-&gt;bindParam(':usercode', $_SESSION['MM_Username']);
  
  if ($stmt-&gt;execute()) {
  $user = $stmt-&gt;fetch(PDO::FETCH_ASSOC);
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>And here is where I want to display the results:</p>
  
  <pre><code>&lt;table style="margin:0 auto;" cellspacing="7" width="100%"&gt;
  &lt;tbody&gt;
  
  &lt;tr&gt;
    &lt;td&gt;&lt;?php echo $user['part_number']; ?&gt;&lt;/td&gt;&lt;!--all column values--&gt;
    &lt;td&gt;&lt;?php echo $user['location']; ?&gt;&lt;/td&gt;&lt;!--all column values--&gt;
    &lt;td&gt;&lt;?php echo $user['price']; ?&gt;&lt;/td&gt;&lt;!--all column values--&gt;
    &lt;td&gt;&lt;?php echo "Total:",  $user['sum(price)']; ?&gt;&lt;br&gt;&lt;/td&gt;&lt;!--this is ok--&gt;
  
  &lt;/tr&gt;
  
  
   &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>