Jump to content

templates system + .htaccess


KYKK

Recommended Posts

so we have the .htaccess which changehttp://kywebsite.co.cc/user/ANYUSERto http://kywebsite.co.cc/user.php?user=ANYUSERAND the templates system make the test.tpl inside template folder to "mix" with php so the HTML can have a theme...but when i go to http://kywebsite.co.cc/user/clanwebsit just showing the HTML not the theme, but the code is fine, the only thing i can think of is <link href="theme/blue/blue.css" rel="stylesheet" type="text/css" media="screen" />would it need to be "relative" to the http://kywebsite.co.cc/user/ANYUSERi think it ../../theme/blue/blue.css ... .. . right?

Link to comment
Share on other sites

yea i was in a hurry want to ask before school so you can reply it ... and yes it work now ....shouldn't post a thread lol.....so i have a css ... and are there a thing that limit how long something is?like i have some links on top of .. http://kywebsite.co.cc/user.php?user=clanwebsand if i put a lot of different links and long link words like home , forum ...then it will go to 2nd row and it will be out of my link background image ... .. .. so are there a thing that limit the length of each link and limit number of links?

Link to comment
Share on other sites

ok then work on my css on that...look at herehttp://kywebsite.co.cc/user.php?user=clanwebsthere are 2 sidebar and 4 header thingy .... let call it sidebar box...different user will have different amount of sidebar boxes and what should i add to the admin codes to allow user to do that?if i add like 10 sidebar boxes to the user table first and if something in it and echo it and if nothing in it then don't show and i will have echo box1 box 2 box 3 box 4 .... box 10 in the php code, but then i need to limit the user to have 10 boxes because if they have 11 i don't have echo box 11 in the php code..so i thinking about when they want a new box create a new field to the user table but then it will add a new field to every user ....( that not a big problem )but how do i echo all sidebar box? and i just want to sidebar box not other fields like user name e-mail....._________________________________advise me:should i create a new table for each user or create a new row in user table for each user? which one better? If create it in user table then i can see all user info like email username .... easily but if i create a new table i can create a new field without add a new field to other user like the sidebar boxes then other user will not have a empty field...

Link to comment
Share on other sites

I'm not able to reach that link so I can't see the actual page, but you'll need to set up the boxes in the tpl file. There are a couple ways to do that, you can either give a certain number of boxes or let there be as many as the PHP page sends. Here's an example where each box is a div with a h2 for the header and some body content with a limited number of boxes:

{*type=if_start box1}<div id="box1">  <h2>{*box1_title}</h2>  {*box1_content}</div>{*type=if_end}{*type=if_start box2}<div id="box2">  <h2>{*box2_title}</h2>  {*box2_content}</div>{*type=if_end}{*type=if_start box3}<div id="box3">  <h2>{*box3_title}</h2>  {*box3_content}</div>{*type=if_end}

On the PHP page, you would do a couple things to get any of those boxes to show up. Each box is surrounded by an if tag, the if_start and if_end. So the first if_start is called box1. In order to get box1 to show up with the title and content, you would set a content variable called box1 to true and assign content variables for the title and body content.

$content['box1'] = true;$content['box1_title'] = 'Box 1';$content['box1_content'] = 'this is the text to show inside box 1';

Since each box has an if around it, it will only show the boxes that you say to in the PHP code.The other way to do it is to use a loop to show however many boxes you send through PHP. The loop that I set up in the template engine is called a dataset. So here's the template tags for a loop to show boxes:

{*type=dataset_start boxes}<div class="box">  <h2>{*type=dataset_item title}</h2>  {*type=dataset_item content}</div>{*type=dataset_end}

To get those to show in PHP, since the dataset_start is called boxes, you need a content variable called boxes that is an array (for the loop). Each element of the array needs to be another array that contains a title and content for the box.

$boxes = array();$newbox = array('title' => 'First box title', 'content' => 'first content');$boxes[] = $newbox;$newbox = array('title' => 'Second box title', 'content' => 'second content');$boxes[] = $newbox;$newbox = array('title' => 'Third box title', 'content' => 'third content');$boxes[] = $newbox;$content['boxes'] = $boxes;

