SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if row doesnt exist, create...

    ok im working on a counter type thing that displays the number of times that page has been viewed.

    I have a table that has 3 fields in ID | page | count

    when the page is loaded the script does a SQL command like SELECT count FROM count WHERE page='$page' then adds 1 to the count and updates the table...

    but how can i make it so if the page does not exist in the table then it is added so that the page views can be counted because i dont want to be adding hundreds of records to the table because of multipurpose pages eg. view.php?name=lauren, view.php?name=jim, view.php?name=ian etc.

    if anyone can help id be very greatful
    hmm...

  2. #2
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    id tried this but it doesnt seem to work

    PHP Code:
    $result mysql_query("SELECT page FROM count WHERE page = '$page'"); 
    $num_rows mysql_num_rows($result); 

    if (
    $num_rows == "0") {

    $sql "INSERT INTO count SET
    page='
    $page',
    count='1'"
    ;

    } else {

    mysql_query("UPDATE count SET count = count + 1 WHERE page='$page'"); 

    $result mysql_query("SELECT count FROM count WHERE page='$page'");
    $row mysql_fetch_array($result);  
    $count $row[count]; } 
    hmm...

  3. #3
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    aaaah ****er! ignore that...
    hmm...

  4. #4
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ignore it because it is working now [or not?]
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  5. #5
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah its working now
    hmm...


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
  •