Monkuar Posted October 31, 2012 Share Posted October 31, 2012 Okay see the code below: $result = $db->query('SELECT g_id, g_user_title,g_color from groups where g_id != 3 AND g_id != 5 AND g_id != 4 AND g_id != 0 AND g_id != 12 ORDER BY g_moderator DESC') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error()); while ($stats =$db->fetch_assoc($result)){ //Grab how many members each group has $result2 = $db->query('SELECT COUNT(group_id) as members from users where group_id = '.$stats['g_id'].' ') or error('Unable to fetch forum topic count', __FILE__, __LINE__, $db->error()); list($totalmembers) = $db->fetch_row($result2); $groupinfo[] = $stats; } $fh = @fopen(FORUM_CACHE_DIR.'cache_group_info.php', 'wb'); fwrite($fh, '<?php '."\n\n".'$ginfo = '.var_export($groupinfo, true).';'."\n\n".'?>'); Okay so when this works, it will create my cache_group_info.php file: $ginfo = array ( 0 => array ( 'g_id' => '2', 'g_user_title' => 'title', 'g_color' => '0F77FF', ), 1 => array ( 'g_id' => '9', 'g_user_title' => 'title', 'g_color' => '00CCFF', ), 2 => array ( 'g_id' => '1', 'g_user_title' => 'title', 'g_color' => 'FF0000', ), 3 => array ( 'g_id' => '7', 'g_user_title' => 'title', 'g_color' => 'EEB10A', ), 4 => array ( 'g_id' => '10', 'g_user_title' => 'title', 'g_color' => '5888BF', ), 5 => array ( 'g_id' => '13', 'g_user_title' => 'title', 'g_color' => '995454', ), ); Now I want to add my "$totalmembers" array below each g_color with php only, I know the data is being called and created from the groups table, but is there a way to add it in with just php? I've tried: $groupinfo[$totalmembers][] = $stats; And a bunch of other crap which doesn't work, if you can help I'd appreciate it greatly, thanks Quote Link to comment https://forums.phpfreaks.com/topic/270101-need-to-add-extra-row-to-var_export/ Share on other sites More sharing options...
Monkuar Posted October 31, 2012 Author Share Posted October 31, 2012 (edited) Update: I tried this: $groupinfo[] = $stats; array_push($totalmembers); But this is not working either, (Couldn't edit my topic, sorry for double post) Edit again: Even tried: $groupinfo[] = $stats; array_merge($groupinfo, $totalmembers); Still not working, Edit 3rd: tried: $addme = array_push($groupinfo, 'test'); $groupinfo[$addme][] = $stats; still fail WHOA SO CLOSE!! $total['members'] = $totalmembers; $groupinfo[] = $stats; array_push($groupinfo, $total); But it shows: $ginfo = array ( 0 => array ( 'g_id' => '2', 'g_user_title' => 'Moderator', 'g_color' => '0F77FF', ), 1 => array ( 'members' => '1', ), 2 => array ( 'g_id' => '9', 'g_user_title' => 'Jr. Moderator', 'g_color' => '00CCFF', ), 3 => It's making a new array, I need it to be added under g_color, so it shows: 'g_color' => '00ccFF', 'members' => '2', I am so close, hope u can help hehe Edited October 31, 2012 by Monkuar Quote Link to comment https://forums.phpfreaks.com/topic/270101-need-to-add-extra-row-to-var_export/#findComment-1388928 Share on other sites More sharing options...
Barand Posted October 31, 2012 Share Posted October 31, 2012 If you do it correctly with a JOIN instead of running queries in a loop you can eradicate your problem. SELECT g.g_id, g.g_user_title, g.g_color, COUNT(m.group_id) as tot FROM groups g LEFT JOIN members m ON g.g_id = m.group_id WHERE g_id NOT IN (0,3,4,5,12) ORDER BY g.g_moderator DESC Quote Link to comment https://forums.phpfreaks.com/topic/270101-need-to-add-extra-row-to-var_export/#findComment-1388969 Share on other sites More sharing options...
kicken Posted October 31, 2012 Share Posted October 31, 2012 $stats['members'] = $totalmembers; $groupinfo[] = $stats; wanting to "add [$totalmembers] below each g_color" means you want to add it to the stats array, since that is where g_color exists at. Quote Link to comment https://forums.phpfreaks.com/topic/270101-need-to-add-extra-row-to-var_export/#findComment-1388970 Share on other sites More sharing options...
Monkuar Posted October 31, 2012 Author Share Posted October 31, 2012 Both solutions work fine, thank you both. Topic Solved, + Liked! Quote Link to comment https://forums.phpfreaks.com/topic/270101-need-to-add-extra-row-to-var_export/#findComment-1389054 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.