So that creates an array called $boxes, where each item in the array is another array that has a title and content. The entire boxes array is put into the $content['boxes'] variable and sent to the template, and the template engine will loop through that array and spit out the box HTML code for each item in there.There are also some ways with the dataset loop to have it alternate between two HTML blocks (e.g. if you want to show a table where the rows alternate colors), and there's also a way to designate an array item as "selected" and show a third HTML block for the selected item (e.g. a table of users where each row alternates color, and the user that you clicked on is highlighted). That's getting a little more complicated, but mess around with the if statements and dataset stuff and see how that works.For the database, have all your users in the same table. If you want to have custom user fields, have a second table for custom user fields with these columns, for example:user IDfield namefield valueYou would add your user record to your 1 user table, and for each custom field you would add a record to the user fields table. When you need to display the custom user fields you would select records from that table where the user ID is the user you're looking for, and you can display the field name and value for each custom field.

Link to comment
Share on other sites

ook so for the first one{*type=if_start box1}<div id="box1"> <h2>{*box1_title}</h2> {*box1_content}</div>{*type=if_end}that mean if i make 1 box it show 1 box and i make 2 it show 2 ........ that be a long code if i have 100 lol ...I choose the 2nd one :)but in array$boxes = array();$newbox = array('title' => 'First box title', 'content' => 'first content');$boxes[] = $newbox;$newbox = array('title' => 'Second box title', 'content' => 'second content');$boxes[] = $newbox;$newbox = array('title' => 'Third box title', 'content' => 'third content');$boxes[] = $newbox;$content['boxes'] = $boxes;do i need to add 1st 2nd 3rd box title and content myself? ( or add php echo row ) myself? what if i have 4th then i need to add one more $new box right? so i still need to manuel know how many boxes there are or set a limit right?so no way that it can like count how many boxes and echo how many boxes?

Link to comment
Share on other sites

do i need to add 1st 2nd 3rd box title and content myself? ( or add php echo row ) myself? what if i have 4th then i need to add one more $new box right? so i still need to manuel know how many boxes there are or set a limit right?
I was thinking you would use a loop. If you want to display the custom fields, for example, then you would select the custom fields from the database and loop through them, and for each one put an entry in the boxes array. The template will show however many you send to it.
Link to comment
Share on other sites

yea i get it i mean do i need to put$boxes = array();$newbox = array('title' => 'First box title', 'echo $row['content1'];' => 'echo $row['content1'];');$boxes[] = $newbox;$newbox = array('title' => 'Second box title', 'echo $row['content2'];' => 'echo $row['content2'];');$boxes[] = $newbox;$newbox = array('title' => 'Third box title', 'echo $row['content3'];' => 'echo $row['content3'];');$boxes[] = $newbox;$content['boxes'] = $boxes;then do i need to keep putting echo $row['content3 4 5 6 7 8 9 10 11 ... .. . ...'] like that do i need to keep echoing the rows...

Link to comment
Share on other sites

No, I was saying you can use a loop to loop through them all instead of writing each one. Also, you shouldn't write the echo statement in quotes, just write the value you want to display. If you leave it like it is then it would replace the template tag with the text "echo $row['content1'];", it wouldn't use the actual value.

Link to comment
Share on other sites

no i want users to insert data to database then read data to let the user's vistor to see it.... using database... not asking the people to change the file themselves get what i mean? like do this without need to know codes...what i trying to do is i trying to make a website that allow me or others to create a general website on something not just some words but have theme styles... like click a button and it add a new paragraphs, and click other button add a header title..... and like more then one header or a title for few paragraphs.. and i try to learn how to controll all these variables of theme styles..... because there a lot of different variables and knowing how to organize and work it without codes will be my goal for ... idk yet....

Link to comment
Share on other sites

I don't know where that message came from, I understand exactly what you're trying to do. I didn't tell you to ask your users to change any files, I don't know what I said to make you think that. Read through posts 6 and 8 again and if you have any questions about what I said, quote what I said and ask your question.

Link to comment
Share on other sites

