Jump to content

array sorting


curryman

Recommended Posts

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

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

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.