Jump to content

Nebbers

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Nebbers's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Sorry, where it read: index.php -> inc_show_colors.php -> showColors.php should be: index.php -> inc_by_color.php -> showColors.php
  2. 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. index.php: <div id="maincontent"> <?php if (isset($_GET['page'])) { switch ($_GET['page']) { case 'by_color': include('includes/inc_by_color.php'); break; case 'by_type': include('includes/inc_by_type.php'); break; case 'by_occasion': include('includes/inc_by_occasion.php'); break; case 'view_cart': include('includes/inc_view_cart.php'); break; case 'payment_options': include('includes/inc_payment_options.php'); break; case 'home_page': default: include('includes/inc_home.php'); break; } } else include('includes/inc_home.php'); ?> </div> inc_by_color.php: 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" /> <p>Red</a></p></div> <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> </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 } break; 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.
×
×
  • 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.