PDA

View Full Version : Strange Error on working PHP


Entourage
10-14-2002, 11:00 AM
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in www/htdocs/test/admin/db_mysql.php on line 154


$currenthits=$DB_site->query_first("SELECT hits FROM main WHERE id=1");
$negertje=$currenthits['hits'] + 1;
$DB_site->query_first("UPDATE main SET hits=$negertje WHERE id=1");


TABLE main (
hits int(10) NOT NULL default '0',
id tinyint(4) NOT NULL default '1'
) TYPE=MyISAM;

It all works but gives that stupid error :/ why o why? :(

DrkFusion
10-14-2002, 04:07 PM
Ah Yes, I get this same error, are you running on a server with Ensim Administration?

-nOX

Velocd
10-14-2002, 04:08 PM
The error is probably caused because you are using query_first instead of query. Also, this method would be easier and save you a query:


$DB_site->query("UPDATE main SET hits=hits+1 WHERE id=1");

Xenon
10-14-2002, 04:08 PM
if you run queries with no output you can't use query_first, just use query.
Because query_first is a call of query and then uses fetch_array once.

so correct it would be:$currenthits=$DB_site->query_first("SELECT hits FROM main WHERE id=1");
$negertje=$currenthits['hits'] + 1;
$DB_site->query("UPDATE main SET hits=$negertje WHERE id=1");
and if you don't need your $negertje and currenthits values anymore you can save a query by doing just this:
$DB_site->query("UPDATE main SET hits=hits+1 WHERE id=1");

DrkFusion
10-14-2002, 04:09 PM
Yes, but Ensim has some sort of universal problem, with this fetch_array thing, its a continued problem for me as well.

-Arunan

DrkFusion
10-14-2002, 04:12 PM
I get this error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site19/fst/var/www/html/support/admin/db_mysql.php on line 149

DrkFusion
10-14-2002, 04:13 PM
Here is the php
if ($string!="") {
$condition.=" AND linkname LIKE '%".addslashes($string)."%' OR linkdesc LIKE '%".addslashes($string)."%'";
}

$search=$DB_site->query_first("SELECT linkid,catagoryid,linkname,linkdesc FROM gportal_weblinkslink ORDER BY linkname");

while ($results=$DB_site->fetch_array($search)) {
$linkid = $results['linkid'];
$linkname = $results['linkname'];
$linkdesc = $results['linkdesc'];
$hits = $results['hits'];

eval("\$resultbits .= \"".gettemplate("drkslinks_linkbit")."\";");
}

eval("\$navigation = \"".gettemplate("drkslinks_navigation")."\";");
eval("dooutput(\"".gettemplate('drkslinks_searchresults')."\");");;

Xenon
10-14-2002, 04:55 PM
arunan: also you have to cut out the _first of your query call..

you cannot use fetch_array with query_first
the outputtype of query is a mysql result, this is what you can use in fetch_array.
the outputtype of query_first is just a normal array not a mysql result so you can't use it with fetch_array

DrkFusion
10-14-2002, 05:15 PM
Thanks Xenon, worked great!

-Arunan

DrkFusion
10-14-2002, 06:03 PM
Hey Xenon, the stuff are getting listed, but they all get listed now, not just the ones with the key words :'(

Xenon
10-14-2002, 06:05 PM
perhaps because you don't use a where in the query ;)

this would be right:

$search=$DB_site->query("SELECT linkid,catagoryid,linkname,linkdesc FROM gportal_weblinkslink WHERE $condition ORDER BY linkname");

Entourage
10-14-2002, 06:20 PM
thnx ppl it works now, stupid mistake of me :)

DrkFusion
10-14-2002, 06:24 PM
Originally posted by Xenon
perhaps because you don't use a where in the query ;)

this would be right:

$search=$DB_site->query("SELECT linkid,catagoryid,linkname,linkdesc FROM gportal_weblinkslink WHERE $condition ORDER BY linkname");
:(
Now I get
Database error in vBulletin 2.2.8:

Invalid SQL: SELECT linkid,catagoryid,linkname,linkdesc FROM gportal_weblinkslink WHERE ORDER BY linkname
mysql error: You have an error in your SQL syntax near 'ORDER BY linkname' at line 1

mysql error number: 1064

Date: Monday 14th of October 2002 03:23:35 PM
Script: http://www.noxmedia.net/support/support/links.php
Referer: http://www.noxmedia.net/support/links.php?action=search


Thanks for your continued support.
I don't know what the problem is :cry:

Thanks in Advance
-Arunan

DrkFusion
10-14-2002, 06:37 PM
Nm, got it to work, thanks Xenon!

Xenon
10-15-2002, 08:09 AM
you're welcome :)