My foreach loop doesn't loop trough all the results in the database. It only displays the last one, and does that xx times (total number of rows)
My code:
$query = db_query('SELECT * FROM push_notifications_messages WHERE msg_appID = :app_id', array(':app_id' => $id));
$qCount = db_query('SELECT * FROM push_notifications_messages WHERE msg_appID = :app_id', array(':app_id' => $id))->rowCount();
$form['table'] = array(
'#theme' => 'table',
'#header' => array(t('Message'), t('Device'), t('Date')),
'rows' => array(),
);
foreach($query as $result) {
for($i = 1; $i <= $qCount; $i++) {
$form['table']["#rows"]["'r$i'"] = array(
'c1' => array(
'data' => array('#type' => 'item', '#markup' => t('@message', array('@message' => $result->msg_message))),
),
'c2' => array(
'data' => array('#type' => 'item', '#markup' => t('@message', array('@message' => $result->msg_device))),
),
'c3' => array(
'data' => array('#type' => 'item', '#markup' => t('@message', array('@message' => date("d F Y H:i:s", $result->msg_timestamp)))),
),
);
}
}
Screenshot of database and result of foreach loop:
db screenshot http://i60.tinypic.com/2ytsfig.jpg result screenshot http://i59.tinypic.com/29f6r14.jpg
Thanks in advance!