Jump to content

Help with function in index.php


bicho83

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

<?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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.