Jump to content

Archived

This topic is now archived and is closed to further replies.

Guest kilbad

How do I update a specific row in my MySQL db with PHP?

Recommended Posts

Guest kilbad
I have been trying to learn how to use mysql, somewhat successfully, using an online tutorial. However, I cannot figure out how to code a php script that will allow me to update specific rows (based on the ID number) in my mysql db.  Can someone help me out by posting some code to get me started?  I can then probably take it from there, and/or reply if I have further questions.

The tutorial I was using (and step I got stuck on) is located at: http://www.freewebmasterhelp.com/tutorials/phpmysql/7

Thank you so much in advance.

Brendan

Share this post


Link to post
Share on other sites
had 2min to spere good luck

[code]
<?php

$db=mysql_connect("localhost","xxx","xxx");
mysql_select_db("database_name",$db);

$query_update="update xxxxxxxx set hits='xxxx' where xxxx='xxxxxx' ";
$result_query=mysql_query($query_update);

?>
[/code]

Hope this helps everyone ok.
[code]

<?php

Select Statement
SELECT "column_name" FROM "table_name"

Distinct
SELECT DISTINCT "column_name"
FROM "table_name"

Where
SELECT "column_name"
FROM "table_name"
WHERE "condition"

And/Or
SELECT "column_name"
FROM "table_name"
WHERE "simple condition"
{[AND|OR] "simple condition"}+

In
SELECT "column_name"
FROM "table_name"
WHERE "column_name" IN ('value1', 'value2', ...)

Between
SELECT "column_name"
FROM "table_name"
WHERE "column_name" BETWEEN 'value1' AND 'value2'

Like
SELECT "column_name"
FROM "table_name"
WHERE "column_name" LIKE {PATTERN}

Order By
SELECT "column_name"
FROM "table_name"
[WHERE "condition"]
ORDER BY "column_name" [ASC, DESC]

Count
SELECT COUNT("column_name")
FROM "table_name"

Group By
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1"

Having
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1"
HAVING (arithematic function condition)

Create Table Statement
CREATE TABLE "table_name"
("column 1" "data_type_for_column_1",
"column 2" "data_type_for_column_2",
... )

Drop Table Statement
DROP TABLE "table_name"

Truncate Table Statement
TRUNCATE TABLE "table_name"

Insert Into Statement
INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1", "value2", ...)

Update Statement
UPDATE "table_name"
SET "column_1" = [new value]
WHERE {condition}

Delete From Statement
DELETE FROM "table_name"
WHERE {condition}

?>
[/code]

Share this post


Link to post
Share on other sites
Okay, to give you a specific exemple of an update:

UPDATE my_table SET column_a = 'abc' WHERE id = 0

Change column_a to value 'abc' for every row in table my_table where column id contains the value 0.
assuming that column_a is a character type column and column id is a numeric type column.

Share this post


Link to post
Share on other sites
Guest kilbad
thank you, that's just what I needed!

Brendan

Share this post


Link to post
Share on other sites
Guest kilbad
The specific example was the most helpful.  Thanks again!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.