Jump to content


Photo

Query error, and I'm going nuts!


  • Please log in to reply
1 reply to this topic

#1 2muchspam

2muchspam
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationPortland, OR

Posted 26 May 2003 - 08:13 PM

Hello again!

I\'ve got a total hits script that I kinda got from an old nuke site. The script does incriment the database just fine. But when I call the result, I get \"Resource id #4\"
What the heck am I doing wrong?
Database:
# Table structure for table `hits`

#



CREATE TABLE hits (

  type varchar(80) NOT NULL default \'\',

  var varchar(80) NOT NULL default \'\',

  count int(10) unsigned NOT NULL default \'0\'

) TYPE=MyISAM;



#

# Dumping data for table `hits`

#



INSERT INTO hits VALUES (\'total\', \'hits\', 45612);

Here is the header script: (this works fine. stolen from nuke)

include_once \'db.php\';

mysql_query("UPDATE hits SET count=count+1 WHERE (type=\'total\' AND var=\'hits\')");


Here is the footer scriipt:

$total_hits = mysql_query("SELECT count FROM hits WHERE type=\'total\' AND var=\'hits\'");

echo "$total_hits";

Thanks in advance!

#2 2muchspam

2muchspam
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationPortland, OR

Posted 26 May 2003 - 08:57 PM

Got it!!
The result returned by a mysql query is not the data, it\'s a resource that contains the data. To get the data out, you need to \'fetch\' it out. Try it with mysql_fetch_array().


$query_th = mysql_query("SELECT count FROM hits");

$fetched_result = mysql_fetch_array($query_th);

$total_hits = $fetched_result[\'count\'];






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users