bicho83 Posted March 17, 2007 Share Posted March 17, 2007 First of all, I am a newbie to php (duh!!!!) I am building a website. In the root I have an index.php file. What that file does, it chooses the file that it's going to open. For example if the address is empty (e.g www.website.com), is going to pull the intro.php (where it shows like a general/welcome page). If something else is in the address bar (e.g www.website.com/content_page) is going to pull the content.php page where it would paste the info that is assigned to that address to the content area. I wrote the function in the index.php as follows: <? if ($_REQUEST['module'] == ' ') { include "intro.php"; } else { include "content.php"; } ?> In the content.php page it has the following after the heading, navigations, and all that crap: <?php module() ?> So the assigned URL would get paste in that content area, but I get the following error: Fatal error: Call to undefined function: module() in /url/content.php on line 126 Line 126 is the code that I pasted above which was: <?php module() ?> Now the above is probably true, since the function doesn't have anything inside, it's only declare inside the index.php file and thats it. What would I need to do or write to make it paste the content pages to the content area? Can someone point me to the right direction? Obviously I am missing something. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
bicho83 Posted March 17, 2007 Author Share Posted March 17, 2007 Also, where would I write that module? Index.php I assume. Quote Link to comment Share on other sites More sharing options...
fert Posted March 17, 2007 Share Posted March 17, 2007 unlike C you cannot prototype functions you would need to do this function module() { //do stuff } Quote Link to comment Share on other sites More sharing options...
bicho83 Posted March 17, 2007 Author Share Posted March 17, 2007 Ok, in the //do stuff part, what should I put? I tried return true; Now I don't get any error, but the page wont get paste anywhere. I am getting close ^^ Quote Link to comment Share on other sites More sharing options...
fert Posted March 17, 2007 Share Posted March 17, 2007 Ok, in the //do stuff part, what should I put? whatever you want, I'm not exactly sure what you mean 'get paste anywhere' Quote Link to comment Share on other sites More sharing options...
bicho83 Posted March 17, 2007 Author Share Posted March 17, 2007 To pull all the information that it's located in a whatever.php file when it's clicked. Quote Link to comment Share on other sites More sharing options...
fert Posted March 17, 2007 Share Posted March 17, 2007 oh I see, take a look at the file_get_contents function it'll do what you want. Quote Link to comment Share on other sites More sharing options...
bicho83 Posted March 17, 2007 Author Share Posted March 17, 2007 Ok, that kinda helps. But it's too specific. How do I make it dynamic? I am going to set up all the content pages that way, do I have to write each and every path for all of them?? Quote Link to comment Share on other sites More sharing options...
fert Posted March 17, 2007 Share Posted March 17, 2007 form what I under stand you want index.php?page=page to display a certain page right? Quote Link to comment Share on other sites More sharing options...
bicho83 Posted March 17, 2007 Author Share Posted March 17, 2007 No. I want to set up my page in a way where I only need to paste the necessary information for any content (or link) pages to be called and that information gets into the content area of the website. I don't want to paste the header, navigation links, footers, etc into every single one of the content pages that are in the website. So the content page is setup, and that pulls whatever link the user called into the content area. I just want to set up a normal dynamic site. Like PHP-NUKE in a way, where modules get called and pasted into the content area. I don't want a 90's site where every content page you needed to paste the header, banner, navigation, buttons, footer. And then if you have to make a change to a navigation bar, you have to make changes to EACH and every single content page of that website to keep it consistent. Sorry I am not explaining myself clearly, English is my 2nd language. Quote Link to comment Share on other sites More sharing options...
fert Posted March 17, 2007 Share Posted March 17, 2007 Okay I understand function header() //for the page header { include("header.php"); } function footer() //for the footer { include("footer.php"); } Just repeat that code for the other things you want Quote Link to comment Share on other sites More sharing options...
bicho83 Posted March 17, 2007 Author Share Posted March 17, 2007 Ok, I know how to do it that way. There is another way however. That way is kinda still pasting all the information but referencing in a single line, still dynamic I understand. At my work, they have it so that you only need to paste the content itself to a .php file. There isn't any includes in it at all. The function (only declared) is in the index.php where we have access. Now where it is written, I don't know, and we (designers) can't edit it or see it. The Function probably has an X value, where that value gets the address.php and then pastes that information into the content area. How to do that, is what I want to find out. I can ask them on Monday, I just thought by declaring it was enough (I have little knowledge in programming). Quote Link to comment Share on other sites More sharing options...
shaunrigby Posted March 17, 2007 Share Posted March 17, 2007 <?php //Add this code to your index page if(isset($_REQUEST['pageid'])){ $pageID = addslashes(mysql_escape_string($_REQUEST['pageid'])); loadPageContent($pageID); } else { loadPageContent(9295); } //Add this to a function definition page function loadPageContent($pageID){ mysql_connect($dbAddress,$dbUsername,$dbPassword) or die("Error: " . mysql_error()); mysql_select_db($dbSchema); $contentQuery = mysql_query("SELECT `pagelink` FROM `website_content` WHERE `pageid` = $pageID LIMIT 1") or die("Error: " . mysql_error()); $contentLink = mysql_fetch_array($contentQuery); $returnedPages = mysql_num_rows($contentQuery); if($returnedPages > 0){ if(file_exists("content/" . $contentLink['pagelink'])){ include 'content/' . $contentLink['pagelink']; //$pageContent = file_get_contents("content/" . $contentLink['pagelink']); //print $pageContent; } } else { loadErrorPage(); } } ?> NOTE: DONT FORGET TO INCLUDE YOUR FUNCTIONS PAGE IN YOUR INDEX PAGE Quote Link to comment Share on other sites More sharing options...
bicho83 Posted March 17, 2007 Author Share Posted March 17, 2007 I was serious when I said that I have little knowledge of PHP or programming. That code in the index.php gives me an error in line: loadPageContent(9295); By looking at it, it seems like it has a sql query, I don't have a DB set up or anything. It also seems looking for 9295 since whatever that means inside it doesn't exists. Why is it so hard to implement that? Have anyone here seem pages where in the URL has a ? then the funtion then = 'pagename' like ?page=whatever Where 'page' can be any name given to the function. For example: http://www.showcasehomerealty.com/?pg=sh_featured_properties Quote Link to comment 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.