Each element of the array needs to be another array that contains a title and content for the box.Post(6)
so a better way to say it is i need more array if i have more boxes ?because
$boxes = array();$newbox = array('title' => 'First box title', 'content' => 'first content');$boxes[] = $newbox;$newbox = array('title' => 'Second box title', 'content' => 'second content');$boxes[] = $newbox;$newbox = array('title' => 'Third box title', 'content' => 'third content');$boxes[] = $newbox;$content['boxes'] = $boxes;
when i put it on my user.php it show First Box title then smaller text first content.... 2nd...3rd,,,but there no array for 4th so I need to add it if i have 4 ?>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<
So that creates an array called $boxes, where each item in the array is another array that has a title and content.
creates array call boxes you mean by adding a new array to the code or some how like create table in database create array ?
Link to comment
Share on other sites

so a better way to say it is i need more array if i have more boxes ?
Pretty much, you need 1 element in the array for each box you want to show. In this code on the template file:
{*type=dataset_start boxes}<div class="box">  <h2>{*type=dataset_item title}</h2>  {*type=dataset_item content}</div>{*type=dataset_end}

That has the dataset_start, and inside that are the dataset_item tags. Each dataset_item corresponds to 1 box you want to show (the title and content in the example are both part of the same dataset_item). So that loop above is sort of similar to this in PHP:foreach ($boxes as $box)It's just going to loop through each item in the boxes array and display the HTML code for each one.But you don't have to put each box in the array yourself. If you have a table in the database for the custom fields to show, where each one has a title and a value or content, you can get that list of fields and build the array of boxes in a loop.

$result = mysql_query("SELECT title, content FROM custom_fields WHERE user='user1'");$boxes = array();while ($row = mysql_fetch_assoc($result)){  $new_box = array('title' => $row['title'], 'content' => $row['content']);  $boxes[] = $new_box;}$content['boxes'] = $boxes;

You can build the array yourself if you want to, there are several ways to build arrays. The only thing that is required is that boxes is an array, it doesn't matter if you build it yourself or build it in a loop.

Link to comment
Share on other sites

I don't know if you've done a lot of work with databases, but the code I posted will get all items from the database and loop through them. This is what the loop does. It gets a set of things, and loops through them, running the same code for each item. If there are 5 items in the database, then the loop will run 5 times and will send 5 boxes to the template.

Link to comment
Share on other sites

$new_box = array('title' => $row['title'], 'content' => $row['content']);

but the code I posted will get all items from the database and loop through them.
ALL that mean all data from title field and content field right?but i having different title let say - welcome to home page, news, calendar I can't put all 3 of those title into 1 title field right? so i need to make title 1 and put home page, title 2 and put news , title 3 for calendar ....and then $new_box = array('title' => $row['title1'], 'content' => $row['content1']); $new_box = array('title' => $row['title2'], 'content' => $row['content2']); $new_box = array('title' => $row['title3'], 'content' => $row['content3']);right?.......how should i explain this.... like can you give a simple example of all codes? what i trying to do is to click a button then it will add a title, then add a button add a content ... and no matter how many time i click it there no limit of 10 title or 20 ...
Link to comment
Share on other sites

Dude, look at this code:

while ($row = mysql_fetch_assoc($result)){  $new_box = array('title' => $row['title'], 'content' => $row['content']);  $boxes[] = $new_box;}

Pay attention to what that says, look at the very first line. The while statement is a loop. Those two lines inside the loop, where it creates the $new_box array and puts it in the $boxes array, are going to get executed for every row that came back from the database. If the $result variable contains 10 records, then $row is going to be set to each of the ten records, one at a time, and the other two lines are going to be executed to save the contents of the current row in $new_box. I'll say this again: if the database contains 10 rows, 1 row for each box to show, then that code is going to set up 10 boxes. It's not going to set up 1 box with 10 things in it, you don't need to put 10 things in 1 row, I don't know where you're getting that stuff from. This is a regular, every-day loop. If there are 10 rows, it's going to loop 10 times, once for each row, and store each row in the boxes array. When the template gets the boxes array, it's going to look inside it and see, hey, there's 10 boxes in there! And print all 10 of them out, each in its own box.I get the feeling that you're just arguing with me and not actually running the code to see if it works or not.

