Perry| Posted August 15, 2008 Share Posted August 15, 2008 Hello. I am not sure how to store files for my site and then display them. I have installed Smarty on my server for templates. My site is guide based and I want to keep the URL's short and identify them with ?id= (http://www.myurl.com/guide.php?id=1) Those not familiar with Smarty, you create a template (.tpl file) and add areas in the template that you edit in your main file (index.php or whatever) This is what I have in my index.php file currently <?php require 'smartyconfig/libs/Smarty.class.php'; $smarty = new Smarty; $smarty->assign('title','Home'); $smarty->assign('main','THIS IS WHERE MAIN CONTENT WILL GO'); $smarty->display('index.tpl'); ?> So basically anything in 'main' needs to be dynamic. So any ideas on how to achieve this please post them, if you are unsure about anything please ask me! I have subscribed to this topic so I will get back to you within ~20 minutes. Many thanks, Perry Quote Link to comment https://forums.phpfreaks.com/topic/119833-not-sure-how-to-store-files-and-how-to-display-them/ Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 The page content is stored in a database table - correct? You would select the record from your URL id, then pass it to Smarty so: $query = mysql_query("SELECT field FROM table WHERE id='".$_GET['id']."' LIMIT 1"); $result = mysql_fetch_array($query); $smarty->assign('main', $result['field']); Quote Link to comment https://forums.phpfreaks.com/topic/119833-not-sure-how-to-store-files-and-how-to-display-them/#findComment-617407 Share on other sites More sharing options...
Perry| Posted August 15, 2008 Author Share Posted August 15, 2008 The page content is stored in a database table - correct? You would select the record from your URL id, then pass it to Smarty so: $query = mysql_query("SELECT field FROM table WHERE id='".$_GET['id']."' LIMIT 1"); $result = mysql_fetch_array($query); $smarty->assign('main', $result['field']); No it's not that's what I'm asking, where should I store the content? In mySQl? In files? Also the Title needs to be dynamic with the content too. Quote Link to comment https://forums.phpfreaks.com/topic/119833-not-sure-how-to-store-files-and-how-to-display-them/#findComment-617418 Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 Store it wherever you like. In text files is more difficult if the title needs to be extracted as a separate piece of data. In mysql you could have a page content table with fields pageId, title, content Then your page title is sent to the template: $smarty->assign('title', $row['title']); Quote Link to comment https://forums.phpfreaks.com/topic/119833-not-sure-how-to-store-files-and-how-to-display-them/#findComment-617423 Share on other sites More sharing options...
Perry| Posted August 15, 2008 Author Share Posted August 15, 2008 I need to learn about MySQL. Just to clear it up, what would I do with the tables? Create a table then add data for each page of content? Or will I need a table for each page of content? Quote Link to comment https://forums.phpfreaks.com/topic/119833-not-sure-how-to-store-files-and-how-to-display-them/#findComment-617462 Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 No. 1 table. When you stated: want to keep the URL's short and identify them with ?id= (http://www.myurl.com/guide.php?id=1) What was the id supposed to reference in ?id=x In most cases this is the primary key value for the database table you are querying Quote Link to comment https://forums.phpfreaks.com/topic/119833-not-sure-how-to-store-files-and-how-to-display-them/#findComment-617464 Share on other sites More sharing options...
Perry| Posted August 15, 2008 Author Share Posted August 15, 2008 The id is referencing the specific guide. Say I have one guide category then the id is pointing to a specific part of the category (On a new page). Quote Link to comment https://forums.phpfreaks.com/topic/119833-not-sure-how-to-store-files-and-how-to-display-them/#findComment-617468 Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 OK. You need to learn a relational database if you want dynamic capabilities in your website. Quote Link to comment https://forums.phpfreaks.com/topic/119833-not-sure-how-to-store-files-and-how-to-display-them/#findComment-617471 Share on other sites More sharing options...
Perry| Posted August 15, 2008 Author Share Posted August 15, 2008 Where should I start? I don't really like W3Schools, what is an alternative? Quote Link to comment https://forums.phpfreaks.com/topic/119833-not-sure-how-to-store-files-and-how-to-display-them/#findComment-617472 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.