emma perkins
emma perkins

Reputation: 769

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

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)){

    }

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

Upvotes: 0

Views: 42

Answers (1)

Script Kitty
Script Kitty

Reputation: 1747

From what I understand in your question, you're looking for a way for your data to be transformed from a PDO/mysqli to string array.

Can you try to use the fetch() function?

$valuesarray = $horseplace->fetch();//Holding the values plainly
for(int i=0; i<$horseplace->rowCount(); i++){
    $valuesarray[i];
}

Please tell me if this works for you or let me know if it didn't properly answer your question. Thanks

Upvotes: 1

Related Questions