Friday 23 April 2010

Setting an MySQL table value to NULL using WHERE condition

To set an individual entry to NULL:

UPDATE tablename SET columnname = NULL WHERE condition;

So, referring to our Car/Driver table again - http://creating-websites-with-php-and-mysql.blogspot.com/2010/04/updating-mysql-table-row-entry.html

Let's set the Fiesta to have no Driver assigned:

UPDATE DriverTable SET Driver = NULL WHERE Car = 'Fiesta';

Creating the Primary Key on an already existing MySQL Table

ALTER TABLE tablename ADD PRIMARY KEY (columnname);

So referring back to our little table on :-
http://creating-websites-with-php-and-mysql.blogspot.com/2010/04/updating-mysql-table-row-entry.html

If we want to make the Car column the primary key we'd use:

ALTER TABLE DriverTable ADD PRIMARY KEY (Car);

Updating an MySQL table row entry with condition WHERE

To update a single entry of an MySQL table use:


UPDATE tablename SET columnname = 'NewValue' WHERE condition;

For example on this table called "DriverTable"

|  Car     |  Driver    |
|--------|-----------|
| Fiesta   |  Kev       |
| Escort  |  Tim        |
| Vectra  |  Stu        |

To update the driver of the Escort to Fred we'd use:

UPDATE DriverTable SET Driver = 'Fred' WHERE Car = 'Escort';

Sunday 18 April 2010

Learn with me as I Learn to create Websites with PHP & MYSQL

Hi and welcome to my blog.

I've always been keen to learn how to create good and clever websites and have recently gone down the route of learning PHP (version 5), also using this together with MYSQL.

This seems to be a very common method of creating websites, infact many big name websites such as Yahoo use PHP! As do many other search engines.

i'm a complete novice with this and will be running my websites on a basic Server 2008 R2 server at home and i use 123-reg (see links) for my domain names. (Which are very cheap and just point to my home server).

I've created this blog to share with other "noob" website creators out there like myself, also as a method of helping me to remember and understand the commands. So please join me, on this PHP/MYSQL journey!

I'd love to hear from anyone who has also been learning PHP and/or MYSQL and lets share in our sites too!
More brains working together = more ideas and better websites!

But before i start, i must mention the most excellent websites - http://www.phpfreaks.com/ This site (forum) is just an excellent source of help and coding ideas. I've made a couple of posts to help with with my sites and i've had almost instant replies from some helpful (and clever!) people. I definitely recommend joining this site and using the forums.

Lets go....