Tutorial?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
3.14
Forum Commoner
Posts: 28
Joined: Mon Sep 08, 2003 12:17 am

Tutorial?

Post by 3.14 »

I'm playing with PHP and MySQL and have learnt some basics, but am looking to increase my knowledge.

I have designed a database in MySQL and want to design the front end with PHP. I want to have a local contact database where on initial load it opens the default record, then with some navigation buttons, the user will be able to go to the next and previous records etc.

Now I can populate tables in a general way and I can specifiy with the sql to only show the first record, but I'm trying to integrate the html and php so that I can have it set out in a way where it has the following structure:

FirstName: Frank LastName: Barns
Telephone: 1234 5678 Etc: etc

So essentially, I want the html to print out the field lables and then get PHP to put the relevant details in the right spots.

Are there any tutorials out there which will guide me a little bit more in this direction? Or can anyone here offer any advice on what path I can take?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

It's usually considered good practice to keep html tags out of php scripts. That keeps the presentation layer separate from the business logic.

Infact "don't mix things up" is a general principle of good program design. Get that tattooed somewhere. Another example would be don't write one big function when you can split it into smaller, sub functions each carrying out a specific task.

Anyway, I'd suggest that you write a script which:

(1) defines the vars: $first_name, $lastName, $telephone, etc.
(2) finishes off by including an html template where the vars are echo'd out

That's the basic plan of every php script which creates a browser page (maybe with some other background functions like a db update etc).

You can create any kind of template layout you like - and edit it in your favourite html editor without touching the script (that's the whole point of separating html & php).

Add <?php echo $first_name; ?> (etc) anywhere you want in the template.
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

have you read the PHP Manual/Documentation at http://www.php.net yet?
also, if you have the money, you can buy a book, i suggest PHP Bible (i read it myself and i learned a lot)
Post Reply