barecool Posted May 19, 2008 Share Posted May 19, 2008 Im a newbie and I m trying to create a page on which i can go in and type in a value (number) to find a record that is between several ranges hi numbers and low numbers. my tables have the following info model Name year beggining serial ending serial 300 300 1999 3006097 3007000 500 500 2003 5040000 5041000 i want to be able to create a dropdown list and also a serial number finder box that can find a that if for example i enter 3006550 it can tell me that it is a model 300 name 300 year 1999 can anyone help? I need it really bad!!! Link to comment https://forums.phpfreaks.com/topic/106265-find-value-between-range-of-values/ Share on other sites More sharing options...
jonsjava Posted May 19, 2008 Share Posted May 19, 2008 just change the sql stuff, and you should be fine. (don't forget to change the sql query to reflect your tables actual name) <center> <table border="0"> <tr> <td>Search for:</td> <td><input type="text" name="serial"></td> </tr> <tr> <td><input type="submit" value="Search"></td> </tr> </table> </center><br /> </center> <?php if (isset($_POST['serial'])){ /* EDIT TO MATCH YOUR DB CONNECTION INFO */ $db_host = "localhost"; $db_user = "username"; $db_pwd = "password"; $db_name = "database_name"; /* END SQL CONNECTION INFO */ $link = mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name, $link); $serial = mysql_real_escape_string($_POST['serial']); /* EDIT THIS TO SUIT YOUR NEEDS */ $sql = "SELECT * FROM `table_name` WHERE `beginning serial` <= '{$serial}' AND `ending serial` >= '{$serial}' LIMIT 1;"; /* END QUERY */ $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)){ $model = $row['model']; $Name = $row['name']; $year = $row['year']; echo <<<END <center> <table> <tr> <td>Model:</td> <td>$model</td> </tr> <tr> <td>Name:</td> <td>$name</td> </tr> <td>Year:</td> <td>$year</td> </tr> </table> </center> END; } } ?> Link to comment https://forums.phpfreaks.com/topic/106265-find-value-between-range-of-values/#findComment-545153 Share on other sites More sharing options...
barecool Posted May 20, 2008 Author Share Posted May 20, 2008 thanks i will try it Link to comment https://forums.phpfreaks.com/topic/106265-find-value-between-range-of-values/#findComment-545816 Share on other sites More sharing options...
barecool Posted May 21, 2008 Author Share Posted May 21, 2008 im still stuck I cant get the page to pull the records from the table.. and display them can someone help me and copy the values that i have into an sql dump file and see if they can get the code above to work. Link to comment https://forums.phpfreaks.com/topic/106265-find-value-between-range-of-values/#findComment-546261 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.