Note that there are some explanatory texts on larger screens.

plurals
  1. POGroup mutliple array values in PHP
    primarykey
    data
    text
    <p>What I need is to take an issue id and track user submitted upvotes by the hour. I'm running into a wall when I try to get the data out of the array coherently for PHPExcel charting purposes.</p> <p>I end up with this $hourlyUpvotesTodayResult[] array, which has the correct number of votes for each hour (verified through print_r), but I want to group them in such a way where I can do something like "for each issue id display the hours 0-24 and the total votes for each hour". Maybe I'm overthinking it and missing something simple. </p> <p>Also, please ignore the ancient MySQL - I'm working on some existing code, I know it's deprecated and I'll get around to updating it someday :D</p> <pre><code>while ($todayInfoRow = mysql_fetch_array($todayInfoQuery)) { $issue_entry_id_today = array($todayInfoRow['issue_entry_id']); foreach ($issue_entry_id_today as $issue_entry_id_today) { $todayInfoUpvotes = "SELECT id from $db.$tb2 WHERE date = '".$date."' and issue_entry_id = '".$issue_entry_id_today."' ORDER BY issue_entry_id DESC"; $todayInfoUpvotesQuery = mysql_query($todayInfoUpvotes)or die(mysql_error()); $todayInfoUpvotesRow = mysql_num_rows($todayInfoUpvotesQuery); $todayInfoResult = array($issue_entry_id_today, $todayInfoUpvotesRow); } // get votes for individual hours for today for ($hour_today=0; $hour_today&lt;25; $hour_today++) { $hourlyUpvotesToday = "SELECT id from $db.$tb2 WHERE date = '".mysql_real_escape_string($date)."' AND issue_entry_id = '".$issue_entry_id_today."' AND hour = '".$hour_today."' ORDER BY issue_entry_id DESC"; $hourlyUpvotesTodayQuery = mysql_query($hourlyUpvotesToday)or die(mysql_error()); $hourlyUpvotesTodayRow = mysql_num_rows($hourlyUpvotesTodayQuery); $hourlyUpvotesTodayResult[] = array('id'=&gt;$issue_entry_id_today, 'upvotes'=&gt;$hourlyUpvotesTodayRow, 'hour'=&gt;$hour); } } //debug print array print_r($hourlyUpvotesTodayResult); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload