theladycoder Posted July 30, 2008 Share Posted July 30, 2008 I am still fairly new to PHP and have hit a wall. I initially built a search function that a user types in a measurement and the results returned everything within .25 of the searched size. I got that to work, but now I need to expand the function and not sure how to do it. ??? I need to take what I've done and another text box so that the user can type in another size and select 1 of 2 radio buttons to determine if the want to search inches or metrics. The first box checks again the inner diameter in the database within .25 then needs to look at the cross section size within 3.125 and return the results, which will either be inches or metrics based on the radio button selection. From here I will carry the values to the second page. Here is part of the original code: <?php if($_POST['Submit']!=''){ $variable_a = $_POST['variable_a']; $results = .25; $total = $variable_a - $results ; $total1 = $variable_a + $results ; //This takes the user input //That result is then added and subtracted by .25 from user input //That total is then searched against the database to display //results within the added and subtracted results of .25 echo "Getting .25 (1/4) difference to display Inner Diameter in Inches<br>"; echo "Search your size of $variable_a between $total and $total1"; echo "<br>"; echo "$variable_a = $total ($variable_a - $results)"; echo "<br>"; echo "$variable_a = $total1 ($variable_a + $results)"; echo "<br><br>"; } ?> //The search box <body> <hr> <form name="calc" method="post"> Inner Diameter: <input name="variable_a" type="text" id="variable_a"> INCHES <input type="submit" name="Submit" value="Search"> </form> //the rest of the php /* make connection to database */ MYSQL_CONNECT($hostname, $username, $password) OR DIE( "Unable to connect to database"); @mysql_select_db("$dbName") or die( "Unable to select database"); if ($variable_a == "") {$variable_a = '$variable_a';} $result = mysql_query ("SELECT * FROM $tblNameWHERE idInches between '$total' and '$total1'"); if ($row = mysql_fetch_array($result)) { do { PRINT "<form name='myForm' action='page1.php?orID=$row[orID]' method='post'>"; PRINT "<table width='600' align='center' border='0'><tr><td>"; PRINT "<table align='center' width='100%'><tr><td>"; echo "<a href='page1.php?orID=$row[orID]&idInches=$row[idInches]&idMM=$row[idMM]&csInches=$row[csInches]&csMM=$row[csMM]'>"; print "Record ID: "; print $row["orID"]; PRINT "</a>"; PRINT "<tr><td>Inner Diameter "; print $row["idInches"]; PRINT " Inches | Metrics "; print $row["Metrics"]; print $row["idMM"]; PRINT "</td>"; PRINT "</tr>"; PRINT "<tr><td>Cross Section "; print $row["csInches"]; PRINT " Inches | Metrics "; print $row["Metrics"]; print $row["csMM"]; PRINT "</td>"; PRINT "</tr>"; PRINT "</table></tr></td>"; PRINT ("<p>"); } while($row = mysql_fetch_array($result)); } else {print "Sorry, there isn't a size in that range...";} PRINT "<input type='hidden' name='orID' value='$orID'>"; PRINT"</form> "; ?> ============================================================ This is the start of the new code, but not sure how to do a search of both boxes: <?php if($_POST['Submit']!=''){ $variable_a = $_POST['variable_a']; $variable_b = $_POST['variable_b']; $results = .25; $total = $variable_a - $results ; $total1 = $variable_a + $results ; $results = 3.125; $total2 = $variable_b - $results ; $total2a = $variable_b + $results ; //This takes the user input //That result is then added and subtracted by .25 from user input //That total is then searched against the database to display //results within the added and subtracted results of .25 echo "Getting .25 (1/4) difference to display Inner Diameter<br>"; echo "Search your size of $variable_a between $total and $total1"; echo "<br>"; echo "$variable_a = $total ($variable_a - $results)"; echo "<br>"; echo "$variable_a = $total1 ($variable_a + $results)"; echo "<br><br>"; echo "Getting 3.125 (1/32) difference to display Cross Section<br>"; echo "Search your size of $variable_b between $total2 and $total2a"; echo "<br>"; echo "$variable_b = $total2 ($variable_b - $results)"; echo "<br>"; echo "$variable_b = $total2a ($variable_b + $results)"; echo "<br><br>"; } ?> //The form <form name="calc" method="post"> Inner Diameter: <input name="variable_a" type="text" id="variable_a"> Cross section: <input name="variable_b" type="text" id="variable_b"> <input name="unit" type="radio" id="inches" value="inches">Inches <input name="unit" type="radio" id="metrics" value="metrics">metrics <input type="submit" name="Submit" value="Search"> </form> //The SQL statement $result = mysql_query ("SELECT * FROM tblNameWHERE idInches between '$total' and '$total1' and csInches between 'total2' and ''total2a"); I am not quite sure how to combine the 2 search boxes. All the data is in one table. There are a total of 4 fields that it checks, but only 2 at time. 2 fields are in inches and the other 2 are metrics. Tahnsk in advance Link to comment https://forums.phpfreaks.com/topic/117260-search-function/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.