Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/513-query-error-and-im-going-nuts/
Share on other sites

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\'];

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.