Hi all, I've posted a few times and gotten some really good replies.
I have this project that I'm having trouble with. I know I almost got this figured out, but my brain isn't comprehending something. I got this script from the web that fills 3 selects. One for centers (hospitals), managers, and reps. This example worked when I created the tables for it. When you open this page, it shows one select list, Centers. Once you select a Center, the form submits because of the onchange event. Then 2 selects are included on the page once it reloads, one for Managers, one for Reps that include data related to the Center that was selected. If you select a different Manager, the Rep table changes to relate to the Manager which is selected. Now I have worked with this code to create the page I need. When you first visit the page, only one select (dropdown) list is present, which is filled with data from a query for products. After selecting a product, (only working on graphics and video), 4 selects display holding specifications about the graphics and video products. Upone selecting any one of the specifications, a query is sent to gather any products containing that specification. So the query should hold one or four different specifications. I have everything working up to selecting the first specification. So my script, loads the Product table correctly, then it correctly saved the product and loads the 4 specification selects. Then after selecting the first specification the query works, and renders ok, but all the selects have lost their values. So I have to start again. I feel the problem has to do with the forms (loosing data) or the get method I'm using to determine which path to take. I have tried so many things producing nothing but errors, and can't figure out what's wrong. I really need to understand what I'm doing wrong, not just a solution. I've researched this and can't seem to find anything that I can work with. I'm only using JavaScript with the onchange event, and using php for the rest. I'd like to keep away from JavaScript for this, which I could use for more than I have. I've seen AJAX would work with this easily, but I use basic logic for most of my programming. I would like to keep this mostly PHP and MySQL, and don't want learn something else for this. I hope that maybe its something simple I'm overlooking and someone can help me learn what it is. Here is my script. After I figure this out, I have to produce results like this for every other product and need some advice quickly. Thanks in advance! Tanya Holliday Sorry about the formatting, I tried to do the best i could in this editor. <?php /* http:////productSearch.php */ // INCLUDE THE MYSQL DATABASE CONNECTION FILE require_once(''); // MAKE A CONNECTION TO THE DATABASE BEFORE ANY EVENTS CAN HAPPEN if(!$result = conn_db()) { echo 'Could not make a connection to the database'; } //IF A PRODUCT HAS BEEN SELECTED if($_GET['do'] == 'chproduct') { // THEN GET WHICH PRODUCT WAS SELECTED $product = $_POST['product']; if($product == 4) { $query_ff = "SELECT DISTINCT `Form Factor` FROM product_families ORDER BY `Form Factor` ASC"; $fFactors = @ mysql_query($query_ff); $row_fFactors = @ mysql_fetch_assoc($fFactors); $totalRows_fFactors = @ mysql_num_rows($fFactors); $query_gp = "SELECT DISTINCT `Graphics Processor` FROM product_families ORDER BY `Graphics Processor` ASC"; $gProcessors = @ mysql_query($query_gp); $row_gProcessors = @ mysql_fetch_assoc($gProcessors); $totalRows_gProcessors = @ mysql_num_rows($gProcessors); $query_ss = "SELECT DISTINCT `Software Support` FROM product_families ORDER BY `Software Support` ASC"; $softSupport = @ mysql_query($query_ss); $row_softSupport = @ mysql_fetch_assoc($softSupport); $totalRows_softSupport = @ mysql_num_rows($softSupport); $query_rg = "SELECT DISTINCT Ruggedization FROM product_families ORDER BY Ruggedization ASC"; $rugged = mysql_query($query_rg); $row_rugged = mysql_fetch_assoc($rugged); $totalRows_rugged = mysql_num_rows($rugged); } } elseif($_GET['do'] == "loadTable") { $query = "Select * FROM product_families WHERE "; if($_POST['form_factors']) { $currentFormFactor = $_POST['form_factors']; $query .= "`Form Factor`= '".$currentFormFactor."'"; } if($_POST['graphic_proc']) { $currentGraphicProcessor = $_POST['graphic_proc']; if($currentFormFactor) $query .= " AND `Graphics Processor` LIKE '".$currentGraphicProcessor."'"; else $query .= "`Graphics Processor` LIKE '" .$currentGraphicProcessor."'"; } if($_POST['soft_support']) { $currentSoftwareSupport = $_POST['soft_support']; if($currentFormFactor || $currentGraphicProcessor) $query .= " AND `Software Support` LIKE '" .$currentSoftwareSupport."%'"; else $query .= "`Software Support` LIKE '" .$currentSoftwareSupport."'"; } if($_POST['ruggedization']) { $currentRuggedization = $_POST['ruggedization']; if($currentFormFactor || $currentGraphicProcessor || $currentRuggedization) $query .= " AND Ruggedization LIKE '" .$currentSoftwareSupport."'"; else $query .="Ruggedization LIKE '" .$currentSoftwareSupport."'"; } $tableResults = mysql_query($query); } // GET LIST OF PRODUCTS TO LOAD IN FIRST SELECT MENU $query_products = "SELECT product_type_id, product_type FROM productType"; // QUERY DATABASE, GATHER RESULTS IN AN ARRAY, THEN COUNT THE NUMBER OF PRODUCTS IN ARRAY $products = mysql_query($query_products); $row_products = mysql_fetch_assoc($products); $totalRows_products = mysql_num_rows($products); ?> <!-- INSERT CODE FOR HTML PAGE AND DESIGN --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> </head> <body> <table width="100%"> <tr> <td colspan="2"> <!-- SET THE FORM ACTION TO ENVOKE THE GET do TO CHANGE PRODUCT NAMES --> <form name="productForm" id="productForm" method="post" action="<?php echo $SERVER['PHP_SELF']; ?>?do=chproduct"> <label for="product"><big>Products: </big></label> <select name="product" id="product" onChange="javascript:document.productForm.submit()"> <option value="">Select A Product...</option> <?php do { // ROW_PRODUCTS IS AN ARRAY OF PRODUCT NAMES echo '<option value="'.$row_products['product_type_id'].'"'; // IS PRODUCT_ID THE CURRENT PRODUCT SELECTED if(!(strcmp($row_products['product_type_id'], "$product"))) echo ' selected="SELECTED">' .$row_products'product_type']."</option>\n"; else echo '>'.$row_products['product_type']."</option>\n"; // GET ALL PRODUCT NAMES FROM THE ARRAY }while($row_products = mysql_fetch_assoc($products)); if(($rows = mysql_num_rows($products)) > 0) { mysql_data_seek($products, 0); // PROCEED TO THE NEXT CENTER NAME $row_products = mysql_fetch_assoc($products); } ?> </select> </form> <br /> </td> </tr> <tr> <td valign="top"> <?php // IF ONLY ONE VARIABLE ADDED TO THE GET if($_GET['do'] <> "") ?> <form name="specs" id="specs" method="post" action="http://productSearch.php?do=loadTable"> <label for="form_factors">Form Factors:</label> </td> <td > <select name="form_factors" id="form_factors" onChange="javascript:document.specs.submit()"> <option value="">Select A Form Factor...</option> <?php do { echo '<option value="'.$row_fFactors['Form Factor'].'"'; // IF CURRENT FORM FACTOR EQUALS SELECTED_FORM FACTOR if(!(strcmp($row_fFactors['Form Factor'], $currentFormFactor))) echo 'selected="SELECTED">' .$row_fFactors['Form Factor']."</option>\n"; else echo '>'.$row_fFactors['Form Factor']."</option>\n"; }while($row_fFactors = mysql_fetch_assoc($fFactors)); $rows = mysql_num_rows($fFactors);// COUNT THE NUMBER OF ROWS_IN FORM FACTORS if($rows > 0) //IF ROWS_IS GREATER THAN ZERO { mysql_data_seek($fFactors, 0); $row_fFactors = mysql_fetch_assoc($fFactors} ?> </select> </td> <td valign="top"> <label for="graphic_proc">Graphic Processors:</label> </td> <td> <select name="graphic_proc" id="graphic_proc" onChange="javascript:document.specs.submit()"> <option value="">Select A Graphic Processor...</option> <?php do { echo '<option value="' .$row_gProcessors['Graphics Processor'].'"'; if(!(strcmp($row_gProcessors['Graphics Processor'], $currentGraphicProcessor))) echo 'selected="SELECTED">' .$row_gProcessors['Graphics Processor']."</option>\n"; else if($row_gProcessors['Graphics Processor'] != NULL) echo '>' .$row_gProcessors['Graphics Processor'] ."</option>\n"; }while($row_gProcessors = mysql_fetch_assoc($gProcessors)); // COUNT THE NUMBER OF ROWS_IN SUPERVISORS $rows = mysql_num_rows($gProcessors); if($rows > 0) //IF ROWS_IS GREATER THAN ZERO { mysql_data_seek($gProcessors, 0); $row_gProcessors = mysql_fetch_assoc($gProcessors); } ?> </select> </td> </tr> <tr> <td valign="top"> <label for="soft_support">Software Support:</label> </td><td> <select name="soft_support" id="soft_support" onChange="javascript:document.specs.submit()"> <option value="">Select A Software Support...</option> <?php do { echo '<option value="'.$row_softSupport['Software Support'].'"'; if(!(strcmp($row_softSupport['Software Support'], $currentSoftwareSupport))) echo 'selected="SELECTED">' .$row_softSupport['Software Support']."</option>\n"; else echo '>'.$row_softSupport['Software Support']."</option>\n"; }while($row_softSupport = mysql_fetch_assoc($softSupport)); $rows = mysql_num_rows($softSupport); if($rows > 0) { mysql_data_seek($softSupport, 0); $row_softSupport = mysql_fetch_assoc($softSupport); } ?> </select> </td> <td valign="top"> <label for="ruggedization">Ruggedization:</label> </td> <td> <select name="ruggedization" id="ruggedization" onChange="javascript:document.specs.submit()"> <option value="">Select A Ruggedization...</option> <?php do { echo '<option value="'.$row_rugged['Ruggedization'].'"'; if(!(strcmp($row_rugged['Ruggedization'], $currentRuggedization))) echo 'selected="SELECTED">' .$row_rugged['Ruggedization']."</option>\n"; else echo '>'.$row_rugged['Ruggedization']."</option>\n"; }while($row_rugged = mysql_fetch_assoc($rugged)); $rows = mysql_num_rows($rugged); if($rows > 0) { mysql_data_seek($rugged, 0); $row_fFactors = mysql_fetch_assoc($rugged); } echo '</table>'; if($tableResults) { echo '<br /><br />'; while($row = mysql_fetch_array($tableResults)) { // echo rows that match user information echo '<tr>'; print "\n"; echo '<td>'; print "\n"; echo $row['Product']; print "\n"; echo '</td>'; print "\n"; echo '<td>'; print "\n"; echo $row['Form Factor']; print "\n"; echo '</td>'; print "\n"; echo '<td>'; print "\n"; echo $row['Graphics Processor']; print "\n"; echo '</td>'; print "\n"; echo '<td>'; print "\n"; echo $row['InputsRGG']; print "\n"; echo '</td>'; print "\n"; echo '<td>'; print "\n"; echo $row['InputsNTSC']; print "\n"; echo '</td>'; print "\n"; echo '<td>'; print "\n"; echo $row['InputsLVDS']; print "\n"; echo '</td>'; print "\n"; echo '<td>'; print "\n"; echo $row['InputsDVI']; print "<br /><br />\n"; echo '</td>'; echo '</tr>'; } } ?> echo '</table>'; </select> </form> </body> </html> <?php } ?> ------------------------ Yahoo! Groups Sponsor --------------------~--> 1.2 million kids a year are victims of human trafficking. Stop slavery. http://us.click.yahoo.com/.QUssC/izNLAA/TtwFAA/CefplB/TM --------------------------------------------------------------------~-> The php_mysql group is dedicated to learn more about the PHP/MySQL web database possibilities through group learning. Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php_mysql/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