Link to comment
Share on other sites

i not trying to argue with you.... So now that mean i need to have user database and each user have it's table..... i used the register-login-.... thing from your php tips.....now i get what you saying when you add a new title or content you create a row, and the loop will read all the data in the title field...i was like if reading the whole field reading other user data.......now i get what you saying need rows..... okso i start over with my user thingy.... i tried to create a table but I think i run into a problem.....

<?php$con = mysql_connect("localhost","ksclans_user","@@11@@oo");mysql_select_db("ksclans_user");$sql = "CREATE TABLE `person`(`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`email` VARCHAR( 255 ) NOT NULL ,`name` VARCHAR( 255 ) NOT NULL ,`password` VARCHAR( 40 ) NOT NULL)";?>

what is wrong?I should able to just go to the URL and then i should able to see a new table in the user database right?

Link to comment
Share on other sites

You need to use mysql_query to execute the query.I was thinking you would use a second table to hold this info, not the main users table. The users table will hold the user accounts, but if a user can have a variable number of these boxes show up, then the boxes should go in a separate table. That's what I was talking about here:

For the database, have all your users in the same table. If you want to have custom user fields, have a second table for custom user fields with these columns, for example:user IDfield namefield valueYou would add your user record to your 1 user table, and for each custom field you would add a record to the user fields table. When you need to display the custom user fields you would select records from that table where the user ID is the user you're looking for, and you can display the field name and value for each custom field.
So you would have a second table with fields for user ID, title, and content. The user ID field is so that you can select the boxes for just the one user you're looking for. So you might have records like this in the table:
user_id	 title			 content---------------------------------------------------1		   Box 1 title	   Box 1 content1		   Box 2 title	   Box 2 content1		   Box 3 title	   Box 3 content1		   Box 4 title	   Box 4 content1		   Box 5 title	   Box 5 content1		   Box 6 title	   Box 6 content

So you would use the code above to get the records out of that table and set up the boxes array for the user with ID 1.

$result = mysql_query("SELECT title, content FROM custom_fields WHERE user_id=1");$boxes = array();while ($row = mysql_fetch_assoc($result)){  $new_box = array('title' => $row['title'], 'content' => $row['content']);  $boxes[] = $new_box;}$content['boxes'] = $boxes;

After you do that, $content['boxes'] will contain an array of the 6 records with the title and content for each one, and the template will display 6 boxes with the corresponding titles and content.

Link to comment
Share on other sites

I know you're not spamming or trying to argue, I'm just getting frustrated when I try to explain something but you're not understanding. It seems like for a while you were asking a question, and I'd explain how to do it, and you'd say no that's not what you want, and then ask the exact same question again. You really have to start just using this in order to understand how it works probably.

Link to comment
Share on other sites

I improve my english a lot better then when i start this website thingy look like i need to keep improving lol....i didn't know you post reply on my morning also... i have no school today....anyway..so since need different table for different user i have

mysql_select_db("ksclans_user", $con);$sql = "CREATE TABLE $name(FirstName varchar(15),LastName varchar(15),Age int)";// Execute querymysql_query($sql,$con);      db_query("INSERT INTO $name (email, name, password) VALUES ('{$email}', '{$name}', '{$password}')");      db_query("INSERT INTO users (email, name, password) VALUES ('{$email}', '{$name}', '{$password}')");

and you can see i have db_query("INSERT INTO $name (email, name, password) VALUES ('{$email}', '{$name}', '{$password}')");i can see the table in database but i don't see the data go into the new table.. do it need like if create table successful, insert into $name or something? even i put

if (mysql_query("CREATE table $name",$con))  {  echo "Database created";  db_query("INSERT INTO $name (email, name, password) VALUES ('{$email}', '{$name}', '{$password}')");  }

it don't work still

Link to comment
Share on other sites

i look at my user.php and what this$content = array('page_title' => 'theme',);what that for?PROBLEM!You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE name='clanwebs'' at line 1the code is mysql_query("INSERT content SET h1title='{$h1title}'WHERE name='{$_SESSION[user_name]}'") and the session user_name is clanwebs it show as line 1 and the WHERE name="clanwebs" will only show on every INSERT or update "script"and the whole code is

