curryman Posted March 21, 2009 Share Posted March 21, 2009 I have an array being generated from a database like $sql = 'SELECT p.topic_id AS t_id, f.fact_id AS f_id, f.fact_name AS f_name, COUNT(DISTINCT p.topic_id) AS count FROM ' . POLL_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FACT_TABLE . ' f WHERE p.topic_id = t.topic_id AND t.fact_id = f.fact_id' . $fact_sql . ' GROUP BY f_id ORDER BY count ' . $order; $result = $db->sql_query_limit($sql, $limit_count); while ($temp_row = $db->sql_fetchrow($result)) { $fact_ary[] = $temp_row; } $db->sql_freeresult($result); Therefore for as long as there is a database row the array is built up for example: t_id,f_id,f.fact_name, p_topic_is 2,1,true,5 6,4,false,7 etc etc This array is then used in other parts of the script What i want to do is take the $fact_ary and make another array from the results say $graph_ary but i only want the last 2 variables in the array so i would end up with the array of true,5 false,7 etc etc. How do i do this as in array to array Thanks Link to comment https://forums.phpfreaks.com/topic/150478-array-sorting/ Share on other sites More sharing options...
WolfRage Posted March 21, 2009 Share Posted March 21, 2009 Are the last two names of the array's fields always going to be known by the script? Link to comment https://forums.phpfreaks.com/topic/150478-array-sorting/#findComment-790340 Share on other sites More sharing options...
curryman Posted March 21, 2009 Author Share Posted March 21, 2009 Hi Yes they are. As the array builds then the original array is sent to one part of the script and the last 2 that form the new array are sent to another part of the script Link to comment https://forums.phpfreaks.com/topic/150478-array-sorting/#findComment-790350 Share on other sites More sharing options...
WolfRage Posted March 21, 2009 Share Posted March 21, 2009 Well then just break the array into a new one like so. <?php $new_array['f.fact_name']=$fact_ary['f.fact_name']; $new_array['p_topic_is']=$fact_ary['p_topic_is'] ; //Now you have a new smaller array. ?> But this was too simple so I don't think it is exactly what you want. Can you explian better if it is not? Link to comment https://forums.phpfreaks.com/topic/150478-array-sorting/#findComment-790367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.