Mysql -> pulling count of occurrence of result and displaying on page

Hi all,

I have ran a query to pull the number of distances in a query and how many times the have been repeated and get the following result


>   distance   rows

>     1m6.5f    1
>     1m6f      2
>     2m        5
>     2m.5f     1
>     2m1f      1

but i now need to output the data and add it into the following code:

['Distance', 'Percentage'],

 ['1m6.5f ', 1],
 ['1m6f', 2]

currenly all i have is the following code to get the data

   $sqlhorses = "SELECT distance, COUNT( * ) AS ROWS FROM  `horsesrp`  WHERE  `Horse` = '".$horse."' and place = '1' or  `Horse` = '".$horse."' and place = '2' or  `Horse` = '".$horse."' and place = '3' GROUP BY  `Distance` 
    HAVING ROWS >0";
    $horseplaced = mysqli_query($db, $sqlhorses);
    	while($pasthorse = mysqli_fetch_array($horseplaced)){

Open in new window

so i can return the results but I am not sure where to go with adding it into the desired output.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
It really depends on how you want the data stored. Here's a simple example, but you may need to be clearer on what you want:

$output = array();
while($pasthorse = mysqli_fetch_array($horseplaced)){
   $output[] = array(
      'Distance' => $pasthorse['distance'],
      'Rows' => $pasthorse['ROWS'],

Open in new window

You now have an array of arrays containing the data. You can visualise it by using var_dump:

Brian TaoSenior Business Solutions ConsultantCommented:
This should work:
$data = "['Distance', 'Percentage']";
while($pasthorse = mysqli_fetch_array($horseplaced)){
  $data .= ", ['" . $pasthorse['distance'] . "', " . $pasthorse['ROWS'] . "]";
echo $data;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
runnerjp2005Author Commented:
sometimes you look for a complex answer when a simple one is right infront of you ... thanks :)
Brian TaoSenior Business Solutions ConsultantCommented:
Thanks for the points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.