SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: MySQL help: seemingly simple
-
Apr 2, 2002, 00:08 #1
- Join Date
- Apr 2002
- Location
- Crown Point, IN
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
MySQL help: seemingly simple
I have a real problem. It's stupid, but it doesn't work and I can't figure it out. I'm storing a hit counter in a database (don't ask why). I can get the number to go up each time, I just can't get it to display on the page. My table has one row in it and two columns (id and hits). id = 0 and hits = the number of hits, obviously.
I've tried "SELECT hits FROM table" and "SELECT hits FROM table WHERE id = '0'" and basically everything I can think of, and every time I get the same result: a string that says "Resource id #2" Any idea why this is? And any idea how to fix this? Thanks a ton.
-
Apr 2, 2002, 03:08 #2
- Join Date
- Jul 2001
- Location
- Missouri
- Posts
- 3,428
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
why are you storing a hit counter in a database???
sorry.
you're probably doing something like this, right:
PHP Code:$hits = mysql_query("SELECT hits FROM table");
echo $hits;
mysql_query() only returns a resource id (which you're seeing). so you need to use something like this:
PHP Code:$result = mysql_query("SELECT hits FROM table WHERE id=0");
$row = mysql_fetch_array($result);
echo $row['hits'];
- Matt** Ignore old signature for now... **
Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
"Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR
-
Apr 2, 2002, 22:36 #3
- Join Date
- Apr 2002
- Location
- Crown Point, IN
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you so much! Yes, that's exactly what I was doing. I wasn't sure that I'd need to do the fetch since I was only dealing with a single number. Thanks again! (As you can tell, I'm really a newbie with MySQL.)
Bookmarks