title: mysql SUM() and dynamic rows in php table for a specific user not working
body: <p>I am having difficulties creating a dynamic table using a mysql database... my database has this;</p>
  
  <pre><code>userid | product | amount
  2 | cat | 5
  2 | dog | 3
  2 | cat | 5
  3 | cat | 1
  3 | dog | 2
  </code></pre>
  
  <p>And I want to get a table that sums the amount of each product per user so that when the user visits a specific page, they can see their total of each product as (for example user 2);</p>
  
  <pre><code>Product | Amount
  cat | 10
  dog | 3
  </code></pre>
  
  <p>Here is my php code I had put together but it seems like my sum function isn't working and I cannot figure it out... Thanks in advance!</p>
  
  <pre><code>$userid = get_user_id()
  $amountperproduct = mysqli_query($con,"SELECT $userid SUM(amount) FROM wp_payout_history GROUP BY product");
  
  echo "&lt;table border='1'&gt;
  &lt;tr&gt;
  &lt;th&gt;product&lt;/th&gt;
  &lt;th&gt;grand sum&lt;/th&gt;
  &lt;/tr&gt;";
  if (mysqli_num_rows($amountperproduct)&gt;0){
  while($row2 = mysqli_fetch_array($amountperproduct))
  {
  echo "&lt;tr&gt;";
  echo "&lt;td&gt;" . $row2['product'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $row2['amount'] . "&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  }
  }
  echo "&lt;/table&gt;";
  </code></pre>