Web Hosting Talk







View Full Version : problem with mysql query


mikey1090
07-04-2006, 04:13 AM
Ok, i have a mysql table called "in"

It tracks the guests who come to my site, and stores them in a table. The table has 3 fields : ip, from, id

id is unique, from is varchar, and ip is varchar.

Here is my php code that wont work:

<?
require "db.php";





echo "<table border=1 height=30 table width=550 cellpadding=2 cellspacing=0 align=center bordercolor=#444444 bgcolor=black>

<td><font color=white>From:

<td><font color=white>Number:


<tr>";


$result = mysql_query("SELECT COUNT(from) FROM in ORDER BY from",$db);
while($myrow=mysql_fetch_array($result)) {

echo "


<td><font color=white>".$myrow["from"]."
<td><font color=white>".$myrow["COUNT(from)"]."


<tr>";

}
echo "</table>";

?>



Ok, so all i want to do, is display where the people came from (such as top web games, etc) and count how many people came from each place.

Here is the error i am getting in the browser:



Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/zorg1090/public_html/admin4noobs/af.php on line 19



so basically the query is wrong. I have tried loads, but can't seem to debug it....



Please help


mike

UK-Networks
07-04-2006, 05:30 AM
try

$result = mysql_query("SELECT COUNT([from]) FROM in ORDER BY [from]",$db);

from is a mysql keyword and you have to escape it using [] in order to use it in a query.

Rgds,
Chris