ProblemHelpPlease Posted June 10, 2011 Share Posted June 10, 2011 I have a database with a potentially large amount of entries (1 field per row of VARCHAR 200). I am current pulling the data out and using array_count_values on the data to achieve the result I require. Is it better (faster and more effecient) and indeed possible to perform something similar to array_count_values from within the mysql code before pulling the data out, rather than creating a very large array and using array_count_values. Link to comment Share on other sites More sharing options...
ckrudelux Posted June 10, 2011 Share Posted June 10, 2011 I have a database with a potentially large amount of entries (1 field per row of VARCHAR 200). I am current pulling the data out and using array_count_values on the data to achieve the result I require. Is it better (faster and more effecient) and indeed possible to perform something similar to array_count_values from within the mysql code before pulling the data out, rather than creating a very large array and using array_count_values.I can share two options with you:1. mysql_num_rows($query);2. mysql_query("SELECT COUNT(*) AS totalrows, * FROM table WHERE column='value' ORDER BY column ASC");Can't say much about speed difference but second one is said to be faster but I only manage to fetch on row out of plenty when I use it...first one only works in php Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted June 10, 2011 Author Share Posted June 10, 2011 The end result I am trying to achieve is the same as printing the array when array_count_values has been applied to it.A bit likething1 - 50thing2 - 47thing3 - 6 Link to comment Share on other sites More sharing options...
ckrudelux Posted June 10, 2011 Share Posted June 10, 2011 The end result I am trying to achieve is the same as printing the array when array_count_values has been applied to it.A bit likething1 - 50thing2 - 47thing3 - 6mysql_query("SELECT COUNT(*) AS totalrecords, column FROM table GROUP BY column ORDER BY column DESC");OUTPUT:array("totalrecords" => "50", "column" => "thing1");array("totalrecords" => "47", "column" => "thing2");array("totalrecords" => "6", "column" => "thing3"); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.