Jump to content

find value between range of values


barecool

Recommended Posts

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

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;
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.