Jump to content

Fairly basic question - issue with an include and an argument that needs passing


Recommended Posts

I think this is a simple question, but I'm just starting out and can't figure out how to do this exactly.


I'm making a demo site for a flower shop. The structure is as such (only listing the particular files in question - once this is done, the rest will be easy)


index.php -> inc_show_colors.php -> showColors.php


The index is to be standard through the site, loading include files into a main content area.  Clicking on a link loads inc_by_color.php (index.php -> index.php?page=by_color )


From there, one of the four colors is selected.


showColors.php contains switch statements for each color. I want to load showColors.php into the main content window when a color is selected, and I need to have it work for all four colors. I'm not sure how to do this, as you can't pass a variable to an include from what I understand.


What's the easiest way to go about this? Keep in mind this is an intro class and "best practices" are not necessary yet, just the simplest solution to get it working.


I want each of these colors to link to another include file, which will load in its place in index.php.




<div id="maincontent">
	if (isset($_GET['page'])) {
		switch ($_GET['page']) {
			case 'by_color':
			case 'by_type':
			case 'by_occasion':
			case 'view_cart':
			case 'payment_options':

			case 'home_page':





The first link I tried doing in the way I thought would work, but it doesn't. It can't find the include file.

The second one works, kind of - but it just loads the page by itself, not into the maincontent div in index.php.

<h1>Flowers Categorized by Color</h1>
<div class="picdivcontainer">
<div class="picdiv"><a href="index.php?page=red"><img src="images/image.png" width="90" height="90" alt="Red Flowers" />
<div class="picdiv"><a href="showColors.php?color=white"><img src="images/image.png" width="90" height="90" alt="White Flowers" /></a>
  <p><a href="showColors.php?color=white">White</a></p></div>



and showColors.php:

if (isset($_GET['color'])) {
		switch ($_GET['color']) {
			case 'red':
				$result = mysql_query("SELECT * FROM flowers WHERE color='red'") or die(mysql_error());
				while($row = mysql_fetch_array( $result )) {	
				// Set and trim strings and show the resulting flowers from query					 
				$flowername = $row['name'];
				$flowerimage = $row['image'];
				$image_path = "images/";
				$flowername = str_replace('_', ' ', $flowername);
				$flowername = ucwords($flowername);
				?> <div class="picdiv"><p><?php echo $flowername."<br />";
				$flowerimage = str_replace(' ', '_', $flowerimage);			
				echo "<img src='images/" . $row['image'] . "' />";
				?></p></div> <?php


I realize that showColors.php is probably a really messy way of doing this, but I just need to get it functioning ASAP for now.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

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

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.