ee2400 Posted January 7, 2010 Share Posted January 7, 2010 Hi I have a php search form. It consists of two files: search.php and print.php. The select menu works allright but I would like to get the price, year and mileage text fields to work also on the search form. Could you help me with the code? The database is called carsale. It includes a datatable called cars. Table includes information (year, make, model, mileage, price etc.) about used cars. search.php <form method="post" action="print.php"> <?php //connections print "<p>Make: <br>"; $all = "select * from cars group by make order by make asc"; $result = @mysql_query($all); print "<select name='sp'>"; print "<option value='all'>all"; while ( $row = mysql_fetch_array( $result ) ) { print "<option value='$row[3]'> $row[3]"; } print "</select>\n"; print "</p>"; print "<p>Year: <br>"; print "<input type='text' name='yearA' size='3'>"; print " - "; print "<input type='text' name='yearB' size='3'>"; print "</p>"; print "<p>Price: <br>"; print "<input type='text' name='priceA' size='3'>"; print " - "; print "<input type='text' name='priceB' size='3'>"; print "</p>"; print "<p>Mileage: <br>"; print "<input type='text' name='mileA' size='3'>"; print " - "; print "<input type='text' name='mileB' size='3'>"; print "</p>"; ?> <br><input type="submit" value="search"> print.php <?php print "<p>Results:</p>"; if (isset($_POST['sp'])) { $m1 = $_POST['sp']; } if ($m1 == 'all') $sql1 = "select * from cars"; else $sql1 = "select * from cars where make='$m1' order by make asc"; $result = @mysql_query($sql1); print "<table border=1>"; print "<tr><td>make</td><td>model</td><td>year</td><td>miles</td><td>price</td></tr>"; while ($row = mysql_fetch_array( $result) ) { print "<tr><td>$row[3] </td><td>$row[4] </td><td>$row[5]</td><td>$row[6] </td><td>$row[10] </td></tr>"; } print "</table>\n"; ?> So what changes or additions I will have to do to these two files that the search works ok? Link to comment https://forums.phpfreaks.com/topic/187555-php-search-form/ Share on other sites More sharing options...
Catfish Posted January 7, 2010 Share Posted January 7, 2010 it depends what you want to do... if you just want to be able to do searches on different fields individually, my suggestion is to change the dropdown select box to contain the name of the field the user wants to search and have a text box for them to type in the value to look for. eg: dropdown box select "make", text box value "Ford" dropdown box select "mileage", text box value "60000" (would find all records with mileage of 60000 or less i guess) if you want to be able to search against value of multiple fields all at once, then that is a lot more complex and requires choices on what sort of logic to use etc. Link to comment https://forums.phpfreaks.com/topic/187555-php-search-form/#findComment-990272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.