Link to home
Start Free TrialLog in
Avatar of google_girl
google_girlFlag for United States of America

asked on

PHP MySQL site with one page changing content area depending on variable?

If I knew what this was called, I could ask the question properly, but I don't. This site has one page, and this is the PHP (along with other various includes and library files not listed) part I don't get
$catId  = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0;
$pdId   = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0;
and then where the content changes it has this
if ($pdId) {
      require_once 'include/productDetail.php';
} else if ($catId < '20' && $catId > '0') {
      require_once 'include/categoryList.php';
} else if ($catId) {
      require_once 'include/productList.php';
Which I am guessing changes the content depending on which function was invoked and then replaces the content area contents.
I want to integrate a search feature and it's not the search part that is stumping me, it's how to get it to display like the rest of the dynamic content (in that one area).  This is older code and all my books don't use this technique and are all PHP 5.  Well, that's my excuse. ;)
I am thinking I should have my form in the sidebar with the shopping cart (I will add it to the include file that makes up the sidebar), and it's processor in one seperate library file, then the formatting of the results in an include file?  I know I need to figure out what variable I should be using in the first pattern - $searchId maybe?  then that one lowercase letter?  yikes, what is that?  then write my else if part to include the search content should it be requested.  Oh yeah, and make sure I include the form processor in the require_once section that I didn't listin the code here.
 I don't think I understand how the variables are getting from the processor then back to the page to be displayed.  If this is not enough code, I'll post what ever you need.
Avatar of grendel777
grendel777
Flag of United States of America image

Hi google_girl, I hate it when other people do this, but take a look at:
https://www.experts-exchange.com/questions/21015897/How-can-I-pass-variable-from-one-page-to-another-page.html?anchorAnswerId=11249094#a11249094

It has a healthy discussion about passing variables from one page to another in PHP, and just copying it and pasting it here feels like cheating.  Basically, if you have the variable set up in a Form on the first page, it's automatically passed to the next page when the Submit button is pressed.

You can also embed the variables in the URL:  <a href="search.php?searchidurl=12345>Item 12345</a>

Then in search.php, set up a php variable to retrieve the variable in the URL:
$searchid = $_GET['searchidurl'];

If you are using sessions, you can create your own session variables which are stored on the server until you need them.

Hope that gets you started, at least enough to search for more info!
-Russell
Avatar of google_girl

ASKER

Okay, I have the search working  - except for my original problem of keeping it all on the same page.  I don't want to pass it - I want it to display the result on the same page but in a certain location.  This site has one page, and for example, if you click on a product link, the navigation changes and the content section changes, but it's all the same page.  So there's an index.php and that's it.
You can see that I have variables being retrieved from the URL, but I am unsure how to integrate this with the search.  But now that i know what that first section is called (retreiving the variable in the url) I can at least research it better.  
ASKER CERTIFIED SOLUTION
Avatar of grendel777
grendel777
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial