Log in

View Full Version : PHP Navigation



Titan85
01-05-2007, 09:16 PM
I am trying to make a navigation script that will take me to a page named jobs.php and then on that page display another PHP navigation menu just for that page. I got that much working, but when I click a link on the jobs page, it does not include that page but simply dislpays that pages code. I am using this as my main navigation:
<?php
switch($_GET["page"]) {

default: // Initial case
require('cpanel_home.php');
break;

case "content": // Content case
require('edit_content.php');
break;

case "jobs": // Jobs case
require('jobs.php');
break;

case "create_pages": // Create pages case
require('create_pages.php');
break;

case "statistics": // Statistics case
require('statistics.php');
break;

case "themes": // Themes case
require('themes.php');
break;

case "mail": // Mail case
require('mail.php');
break;

}
?>And this as my job navigation:
<?php
switch($_GET["action"]) {

default: //Original case
require('job_manager/default.php');
break;


case "search": //Search case
require('job_manager/search.php');
break;


case "add": //Add case
require('job_manager/add.php');
break;


case "update": //Update case
require('job_manager/update.php');
break;


case "view_all": //View all case
require('job_manager/view_all.php');
break;


case "delete": //Delete case
require('job_manager/delete.php');
break;

}
?>The code for the jobs page is:

<ul>
<li><a href="jobs.php">Main</a></li>
<li><a href="jobs.php?action=search">Search Jobs</a></li>
<li><a href="jobs.php?action=add">Add Job</a></li>
<li><a href="jobs.php?action=update">Update Jobs</a></li>
<li><a href="jobs.php?action=view_all">View All</a></li>
<li><a href="jobs.php?action=delete">Delete Jobs</a></li>
</ul>

<?php
require('job_nav.php');
?>

</body>
</html>Is there a reason that it does not simply include the page in my code, but rather takes me to that page?

Titan85
01-07-2007, 05:27 AM
Anyone have an idea?

djr33
01-07-2007, 07:24 AM
Please link as I am not sure what you mean.

The code looks fine to me, though.

require just takes ALL of the html and puts that into your page. Perhaps you need to make those other pages not full html documents, but rather, chunks, like removing the <html><body>.... tags, etc.

Titan85
01-07-2007, 02:47 PM
The link to where I get this "error" is http://www.echo-designes.com/testing/cms/cpanel.php?page=jobs . If you click on one of the links on that page, it opens that page, instead of including it. Hope this will help you find a solution ;)

NineTwoZero
01-07-2007, 04:06 PM
at first glance, there seems to be sumthin wrong in ur phpfiles.

Fatal error: Call to undefined function: clean() in /home/bntqann/public_html/testing/cms/job_manager/search.php on line 9
well I might just be stating the obvious.

Warning: mysql_query(): Access denied for user 'nobody'@'localhost' (using password: NO) in /home/bntqann/public_html/testing/cms/job_manager/view_all.php on line 2

Warning: mysql_query(): A link to the server could not be established in /home/bntqann/public_html/testing/cms/job_manager/view_all.php on line 2

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bntqann/public_html/testing/cms/job_manager/view_all.php on line 3
my conclusion: i dont know anything about php :(

sry man. hope sum1 else figures it out :)

djr33
01-07-2007, 09:45 PM
You do realize the difference between including and going to, correct?
There is no forwarding enabled there. It seems to just be including the code onto your page, which, effectively, is just displaying the other page.

Titan85
01-07-2007, 11:57 PM
You do realize the difference between including and going to, correct?
There is no forwarding enabled there. It seems to just be including the code onto your page, which, effectively, is just displaying the other page.Yeah, I want it to include the other page in the code of the page that is currently being displayed. Is there a way that I can make it do so?

djr33
01-08-2007, 12:06 AM
It should be.

Hmm.... have you looked at the source code to see if it's outputting the 'right' html, but then the html isn't displaying how you want?


EDIT: Ok, I get it.

Your PHP isn't in the right spot.

You need to place your PHP within the html, so it outputs the html of the other page at the right point.

If you look at the source, you'll see the source of the required/included page, then, following that, the source of the main page.

Titan85
01-08-2007, 12:12 AM
It is outputting the html that I want it to, but it is not including it in the page, but rather just displaying that code.

djr33
01-08-2007, 12:22 AM
Yes, exactly.

include() and require() do exactly this:
they take all of the html from a document AS-IS, then place that html into the html of your current document at the point at which they are called.

mburt
01-08-2007, 12:27 AM
So what's the difference in that and

echo file_get_contents('filename.htm');
?

Titan85
01-08-2007, 12:44 AM
Is my placing wrong? I put the require in the body section of the page I want it displayed on. I think the issue is that I am trying to do that 2 times, once to display the job page in the Page of the CMS and another time to include the pages that the job page navigation is calling. Could that be a problem?

djr33
01-08-2007, 12:49 AM
I don't think that using the function twice would be an issue.

using the variation of require_once(); would be, but only if you are doing so to the same file (since that's the point of the _once, where it just includes/requires that page one time)

mburt, there is no difference.
However, require and include also include the php. on a remote server, it just grabs the text and outputs, but one your server, it evaluates the code as part of the document.

like:

<?php

require('test.php');

echo $var;

?>

And if test.php was:

<?php
$var='test';
?>

Then the main page would output 'test'.

However, that's not relavant here, I don't think.

If the php on the included page shouldn't be parsed (as it won't be with .htm extensions, unless they're set to be parsed on the server configuration), then it won't be any different from file_get_contents, echo...

Titan85
01-08-2007, 02:11 AM
Thanks for the help, I guess I will have to look through the code and search for the problem, it probably something simple I missed ;)