SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast wiseguy316's Avatar
    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.

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    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
    well, you need to fetch the row before you can display anything. 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

  3. #3
    SitePoint Enthusiast wiseguy316's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •