user1227914 user1227914 - 1 year ago 83
MySQL Question

additional variable into php array output?

I have the following script currently, which gets the category IDs as arrays:

$sql_select_categories = $db->query("SELECT category_id FROM " . DB_PREFIX . "categories
WHERE parent_id='" . intval($src_details['parent_id']) . "'
ORDER BY order_id ASC, name ASC");

$additional_vars = set_filter_link($src_details, array('parent_id' => '', 'start' => ''), 'address');

while ($cat_details = $db->fetch_array($sql_select_categories)) {
$cat_array[$cat_details['category_id']]["name"] = $category_lang[$cat_details['category_id']];

if(is_array($cat_array)) {

foreach($cat_array as $key => $value) {
$subcat_link = basename($_SERVER['PHP_SELF']) . '?parent_id=' . $key . $additional_vars;

$output .= '<tr> '.
' <td class="contentfont">&nbsp;&raquo; <a href="' . $subcat_link . '">' . $category_lang[$key] . '</a></td> '.
'</tr> ';
return $output;

This works perfectly, except I need to extract one more variable from the database which is called
. So the MySQL query will change from

SELECT category_id FROM


SELECT category_id, count FROM

So far so good, but how do I get it to then display each of the counts in the
? I need them displayed in the HTML after
as something like

Answer Source

Your $cat_details array will have another element that you can reference, which will be $cat_details['count']. You can then add that to your $cat_array like you do with that name element in the while loop.

$cat_array[ $cat_details['category_id'] ]['count'] = $cat_details['count'];

Make sense?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download