Jump to content


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


  • Please log in to reply
5 replies to this topic

#1 Guest_kilbad_*

Guest_kilbad_*
  • Guests

Posted 04 August 2006 - 09:45 PM

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.freewebma...ials/phpmysql/7

Thank you so much in advance.

Brendan



#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 August 2006 - 09:51 PM

had 2min to spere good luck

<?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);

?>

Hope this helps everyone ok.

<?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}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 10:18 PM

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.

RTFM is an almost extinct art form, it should be subsidized.

#4 Guest_kilbad_*

Guest_kilbad_*
  • Guests

Posted 04 August 2006 - 10:34 PM

thank you, that's just what I needed!

Brendan

#5 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 10:41 PM

What was it you needed, the overview or the specific example?


RTFM is an almost extinct art form, it should be subsidized.

#6 Guest_kilbad_*

Guest_kilbad_*
  • Guests

Posted 04 August 2006 - 10:43 PM

The specific example was the most helpful.  Thanks again!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users