<?phpsession_start();require_once 'db.php';$name = $row['name'];$post = $_POST['post'];$h1title = $_POST['h1title'];$h2title = $_POST['h2title'];$h3title = $_POST['h3title'];$byline = $_POST['byline'];$entry = $_POST['entry'];$blockquote = $_POST['blockquote'];if ($_POST['post'] != ''){     mysql_query("INSERT content SET name='{$name}'") or exit(mysql_error());}if (isset($_SESSION['user_id'])){	if ($_POST['post'] == '')	{	echo "there nothing in post box<br>";	}	else	{	mysql_query("INSERT content SET post='{$post}'WHERE name='{$_SESSION[user_name]}'") or exit(mysql_error());	}if ($_POST['h1title'] == ''){echo "there nothing in h1title box<br>";}else{mysql_query("INSERT content SET h1title='{$h1title}'WHERE name='{$_SESSION[user_name]}'") or exit(mysql_error());}	if ($_POST['h2title'] == '')	{	echo "there nothing in h2title box<br>";	}	else	{	mysql_query("INSERT content SET h2title='{$h2title}'WHERE name='{$_SESSION[user_name]}'") or exit(mysql_error());	}if ($_POST['h3title'] == ''){echo "there nothing in h3title box<br>";}else{mysql_query("INSERT content SET h3title='{$h3title}'WHERE name='{$_SESSION[user_name]}'") or exit(mysql_error());}	if ($_POST['byline'] == '')	{	echo "there nothing in byline box<br>";	}	else	{	mysql_query("INSERT content SET byline='{$byline}'WHERE name='{$_SESSION[user_name]}'") or exit(mysql_error());	}if ($_POST['entry'] == ''){echo "there nothing in entry box<br>";}else{mysql_query("INSERT content SET entry='{$entry}'WHERE name='{$_SESSION[user_name]}'") or exit(mysql_error());}	if ($_POST['blockquote'] == '')	{	echo "there nothing in blockquote box<br>";	}	else	{	mysql_query("INSERT content SET blockquote='{$blockquote}'WHERE name='{$_SESSION[user_name]}'") or exit(mysql_error());	} 	?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>  <head>    <title></title>  </head>  <body><?php echo $name;?>    <?php    ?>        Hello, <?php echo $_SESSION['user_name']; ?>,        <p>start row</p><?php$sql = "SELECT * FROM `users` WHERE `name` = '{$_SESSION['user_name']}'";$result = mysql_query($sql);while($row = mysql_fetch_array($result)){echo $row['webtitle<br>'];echo $row['name<br>'];echo $row['themecontent<br>'];}?><p>end row</p>              <form action="content.php" method="post">    <input type="hidden" name="page_mode" value="">    <div class="left_box">Post</div>    <div class="right_box"><input type="text" name="post" size="30" maxlength="255" value="post"></div>        <div class="left_box">h1title</div>    <div class="right_box"><input type="text" name="h1title" size="30" maxlength="255" value="h1title"></div>        <div class="left_box">h2titleE</div>    <div class="right_box"><input type="text" name="h2title" size="30" maxlength="255" value="h2title"></div>        <div class="left_box">h3title</div>    <div class="right_box"><input type="text" name="h3title" size="30" maxlength="255" value="h3title"></div>        <div class="left_box">byline</div>    <div class="right_box"><input type="text" name="byline" size="30" maxlength="255" value="byline"></div>        <div class="left_box">entry</div>    <div class="right_box"><input type="text" name="entry" size="30" maxlength="255" value="entry"></div>            <div class="left_box">blockquote</div>    <div class="right_box"><input type="text" name="blockquote" size="30" maxlength="255" value="blockquote"></div>        <div class="left_box"> </div>    <div class="right_box"><input type="submit" value="update" size="30"></div>    <br><br>    <a href="logout.php">Log out</a>    <?php    }    else    {    ?>    Click <a href="register.php">here</a> to register or click <a href="login.php">here</a> to log in.    <?php    }    ?>  </body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...