Jump to content

Need To Add Extra Row To Var_Export


Monkuar

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/270101-need-to-add-extra-row-to-var_export/
Share on other sites

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.