nickbunyun Posted October 19, 2007 Share Posted October 19, 2007 ok so basically this is the thing i have this page now so far what i usually done is copied and pasted index.php 3 times and changed it to about, contact and news . php and i had my 4 page site. now i wanna make it easier for me when i wanna call for a page to load. i kinda understand the idea if and else.. but what about in the case of clicking the LINKs and than loading it in a different place (maincontent) so thats kinda my question.. any pointers to tutorials, or feel free to explain here thanks in advantage. Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/ Share on other sites More sharing options...
Wes1890 Posted October 19, 2007 Share Posted October 19, 2007 I don't quite understand what you want... Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-372836 Share on other sites More sharing options...
soycharliente Posted October 19, 2007 Share Posted October 19, 2007 Well, you could use 4 different pages? Or look into using the GET method and putting the page into the url. For example, the links would be formatted like this: index.php?pg=about And it would pull the variable and try to load an about.php page with include() or some other function like that. If you do it that way, you need to have some type of check to make sure that the page exists and if not return a 404. That's pretty easy. You would just loop through all the files on that directory level and see if one exists that is called whatever variable you're looking for. Hope that helps. I've done it that way on 2 different sites, as I'm sure many people here have, so if you get stuck just come back and show us what code is giving you the trouble. Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-372837 Share on other sites More sharing options...
trq Posted October 19, 2007 Share Posted October 19, 2007 You have three links and some processing code.... <a href="?page='one'>LINK ONE</a> <a href="?page='two'>LINK TWO</a> <a href="?page='three'>LINK THREE</a> <?php if (isset($_GET['page'])) { switch ($_GET['page']) { case 'one': echo "this is one"; break; case 'two': echo "this is two"; break; case 'three': echo "this is three"; break; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-372838 Share on other sites More sharing options...
peterbarone Posted October 19, 2007 Share Posted October 19, 2007 I'm new also, but I would use CSS first to layout your page make that your template. Then copy the template 3 more times and your on your way. Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-372842 Share on other sites More sharing options...
soycharliente Posted October 19, 2007 Share Posted October 19, 2007 I might modify that to use include() so the code doesn't become crowded. But I like the way you think thorpe <a href="?page='one'>LINK ONE</a> <a href="?page='two'>LINK TWO</a> <a href="?page='three'>LINK THREE</a> <?php if (isset($_GET['page'])) { switch ($_GET['page']) { case 'one': include("one.php"); break; case 'two': include("two.php"); break; case 'three': include("three.php"); break; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-372843 Share on other sites More sharing options...
trq Posted October 19, 2007 Share Posted October 19, 2007 Ah see, if your going to use include you best make sure its safe to include the files. Otherwsie people can do vicious things to your site. You can also get rid of the switch all together. <a href="?page=one">LINK ONE</a> <a href="?page=two">LINK TWO</a> <a href="?page=three">LINK THREE</a> <?php $valid = array('one','two','three'); if (isset($_GET['page'])) { if (in_array($_GET['page'],$valid)) { include $_GET['page'].'.php'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-372846 Share on other sites More sharing options...
nickbunyun Posted October 19, 2007 Author Share Posted October 19, 2007 oh lol wow thats fast responses here http://kurruptsystem.com/media/random/question/ thats what i made up the test.php has the "coding" in it <body> <div align="center" style="padding: 2px;"> <div align="center" style=" width:600px; height:100px; background-color:#999999;">Banner </div> <div align="center" style=" width:600px; height:20px; background-color: #CCCCCC;"> <a href="?page=one">LINK ONE</a> <a href="?page=two">LINK TWO</a> <a href="?page=three">LINK THREE</a> </div> <div align="center" style=" width:600px; height:50px; background-color:#999999;"> <p>Div dedicated to the people that helped me on that thread<br /> Thanks!</p> </div> <div align="center" style=" width:600px; height:auto; background-color: #333333; color:#FFFFFF;"> <?php if (isset($_GET['page'])) { switch ($_GET['page']) { case 'one': include("one.php"); break; case 'two': include("two.php"); break; case 'three': include("three.php"); break; } } ?> </div> </div> </body> and it actually worked.. ok time to try the array thing.. can u define the "people can do things to your site" ? ** edit copied and pasted the array worked nicely.. u guys make php easy.. lol Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-372853 Share on other sites More sharing options...
ptolomea Posted October 19, 2007 Share Posted October 19, 2007 I found a tutorial on this website about doing kinda what you want. but alas i am unable to find said tutorial right now but what it had done was create 1 giant table with the with your design and what you did was look at the table code till you find the section where you want your pages to go, and make this a file called header.php then take the rest of it and call it footer.php. thats what i did. now on my files i just had the top line include 'header.php'; and when the page was done, include footer.php then build your page the way you want. it was something like frames in html. I did notice you have a fix or sorts already but this is something i have done, it was fun Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-372858 Share on other sites More sharing options...
nickbunyun Posted October 19, 2007 Author Share Posted October 19, 2007 yeah well thats how i code my templates banner.php maincontent.php footer.php navigation.php sidecategory1.php etc etc. and than include them in index.php but my question was ( and it was answered) instead of taking index.php and copy paste 3 times and change name (for a 4 page site) to have just one index.php and to change the text needed to be changed by switching just to about.php or w/e and in about.php i can simply have only the text.. no design required. kinda know what i mean now ? Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-372896 Share on other sites More sharing options...
trq Posted October 19, 2007 Share Posted October 19, 2007 To do that you actually need only one page (index.php) and your content is stored within a database. This is the basic principle behind dynamic sites. A quick example (you can build quite alot from here). <?php // build the menu. $sql = "SELECT id,title FROM menu"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { echo "<a href=\"?id={$row['id']}\">{$row['title']}</a><br />"; } } } // check to see if a link was checked, otherwise prepare a default id. if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); } else { $id = 1; } // build query to grab the content for this page. $sql = "SELECT data FROM content WHERE id = '$id' LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo "<p>{$row['data']}</p>"; } } ?> Of course this example is pretty stripped back, but there would be nothing stopping you copying and pasting that code, creating the correct tables / data and using it to dynamically generate a site with 10,000 pages with it. Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-372904 Share on other sites More sharing options...
simcoweb Posted October 19, 2007 Share Posted October 19, 2007 Thorpe, would that then produce something like: index.php index.php?aboutus index.php?blahblah index.php?yadayada Where it's basically dynamically generating the text in the content area depending upon what link is clicked? I've been wanting to learn this method. Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-372978 Share on other sites More sharing options...
trq Posted October 19, 2007 Share Posted October 19, 2007 Something like that. This part.... <?php // build the menu. $sql = "SELECT id,title FROM menu"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { echo "<a href=\"?id={$row['id']}\">{$row['title']}</a><br />"; } } } ?> would generate something like (as an example).... <a href="?id=1">home</a> <a href="?id=2">about</a> <a href="?id=3">something</a> then this part.... <?php // build query to grab the content for this page. $sql = "SELECT data FROM content WHERE id = '$id' LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo "<p>{$row['data']}</p>"; } } ?> if passed an id of 1 would produce the data related home. Of course you could use named id's as in your example and in fact alot of the time this can be better. Using named id's allows you to use mod_rewrite rules which will clean your urls. This really is the basics of how dynamic sites are built. Like I said, even that simple example I posted is capable of producing a site with 10000+ dynamic pages. its limitless really, though the menu would get pretty ugly. Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-373000 Share on other sites More sharing options...
nickbunyun Posted October 19, 2007 Author Share Posted October 19, 2007 alright i kinda understand the code abit.. i have xampp and i made a database.. and managed to connect my menu.php (trying to get a dynamic menu) can u tell me how my table would look i got too many options that i dont know what they mean.. Field Type Length Attributes Null extra comments.. etc. etc. what exactly am i suppose to fill in those... some are drop down menus with.. lots of more options. thanks Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-373432 Share on other sites More sharing options...
igor berger Posted October 19, 2007 Share Posted October 19, 2007 How about use includes so you will have top.php leftmenu.php buttom.php snd main_boddy1.php you can use CSS to do the layout you want. page1.php will be inside this page top.php leftmenu.php buttom.php snd main_boddy1.php page2.php will be inside this top.php leftmenu.php buttom.php snd main_boddy2.php page3.php etc will be inside this top.php leftmenu.php buttom.php snd main_boddy3.php This way everyone of your pages will include the same template, so if you need to change your banner or add new links for your menues you just change it in one inlude page and all other pages will reflect the change. If you wish you can put the pages in a database like thrope suggested. Here is an example of CSS www.phsdl.net The top left menu is the same on every page, right it is not an include, but if you going to build many pages it would be nice to have it as an inlude, so adding one new link will be reflected on all the Web pages. Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-373444 Share on other sites More sharing options...
nickbunyun Posted October 19, 2007 Author Share Posted October 19, 2007 thanks for the input.. but i know how to use include's i've been using include function for a long time.. tho i would want to learn to get it more dynamic using databases.. since later on.. i might wanna learn how to make an easy edit page (CMS) that would edit the tables in the db. i've looked at a couple of CMS tutorials.. but i dont wanna just copy and paste.. i actually wanna learn it. Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-373449 Share on other sites More sharing options...
igor berger Posted October 19, 2007 Share Posted October 19, 2007 IF you make one share the script with us. Sounds like you are on the right track. I have used a nuber of content managment softwaresand they all were badly build. The last one I used I could only link to internel pages in the menu. Also if you can get some XML fancunality into it to move around manuales same as iGoogle homa page that would be very useful for person updating the pages. Good luck Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-373455 Share on other sites More sharing options...
nickbunyun Posted October 19, 2007 Author Share Posted October 19, 2007 yeah lets not jump ahead now.. i dont know what to make in a db with a simple code that was posted here... lol so we got a while to go anyway back on topic.. hows my tables suppose to loook im really lost in there.. Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-373472 Share on other sites More sharing options...
soycharliente Posted October 21, 2007 Share Posted October 21, 2007 Ah see, if your going to use include you best make sure its safe to include the files. Otherwsie people can do vicious things to your site. You can also get rid of the switch all together. But if you're using a switch, you could just include a default to include a 404 error page or something. That way, if it didn't match any of the conditions, it wouldn't include anything. Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-374758 Share on other sites More sharing options...
Ninjakreborn Posted October 21, 2007 Share Posted October 21, 2007 @ charlieholder good point there. Quote Link to comment https://forums.phpfreaks.com/topic/73887-if-clicked-load-this-page-noob-alert/#findComment-374762 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.