rand3h Posted May 6, 2006 Share Posted May 6, 2006 Hi I created a site and I heard somewhere that creating tables in php is much better than framing in HTML. So, i did exactly that. [a href=\"http://www.rav3online.com/randysocandy/rr/HTML/\" target=\"_blank\"]http://www.rav3online.com/randysocandy/rr/HTML/[/a]thats the beta stage of my site, don't laugh, it's pretty mediocre as I am just learning this. anywho..i've realized that using the php instead of frames is very beneficial when it comes to site changes. This way, I won't have to change EVERY single .php file in order to keep the site maintained. But as I was making the files, I had a index.php attached with a main.php as the main page content. I have a link that leads to the about us page. But hte problem was, when i linked it to the aboutus page, i realized it only linked to that specific file instead of the index + aboutus.php . Is there a way so that I could somehow keep the index.php and add whatever content i need for each link???? I can't seem to figure out how the linking works without having to create two aboutus php files. It's very frustrating =(PLEASE HELP!I'm sorry if my noobiness has confused u. let me know so i can clarify the problem a little more!!p.s. - is there a way that I can somehow automatically feed my sidebar to receive updated news?? I hate the fact that I have to update it every single time. There's gotta be an easier way no?-randy Quote Link to comment https://forums.phpfreaks.com/topic/9180-serious-php-noob-here/ Share on other sites More sharing options...
alpine Posted May 6, 2006 Share Posted May 6, 2006 I suggest switch statement instead of frames, like this[code]<?php// top layout here, or include header fileswitch ($_GET['view']){case 'about':include ("path/about.html");break;case 'news':include ("path/news.php");break;default:include ("path/welcome.php");break;}// footer layout here, or include footer file?>[/code]You see the pattern, if this is called index.php , calling --> index.php?view=about <-- would include about.htmlAs to the news-bar, once you get more familiar with php i suggest mysql database to store news and then get news from the database as many ways as you wish :) Quote Link to comment https://forums.phpfreaks.com/topic/9180-serious-php-noob-here/#findComment-33820 Share on other sites More sharing options...
rand3h Posted May 6, 2006 Author Share Posted May 6, 2006 doesn't that mean i have to add those lines for EVERY link i have to my site??? Quote Link to comment https://forums.phpfreaks.com/topic/9180-serious-php-noob-here/#findComment-33828 Share on other sites More sharing options...
alpine Posted May 6, 2006 Share Posted May 6, 2006 It depends on how your site is build, and if i understand you correctly you currently only have text files. Then the answer is YES if you want to use switch like in my example above.You can do a different twist and include files based on GET variable directly - BUT do it with caution as it is in some cases very vounerable to url injection attacs,example if all your include pages end with .html:[code]$view = htmlspecialchars($_GET['view']);$page = "path/".$view.".html";if(empty($view)){include ("path/welcome.html");}else{if(file_exists($page)){include ($page);}else{print "Page not found";}}[/code]Then call it with --> index.php?view=about <-- that will include --> about.html Quote Link to comment https://forums.phpfreaks.com/topic/9180-serious-php-noob-here/#findComment-33872 Share on other sites More sharing options...
rand3h Posted May 8, 2006 Author Share Posted May 8, 2006 what if they are php files that i would like to put in? does it matter or can i just switch the .html part to .php? Quote Link to comment https://forums.phpfreaks.com/topic/9180-serious-php-noob-here/#findComment-34195 Share on other sites More sharing options...
alpine Posted May 8, 2006 Share Posted May 8, 2006 Yes you can - or you can make it compatible with both by using different GET calls[code]if(!empty($_GET['html'])){$view = htmlspecialchars($_GET['html']);$page = "path/".$view.".html";}elseif(!empty($_GET['php'])){$view = htmlspecialchars($_GET['php']);$page = "path/".$view.".php";}else{$page = "path/welcome.html";}if(file_exists($page)){include ($page);}else{print "Page not found";}[/code]Either call it with --> index.php?html=about <-- that will include --> about.htmlOR call it with --> index.php?php=about <-- that will include --> about.php Quote Link to comment https://forums.phpfreaks.com/topic/9180-serious-php-noob-here/#findComment-34252 Share on other sites More sharing options...
rand3h Posted May 10, 2006 Author Share Posted May 10, 2006 going back to the mysql database for adding news content on my page.. exactly what must i do to do that? I'm just looking to add news from say.. msn or some third party news syndicate but I would prefer to somehow automatically update that portion. Ive seen a few RSS feeds so i was wondering what would be best for my situation.www.rankreview.comthe left side would be my news content part. what do u suggest i do and exactly how would i do it????I'm so lost when it comes to that stuff.Also, i had a question off the topic but I was wondering how [a href=\"http://www.prosportsdaily.com/\" target=\"_blank\"]http://www.prosportsdaily.com/[/a]works. obviously the owner of the site doesn't update all those .htmls daily. I mean.. 20-something teams for a good 5 different sports is impossible. I understand that he made his page look for keywords from certain pages. I could be really off too.. Quote Link to comment https://forums.phpfreaks.com/topic/9180-serious-php-noob-here/#findComment-34925 Share on other sites More sharing options...
haydndup Posted May 10, 2006 Share Posted May 10, 2006 To feed your sidepanel, create your script, save it as something like news.php. Then include it in your main page in the left panel[code]<?phpinclude 'news.php';?>[/code]Just a quick copy, paste and edit of one of my news scripts:[code]<?php//db.inc.phpmysql_connect ("localhost", "username", "password") or die (mysql_error());mysql_select_db("your_db_name_here") or die (mysql_error());?>[/code][code]//news.php<?phpinclude 'db.inc.php';//db username and pass?><p class="heading">News & Announcements</p><?php$result = mysql_query("SELECT * FROM news ORDER BY date DESC") or die (mysql_error());while ($row = mysql_fetch_array($result)) {?><table border="0" cellpadding="0" cellspacing="0"><tr><td><b><?=$row['subject'];?></b></tr><tr><td><?php echo $row['body'];echo "<br>";?><br><br>Posted on <?=$row['date'];?><hr/></td></tr><tr><td></td></tr></table><br><?}?>[/code]The code above will fetch everything from your db, from the table 'news', ordered by the newest date, and loop through echoing the heading, body, and then the date it was posted on.Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/9180-serious-php-noob-here/#findComment-34934 Share on other sites More sharing options...
rand3h Posted May 22, 2006 Author Share Posted May 22, 2006 ok, done that. now how do i feed it to my database. and where do i get the content for it? and are rss involved with this somehow?i'm sorry, im a real mysql nub. Quote Link to comment https://forums.phpfreaks.com/topic/9180-serious-php-noob-here/#findComment-38040 Share on other sites More sharing options...
haydndup Posted May 23, 2006 Share Posted May 23, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]ok, done that. now how do i feed it to my database. and where do i get the content for it? and are rss involved with this somehow?[/quote]What exactly do you mean? RSS is not involved. The script i provided, will connect to the db and retrieve all the info out of it, and then put everything into a table. If you want to add news, you can use something like phpMyAdmin, or alternatively, write your own script that inserts data into the db.hth. Quote Link to comment https://forums.phpfreaks.com/topic/9180-serious-php-noob-here/#findComment-38263 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.