I am a newbie and unfamiliar with PHP and MySQL... I am trying to create a dropdown menu that defaults to all items in my database while still allowing one to also filter to certain products. Right now, I have a database named Products and am trying to base my dropdown off of the three different Product_Type items (Chips, Dips & Marinades, Rubs). Below is my code that I have so far which gets the individual Product_Type items, but I cannot get the dropdown to get ALL items in my db. Can someone help me out?
Expand|Select|Wrap|Line Numbers
- <code>
- <?php
- if (!function_exists("GetSQLValueString")) {
- function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
- {
- if (PHP_VERSION < 6) {
- $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
- }
- $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
- switch ($theType) {
- case "text":
- $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
- break;
- case "long":
- case "int":
- $theValue = ($theValue != "") ? intval($theValue) : "NULL";
- break;
- case "double":
- $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
- break;
- case "date":
- $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
- break;
- case "defined":
- $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
- break;
- }
- return $theValue;
- }
- }
- $currentPage = $_SERVER["PHP_SELF"];
- $maxRows_Test = 10;
- $pageNum_Test = 0;
- if (isset($_GET['pageNum_Test'])) {
- $pageNum_Test = $_GET['pageNum_Test'];
- }
- $startRow_Test = $pageNum_Test * $maxRows_Test;
- mysql_select_db($database_WPhoto, $WPhoto);
- $query_Test = "SELECT * FROM Products WHERE Product_Type='$Product_Type' ORDER BY Product_Title ASC";
- $query_limit_Test = sprintf("%s LIMIT %d, %d", $query_Test, $startRow_Test, $maxRows_Test);
- $Test = mysql_query($query_limit_Test, $WPhoto) or die(mysql_error());
- $row_Test = mysql_fetch_assoc($Test);
- if (isset($_GET['totalRows_Test'])) {
- $totalRows_Test = $_GET['totalRows_Test'];
- } else {
- $all_Test = mysql_query($query_Test);
- $totalRows_Test = mysql_num_rows($all_Test);
- }
- $totalPages_Test = ceil($totalRows_Test/$maxRows_Test)-1;
- $queryString_Test = "";
- if (!empty($_SERVER['QUERY_STRING'])) {
- $params = explode("&", $_SERVER['QUERY_STRING']);
- $newParams = array();
- foreach ($params as $param) {
- if (stristr($param, "pageNum_Test") == false &&
- stristr($param, "totalRows_Test") == false) {
- array_push($newParams, $param);
- }
- }
- if (count($newParams) != 0) {
- $queryString_Test = "&" . htmlentities(implode("&", $newParams));
- }
- }
- $queryString_Test = sprintf("&totalRows_Test=%d%s", $totalRows_Test, $queryString_Test);
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>Callaloo Foods - Products</title>
- <link rel="stylesheet" href="animated-menu/animated-menu.css"/>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
- <script src="animated-menu/js/jquery.easing.1.3.js" type="text/javascript"></script>
- <script src="animated-menu/animated-menu.js" type="text/javascript"></script>
- <!-- JavaScripts-->
- <script type="text/javascript" src="s3Slider.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- $('#slider1').s3Slider({
- timeOut: 10000
- });
- });
- </script>
- </head>
- <body>
- <div id="container">
- <div id="header">
- <img src="http://bytes.com/images/header_logo_top.jpg" width="898" height="95" border="0" usemap="#Map" />
- <map name="Map" id="Map">
- <area shape="rect" coords="224,1,673,89" href="index.php" alt="home" />
- </map>
- <ul class="nav">
- <img src="http://bytes.com/images/header_logol_bottom.jpg" align="left"/>
- <li class="green-home">
- <p><a href="index.php">Home</a></p>
- <p class="subtext"></p>
- </li>
- <li class="green-background">
- <p><a href="background.php">Background</a></p>
- <p class="subtext"></p>
- </li>
- <li class="green-products">
- <p><a href="products.php">Products</a></p>
- <p class="subtext"></p>
- </li>
- <li class="green-contact">
- <p><a href="contact.php">Contact</a></p>
- <p class="subtext"></p>
- </li>
- <li class="green-locations">
- <p><a href="locations.php">Locations</a></p>
- <p class="subtext"></p>
- </li>
- <img src="http://bytes.com/images/header_logor_bottom.jpg" align="right"/>
- </ul>
- </div>
- <div id="thankyou">
- <div id="gallery">
- <div id="content">
- <h1>Products</h1>
- <form id="form1" name="form1" method="get" action="products.php">
- <p>
- <label>Narrow Your Search:
- <select name="Product_Type" method="post">
- <option value="Product_Type" selected="selected">All</option>
- <option value="Chips">Chips</option>
- <option value="Dips, Marinades">Dips, Marinades</option>
- <option value="Rubs">Rubs</option>
- </select>
- </label>
- <label>
- <input type="submit" name="button" id="button" value="Submit" />
- </label>
- </p>
- </form>
- </div>
- <div id="contentbody">
- <?php do { ?>
- <p><img src = "http://bytes.com/images/<?php echo $row_Test['Product_Image_Small']; ?>" align="left"/><br />
- <a href="productdetails.php?recordID=<?php echo $row_Test['Product_ID']; ?>" >
- <?php echo $row_Test['Product_Title']; ?></a><br />
- <?php echo $row_Test['Product_Type']; ?><br />
- <?php echo $row_Test['Product_Description']; ?><br />
- <?php } while ($row_Test = mysql_fetch_assoc($Test)); ?>
- </p>
- </div>
- <p> </p>
- <h2><br />
- <table border="0">
- <tr>
- <td><?php if ($pageNum_Test > 0) { // Show if not first page ?>
- <p><a href="<?php printf("%s?pageNum_Test=%d%s", $currentPage, 0, $queryString_Test); ?>">First</a>
- </p>
- <?php } // Show if not first page ?></td>
- <td><?php if ($pageNum_Test > 0) { // Show if not first page ?>
- <p><a href="<?php printf("%s?pageNum_Test=%d%s", $currentPage, max(0, $pageNum_Test - 1), $queryString_Test); ?>">Previous</a>
- </p>
- <?php } // Show if not first page ?></td>
- <td><?php if ($pageNum_Test < $totalPages_Test) { // Show if not last page ?>
- <p><a href="<?php printf("%s?pageNum_Test=%d%s", $currentPage, min($totalPages_Test, $pageNum_Test + 1), $queryString_Test); ?>">Next</a>
- </p>
- <?php } // Show if not last page ?></td>
- <td><?php if ($pageNum_Test < $totalPages_Test) { // Show if not last page ?>
- <p><a href="<?php printf("%s?pageNum_Test=%d%s", $currentPage, $totalPages_Test, $queryString_Test); ?>">Last</a>
- </p>
- <?php } // Show if not last page ?></td>
- </tr>
- </table>
- </h2>
- </div>
- <p> Records <?php echo ($startRow_Test + 1) ?> to <?php echo min($startRow_Test + $maxRows_Test, $totalRows_Test) ?> of <?php echo $totalRows_Test ?> <br />
- </p>
- <p> </p>
- </div>
- </div>
- <div id="footer">
- <ul>
- <li><a href="index.php">home</a></li>
- <li><a href="background.php">background</a></li>
- <li><a href="products.php">products</a></li>
- <li><a href="contact.php">contact</a></li>
- <li><a href="locations.php">locations</a></li>
- </ul>
- </div>
- </div>
- </body>
- </html>
- <?php
- mysql_free_result($Test);
- ?>
- </code>