Click to See Complete Forum and Search --> : mysql_fetch_array(): errors!?
A_Tame_Lion
10-08-2006, 08:35 AM
Hello,
I am having a few problems with this script, part of a package of scripts designed to record website visitor data: I get the following errors:
---
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in // webstats.php on line 41
Unique visitors: 0
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in // webstats.php on line 53
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in // webstats.php on line 58
Visited documents: 0
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in // webstats.php on line 89
Top 50 Document PageviewsViews
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in // webstats.php on line 126
CountTop 50 Referrers (excluding mesedilla.com pages and bookmark)
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in // webstats.php on line 160
Total Top BrowsersCount
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in // webstats.php on line 195
Total Top ResolutionsCount
Query failed.Time StampDocument RequestedIP Address / HostnameBrowserResolutionReferrer
---
Can anyone help me work through this to resolve the errors, I have checked on the MySQL site, but can't seem to get my head around why I am getting the errors.
Sorry if this is in the wrong forum, but I thought as these are MySQL errors...
Regards,
ATL
A_Tame_Lion
10-08-2006, 08:45 AM
Here is the script:
<?php
//connect to the database
require("mojows_pro_def.php");
$mj_stamp = date("Y-m-d");
//connect to the database server
$mojows_connect = mysql_connect ($mojows_host, $mojows_username, $mojows_password) or die ("Could not connect");
//select database
mysql_select_db ($mojows_database,$mojows_connect);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="left" valign="top"><font color="#FF9900" size="4">Mojo Webstats Sample</font></td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0" bgcolor="99B3CC">
<tr>
<td width=100% align=left valign=top bgcolor=#003366><font face = arial size = 1>
<?php
//process visitors
$mojows_query = "SELECT id FROM mojows_visitors ORDER BY id DESC LIMIT 1";
$mojows_result = mysql_query($mojows_query);
$mojows_unvisitors = mysql_fetch_array($mojows_result);
$formatted_unique = number_format($mojows_unvisitors[id]);
print " Unique visitors: $formatted_unique\n";
print "<br>\n";
//process documents
$mojows_query = "SELECT count FROM mojows_page";
$mojows_result = mysql_query($mojows_query);
$doc_count = "0";
while($row = mysql_fetch_array($mojows_result))
{
$doc_count = $doc_count + $row[count];
}
$mojows_documents = mysql_num_rows($mojows_result);
$doc_count1 = number_format($doc_count);
print " Visited documents: $doc_count1\n";
?>
</font></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" valign="top" bgcolor="#003366"><img src="shim.gif" width="1" height="10"></td>
</tr>
<tr>
<td align="left" valign="top"><font color="#FF9900" size="2"><a href="javascript:window.location.reload()">Refresh Mojo Webstats</a></font></td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#003366"><img src="shim.gif" width="1" height="30"></td>
</tr>
</table>
<table width="440" border="0" cellspacing="1" cellpadding="0" bgcolor="99B3CC">
<tr>
<td width="400" align="center" valign="top" bgcolor="#003366"><font face="arial" size="1" color="#FF9900">Top 50 Document Pageviews</font></td>
<td width="40" align="center" valign="top" bgcolor="#003366"><font face="arial" size="1" color="#FF9900">Views</font></td>
</tr>
<?php
//process documents for today
$mojows_query = "SELECT page,title,count FROM mojows_page ORDER BY count DESC LIMIT 50";
$mojows_result = mysql_query($mojows_query);
while($row = mysql_fetch_array($mojows_result))
{
$formatted_doc = number_format($row[count]);
print "\t<tr>\n";
print "\t\t<td width=400 align=left valign=top bgcolor=#003366><font face = arial size = 1><a href=$row[page]>$row[title]</a></font></td>\n";
print "\t\t<td width=40 align=right valign=top bgcolor=#003366><font face = arial size = 1>$formatted_doc </font></td>\n";
print "\t</tr>\n";
}
?>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" valign="top" bgcolor="#003366"><img src="shim.gif" width="1" height="10"></td>
</tr>
<tr>
<td align="left" valign="top"><font color="#FF9900" size="2"><a href="javascript:window.location.reload()">Refresh Mojo Webstats</a></font></td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#003366"><img src="shim.gif" width="1" height="30"></td>
</tr>
</table>
<table width="640" border="0" cellspacing="1" cellpadding="0" bgcolor="99B3CC">
<tr>
<td width="40" align="center" valign="top" bgcolor="#003366"><font face="arial" size="1" color="#FF9900">Count</font></td>
<td width="600" align="center" valign="top" bgcolor="#003366"><font face="arial" size="1" color="#FF9900">Top 50 Referrers (excluding mesedilla.com pages and bookmark)</font></td>
</tr>
<?php
//process top referrers
$mojows_query = "SELECT referrer,count FROM mojows_ref WHERE referrer NOT LIKE '%mesedilla.com%' && referrer!='bookmark' ORDER BY count DESC LIMIT 50";
$mojows_result = mysql_query($mojows_query);
while($row = mysql_fetch_array($mojows_result))
{
$formatted_ref = number_format($row[count]);
print "\t<tr>\n";
print "\t\t<td width=40 align=right valign=top bgcolor=#003366><font face = arial size = 1>$formatted_ref </font></td>\n";
print "\t\t<td width=600 align=left valign=top bgcolor=#003366><font face = arial size = 1><a href=\"$row[referrer]\" target=\"_blank\">$row[referrer]</a></font></td>\n";
print "\t</tr>\n";
}
?>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" valign="top" bgcolor="#003366"><img src="shim.gif" width="1" height="10"></td>
</tr>
<tr>
<td align="left" valign="top"><font color="#FF9900" size="2"><a href="javascript:window.location.reload()">Refresh Mojo Webstats</a></font></td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#003366"><img src="shim.gif" width="1" height="30"></td>
</tr>
</table>
<table width="300" border="0" cellspacing="1" cellpadding="0" bgcolor="99B3CC">
<tr>
<td width="250" align="center" valign="top" bgcolor="#003366" colspan="2"><font face="arial" size="1" color="#FF9900">Total Top Browsers</font></td>
<td width="50" align="center" valign="top" bgcolor="#003366"><font face="arial" size="1" color="#FF9900">Count</font></td>
</tr>
<?php
//process total top browsers
$mojows_query = "SELECT b.name,c.version,count(c.version) AS counter FROM mojows_stats AS a, mojows_bname AS b, mojows_bver AS c WHERE a.bname=b.id && a.bver=c.id GROUP BY bver ORDER BY counter DESC";
$mojows_result = mysql_query($mojows_query);
while($row = mysql_fetch_array($mojows_result))
{
$formatted_count = number_format($row[counter]);
print "\t<tr>\n";
print "\t\t<td width=200 align=left valign=top bgcolor=#003366><font face = arial size = 1> $row[name]</font></td>\n";
print "\t\t<td width=50 align=left valign=top bgcolor=#003366><font face = arial size = 1> $row[version]</font></td>\n";
print "\t\t<td width=50 align=right valign=top bgcolor=#003366><font face = arial size = 1>$formatted_count </font></td>\n";
print "\t</tr>\n";
}
?>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" valign="top" bgcolor="#003366"><img src="shim.gif" width="1" height="10"></td>
</tr>
<tr>
<td align="left" valign="top"><font color="#FF9900" size="2"><a href="javascript:window.location.reload()">Refresh Mojo Webstats</a></font></td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#003366"><img src="shim.gif" width="1" height="30"></td>
</tr>
</table>
<table width="180" border="0" cellspacing="1" cellpadding="0" bgcolor="99B3CC">
<tr>
<td width="130" align="center" valign="top" bgcolor="#003366"><font face="arial" size="1" color="#FF9900">Total Top Resolutions</font></td>
<td width="50" align="center" valign="top" bgcolor="#003366"><font face="arial" size="1" color="#FF9900">Count</font></td>
</tr>
<?php
//process total top resolutions
$mojows_query = "SELECT resolution,count FROM mojows_res ORDER BY count DESC";
$mojows_result = mysql_query($mojows_query);
while($row = mysql_fetch_array($mojows_result))
{
$formatted_res = number_format($row[count]);
print "\t<tr>\n";
print "\t\t<td width=130 align=left valign=top bgcolor=#003366><font face = arial size = 1> $row[resolution]</a></font></td>\n";
print "\t\t<td width=50 align=right valign=top bgcolor=#003366><font face = arial size = 1>$formatted_res </font></td>\n";
print "\t</tr>\n";
}
?>
NogDog
10-08-2006, 08:59 AM
Those errors mean that MySQL is not able to process your queries due to some sort of syntax error or invalid table/column name. For debugging purposes, you might want to change your mysql_query() lines to something like this:
$mojows_result = mysql_query($mojows_query) or die("Query failed: $mojows_query - " . mysql_error());
This way if it fails, you'll see the exact query that was sent to MySQL along with the error message returned from MySQL.
A_Tame_Lion
10-08-2006, 12:39 PM
Hi Nog Dog,
I took your advice, and that got me set to start trying to figure this thing out a little more. Basically I think there is something wrong with line 16, the "require" statement, should that read "include". The deal is the "mojows_" prefix has been replaced by another prefix in the "mojows_pro_def.php" file, which the manual says you can do to make the prefix relate to your table name. So basically I think because the actual names in the table have been changed and the script doesn't call those actual names, but calls the "mojows_" prefix - which is not related to the actual prefix of the table names (because of the require statement), this is the reason why MySQL is returning errors, i.e.it is calling table names which don't exist. I undertand what I have just written, but I'm not sure if anyone else will.
Anyway so far I have got most of the script to work by changng the "mojows_" references within the MySQL SELECT statements to the correct prefix.