Forum Moderators: coopster

Message Too Old, No Replies

Need help with setting up a template based website...

         

Nu1

9:18 pm on May 19, 2003 (gmt 0)

10+ Year Member



Hello folks,

I building an information portal where I will be implementing a template system. The goal will be
to customize the page for the user's city.

Upon arrival the user will be welcomed by a page
asking them to choose a city. Once they've chosen
a city, the script will go to MySQL db and look
for all the content pertaining to that city.

Does anyone know how I can accomplish this. If any
knows of a tutorial, I would appreciate it very
much as I am really working with a deadline. :)

MySQL tables include:

city
events
top 5 events
ad banner rotation
city weather

Below is the template that I will be working with. I found this on the web on a tutorial.
===========================================================
First, let us understand the varibles in both the main .html page, and in the php scripts.
In this example <% main %> is the varible used in the main HTML template.

Next, the varibles in the index.php file are as follows:

$main
$content
$fd
$filename
$template
$action
The functions and commands within the index.php are as follows:

function template();
function home();
fopen
fclose
global
stripslashes
eregi_replace
echo
switch
default:
break:
This type of scripting will make outputed varible $main match up with HTML <% main %>. The result is that you can output just about anything within a template.

Now, create three files (named below).

Filename: theme.htm

<html><body>
<table cellpadding="0" spacepadding="0" border="0">
<tr><td valign=top align=left>
<% main %>
</td></tr>
</table>
</body>
</html>

Filename: index.php

<?
function template($content) {
global $main;
$filename = "theme.htm";

if(!$fd = fopen($filename, "r")) {
$error = 1;
}
else {
$template = fread ($fd, filesize ($filename));
fclose ($fd);
$template = stripslashes($template);
$template = eregi_replace("<% main %>", "$main", $template);
$template = eregi_replace("<% content %>", "$content", $template);
echo "$template";
} }

function home() {
global $main;
include ("test.php");
template("$data");
}

switch($action) {
default: // default switch
home();
break;
}
?>

Filename: test.php

<?
$main .= 'This is a test of the emergency boradcast system.<br>This is only a test';
?>

Notice the test.php file having the $main .=. This would be normally an echo command, but echo is not longer needed, since it would not stream through the index.php in the <% main %> area of the template HTML file.

jatar_k

1:38 am on May 21, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hey Nu1, sorry this seemed to have slipped by everyone.

How far have you gotten with this? Is there a specific part of the code which is giving you a problem?

As far as the landing page goes you could use a small form with a drop down containing all of the cities then post that info to the next page (or itself for that matter).

You could take at the $_POST [php.net] superglobal array.

There are also a host of MySQL Functions [php.net] available as well.

Nu1

4:26 pm on May 21, 2003 (gmt 0)

10+ Year Member



Hey Jatar_k,

I have actually not gotten very far. You see I am very new to php and mysql and though I do know how to tweak code, I do not know how to create my own. :)

So basically what I am trying to do is have the user arrive at a splash page that will contain a pull down menu of cities.

Once a city is picked, a script will then pull the template, which will also pull the tables from MySQL tables which contain everything about the corresponding city.

Does that make sense?

Thanks!

jatar_k

4:32 pm on May 21, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



yes it does.

The links that i posted above should give you an idea of how it all works.

MySQL steps

connect to mysql
select db
build query
execute query
retrieve rows from query
output/sort/whatever

those are the basic steps
here is a code example

$connection = mysql_connect ($dbhost, $dbauser, $dbapass);
mysql_select_db ($dbname);
$sdq = "select * from tablename";
$singledataquery = mysql_query($sdq);
while ($sdrow = mysql_fetch_array($singledataquery)) {
echo "<p>",$sdrow[0];
echo "<p>",$sdrow[1];
}

all of the functions above are available through the MySQL Functions link above

Nu1

4:57 pm on May 21, 2003 (gmt 0)

10+ Year Member



Thanks dude!

How do I include and ensure that the table data that corresponds with the city requested goes into the exact part of the template.

For example on the every page I want to pull the city name and print it on the top table of every page in a designated area of the design of the html table on the template.

Thanks again!

jatar_k

5:12 pm on May 21, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



in the while loop instead of echo'ing values you can assign them to the proper variable names and then when the template echos them they will have the proper values.