meandeviation.com > learn php > design generated pages ... (1)

how to design generated pages (1)
simple substitution

Web forms can easily be designed using Dreamweaver or any other opage design tool. However, the pages generated by PHP scripts may seem more difficult - do you have to code it all in raw HTML?

In fact, you can still do most of the work in something like Dreamweaver and then edit the resulting HTML file to make the PHP script. here is how.

First of all imagine some sample data (e.g. for personal details data may have name="Alan Dix", title="Prof", url="http://www.hcibook.com/alan/"). Now design using Dreamweaver the way uou would like the page to look:

This is the HTML that Dreamweaver generated for the above:.

<head>
<title>personal details - Alan Dix</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1>Contact details</h1>
<p><font size="+1">Prof <a href="http://www.hcibook.com/alan/">Alan Dix</a></font><br>
</p>
<p>... lots more info ...</p>
<p>&nbsp;</p>
</body>
</html>

Save this file and then copy it and change the extension at the end to ".php".

Look through the HTML for the places where there is infornmation that should change depending on the actual data (highlighted):

<head>
<title>personal details - Alan Dix</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1>Contact details</h1>
<p><font size="+1">Prof <a href="http://www.hcibook.com/alan/">Alan Dix</a></font><br>
</p>
<p>... lots more info ...</p>
<p>&nbsp;</p>
</body>
</html>

Now for each of these simply replace the text with the PHP script <? php echo $varname; ?> (where '$varname' is the appropriate field name):

<head>
<title>personal details - <?php echo $name; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1>Contact details</h1>
<p><font size="+1"><?php echo $title; ?> <a href="<?php echo $url; ?>"><?php echo $name; ?></a></font><br>
</p>
<p>... lots more info ...</p>
<p>&nbsp;</p>
</body>
</html>

That is it!!

If the data has just come from a web form or a URL with a query string (e.g. abc.php?name=Alan+Dix&title=...), we can define the variables by preceeding the above by some PHP code:

<?php
$name = $_GET['name'];
$title = $_GET['title'];
$url = $_GET['url'];
?>

 

If the code was being run as the result of a web form with the 'post' method rather than 'get' method, then $_POST would have to be substituted for $_GET ... and if it is coming from a data base then you will also need to add a bit more code to actually read the data from the database (see later).


http://www.meandeviation.com/tutorials/learnphp/howto-design-gen.html Alan Dix © 2002