Hi All,
I am ripping my hair out over why this doesnt work.......and im sure its something really simple.
Basically I have a Database Of Data That I want To Print to a PHP Page, which will list in a Descending order of how many are in the same in a certain Field......
e.g
FRUIT | COUNT(*)
APPLES = 10
BANANAS = 9
PEACHES = 6
ORANGES = 2
Now I know what the command SQL command is :
"SELECT FRUIT , COUNT(*) FROM mytable GROUP BY FRUIT ORDER BY COUNT( * ) DESC LIMIT 0, 30"
As I have tested this within phpMyAdmin and it works......
However I fail to print this to PHP.
I believe I need a Loop here in order to get all the rows and print them all
I have used
"
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
}
"
SO my Code Looks Like
$query = "'SELECT FRUIT , COUNT(*) FROM mytable GROUP BY FRUIT ORDER BY COUNT( * ) DESC LIMIT 0, 30 '";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
?>
<?php echo ($row['FRUIT'])?>
<?php echo ($row['COUNT'])?>
<?php
}
mysql_free_result($result);
mysql_close();
?>
"
However This Fails,
I have tried using mysql_fetch_row and mysql_fetch_array and mysql_fetch_assoc but all show
"
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource"
Someone PLease Help Me