Page 1 of 2

Question regarding and include() functions and commands

Posted: Wed Aug 15, 2007 12:14 pm
by Parallax
Hi,

I've run into some trouble while developing a site for a friend of mine.

He plans to present his gallery of antiques to people at an expo, and he needs a web site up and running in a few days form now.

I have made a template and several otherpages that could be changed on the same php file using the

switch ($_GET[blah]) and include() functions.

I don't have problem when clicking on links of static/html based pages, but have an issue when I click on links that that include dynamic php files that require a "?comand_line".

When I click on link that includes a php file. It's fine...but when I click on imges and links in the gallery that have included, it just returns to the front page. Abvioulsy It donesn't accept the commands for the php file that I've included.

here's my site I'm working on (for now, all of the links on the top are the some. they all include the gallery. After you click on one of those links, then try clicking the ones that appear on the left side of the screen. Those are the ones I'm trying to get to work.):
http://frickenawesome.org/demo_1

here's the main peice of code I use in my index.php page:

Code: Select all

<table class="main" width="100%" height="573" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td class="banner" width="100%" height="115" valign="top">
		<a href="?p=home">home page</a> | <a href="?p=about">info</a></td>
	</tr>
	<tr>
		<td class="links" width="100%" height="25">
		<a href="?p=products">Antiques</a>&nbsp | &nbsp<a href="?p=products">Aubussons</a>&nbsp | &nbsp<a href="?p=products">Tapestries</a>&nbsp | &nbsp<a href="?p=products">Savonneries</a>&nbsp | &nbsp<a href="?p=products">Textiles</a></td>
	</tr>
	<tr>
		<td class="content" width="100%"  height="100%" valign="top">
<?php
switch ($_GET[p]){ 

     case "home": 
          include 'home.inc'; 
     break; 

     case "products": 
          include 'gallery/gallery.php';                      
     break; 
     
     case "about": 
          include 'about.inc'; 
     break; 
     
     case "history": 
          include 'history.inc'; 
     break;
     
     case "services": 
          include 'services.inc'; 
     break;
     
     case "exh": 
          include 'exhabitions.inc'; 
     break;
     
     case "contact": 
          include 'contacts.inc'; 
     break;

     default: 
          include 'home.inc'; 
     }
?>
		</td>
	</tr>
	<tr>
		<td class="footer" width="100%" height="25">
		<a href="?p=home">Home</a>&nbsp | &nbsp<a href="?p=history">History</a>&nbsp | &nbsp<a href="?p=services">Services</a>&nbsp | &nbsp<a href="?p=exh">Exhabitions</a>&nbsp | &nbsp<a href="?p=contact">Contacts</a>
		</td>
	</tr>
-Mike

Posted: Wed Aug 15, 2007 12:46 pm
by miro_igov
You forget to add the ?p= on these links.

On http://www.frickenawesome.org/demo_1/in ... p=products you have this link:

http://www.frickenawesome.org/demo_1/in ... m=Textiles

But it MUST be http://www.frickenawesome.org/demo_1/in ... m=Textiles

I believe you mixed up the p and page variables.

Posted: Wed Aug 15, 2007 12:49 pm
by Parallax
na, I did that on purpose to not confuse them apart.

the gallery.php has a get function that looks like this: $_GET[page]

Posted: Wed Aug 15, 2007 12:52 pm
by miro_igov
Anyways you do not pass the p=pagename pair to your links which makes the switch at http://www.frickenawesome.org/demo_1/in ... m=Textiles to enter the default: condition where home.inc is included and this gives answer why you always get the home page.

Understand?

Posted: Wed Aug 15, 2007 12:59 pm
by Parallax
The thing is I didn't create the links with the "?page=pagename"....That was all part of a seperate php script I download. The only ones that I've made were the "?p=pagename" links on the top and bottom headers.
I'm trying to intergate two different pages together.

And yes..I'm aware of why it retures to the main page..the problem is that the links on the gallery don't work

Posted: Wed Aug 15, 2007 1:07 pm
by miro_igov
Omg, hopeless. Why the links in gallery do not work?

Because they do not have the p=$_GET['p'].

How to add this? By editing the code where the links are displayed and add p=$_GET['p'] or p=<?php echo $_GET['p'] ?> or p='.$_GET['p'].' or whatever the structure of your link displaying script is.

But i told you in my first post. Can you not understand it?

Posted: Wed Aug 15, 2007 1:07 pm
by superdezign
Parallax wrote:And yes..I'm aware of why it retures to the main page..the problem is that the links on the gallery don't work
And know why they don't work? Because it keeps going back to the front page. Your question has already been answered, so make the fix.

Your code looks for $_GET[p] (which *SHOULD* be $_GET['p'], or better yet: isset($_GET['p']) ? $_GET['p'] : ''.... You should really develop with error reporting turned on), and without it, it goes to the default. Plain and simple.

Posted: Wed Aug 15, 2007 1:25 pm
by Parallax
I think i get what your saying;

That when my links start with ?page=something it looks for swiches that start with ?p=something. Seeing that it donsen't start with ?p=something it reverts to the default. But before I posted on here. The first code had: switch ($_GET[page]) and all of my links had ?page=something, but still had the some problem. Oh, and I'm really unfamiliar with all the php functions. This is like the second php script I've made.

Posted: Wed Aug 15, 2007 2:34 pm
by miro_igov
You can hire someone to do it for you or you can ask us any specific questions.

Posted: Wed Aug 15, 2007 3:03 pm
by Parallax
Is there any way I could not have ?page=&sort=&perPage=&album=Textiles not conflict with default: inlcude "home.inc";?


I almost got it to work when I added another switch ($_get['page']) { default: include "gallery/gallery.php";} at the bottom, but I was able get the links to work :) but was unable to get rid of the main page graphic at the top, because it the top swithch was false and reaverted back the the home page.

Posted: Wed Aug 15, 2007 3:08 pm
by miro_igov
Yes, remove the default: section

Posted: Wed Aug 15, 2007 3:52 pm
by superdezign
Just add the 'p=pageName' to the URLs.

I'm not sure if you're understanding the way GET requests work, but everything in the query string of a URL becomes a part of the $_GET array. All you have to do is add it to the query string of the URLs, and everything would be fixed.

Posted: Wed Aug 15, 2007 4:39 pm
by Parallax
could you give me an example of what you meen add them to the URLs?

Posted: Wed Aug 15, 2007 4:46 pm
by Parallax
To make the question more clear. How bout- What urls are you refering to?

Posted: Wed Aug 15, 2007 5:03 pm
by superdezign
Parallax wrote:To make the question more clear. How bout- What urls are you refering to?
ALL of them. 'p' determines the page, so EVERY URL must have it, or you'll default to the front page.

Code: Select all

<a href="path/to/whatever.php?p=<?php echo $_GET['p']; ?>&page=foo&sort=bar...">Link</a>
You should really take the time to understand what you are doing before doing it.