Results 1 to 3 of 3

Thread: PHP & MySQL - Inserting??

  1. #1
    Cheeko
    Guest

    PHP & MySQL - Inserting??

    Hi,

    Can someone give me a small example how to edit a row with an id number of say 8 and add one to a field called views?

    Code:
    $res = mysql_db_query ("dammitu_music","insert into 'm_rev' ('views') Values('".$row["views"] + 1."') where id='$id'");
    This causes a parse error

    Why?

  2. #2
    scoutt
    Guest
    try this

    PHP Code:
     $sql "select * from $table where id = '$id' ";
           
    $result_check mysql_query ($sql);
             while (
    $row mysql_fetch_array($result_check))
            {
             
    $views$row["views"];
             
            }
    $views $views 1;
    $sql_update update $table set views $views where id='$id'");

    $result = mysql_query ($sql_update); 
    something like that should work beter for ya.

  3. #3
    Member
    Join Date
    May 2001
    Location
    Adelaide, Australia
    Posts
    51
    PHP Code:
    $sql "UPDATE $table SET views = views + 1 WHERE id = '$id'";
    mysql_query ($sql);
    if (
    mysql_errno () > 0) {
       
    $sql "INSERT INTO $table (id, views) VALUES ('$id', 1)";
       
    mysql_query ($sql);

    That should work, and only one query.

    EDIT: Only one query, unless the counter isn't already in the DB.
    Last edited by Matthew Draper; Dec 4th, 2001 at 09:10 PM.
    Matthew Draper
    [email protected]

    "Genius may have its limitations, but stupidity is not thus handicapped." - Elbert Hubbard

    "I like long walks, especially when they are taken by people who annoy me." - Noel Coward

Posting Permissions

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



Click Here to Expand Forum to Full Width