|
-
Dec 1st, 2001, 09:34 PM
#1
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?
-
Dec 3rd, 2001, 12:59 PM
#2
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.
-
Dec 4th, 2001, 08:13 AM
#3
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|