I tried these two snippets of code and it gave me all records...even the "LIKE 3%" snippet didn't work...also I don't want to have to hardcode it...if someone enters any number in any segment I want to be able to query the db that way...but the user must enter a complete segment in any of the three SSN segment text boxes...if they don't enter any number I want it to die with an error msg...
I've seen people's web pages do this but when the php is parsed server side it's tough to lift the source and figure it out myself...so any help would be much appreciated.
Originally posted by cgraz
If you have three seperate fields (field1, field2, and field3), and in your database it's written as
xxx-xx-xxxx
Then do
$query = mysql_query("SELECT * FROM table WHERE ss_field='" . $_POST["field1"] . "-" . $_POST["field2"] . "-" . $_POST["field3"] . "'") or die(mysql_error());
If you want all the SS numbers that begin with a 3
$query = mysql_query("SELECT * FROM table WHERE ss_field LIKE '3%'") or die(mysql_error());
Cgraz [/B]
Here's what I have so far:
<?php
$db = mysql_connect("127.0.0.1", "client", "");
mysql_select_db("Military_Catalog",$db);
$sql_events = mysql_query("SELECT * FROM partslist WHERE 'nsn' LIKE '%'");
while ($row = mysql_fetch_array($sql_events)) {
$partnum = $row["partnum"];
$nsn = $row["nsn"];
$top_level_kit = $row["top_level_kit"];
$description = $row["description"];
$eng_used_on = $row["eng_used_on"];
echo"
<p>
<span style=\"font-family:verdana 10px;\">
Part Number: ".$row['partnum']."<br />
NSN: ".$row['nsn']."<br />
Top Level Kit: ".$row['top_level_kit']."<br />
Description: ".$row['description']."<br />
Engine Used On: ".$row['eng_used_on']."
</span>
</p>
<hr noshade>
";
}
?>
Here's the form page that calls the script above:
<html>
<head>
<title>Sample NSN Query Page</title>
</head>
<body onload="document.NSN.start.focus()">
<script>
function autotab(original,destination){
if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
destination.focus()
}
</script>
<center>
<div align="center">
<table width="100%" height="100%" border=0 cellspacing=0 cellpadding=0>
<tr>
<td>
<div align="center">
<form name="NSN" method="post" action="getnsn.php">
<p style="font-family: verdana; font-size: 10px;"> NSN Search: </p>
<input name="start" type="text" size="4" maxlength="4" size="11" tabindex=1 style="font-family: verdana; font-size: 10px; border-color:#3871A9;border-width=1px;" onKeyup="autotab(this, document.NSN.second)" />
-
<input name="second" type="text" size="2" maxlength="2" size="11" tabindex=2 style="font-family: verdana; font-size: 10px; border-color:#3871A9;border-width=1px;" onKeyup="autotab(this, document.NSN.third)" />
-
<input name="third" type="text" size="3" maxlength="3" size="11" tabindex=3 style="font-family: verdana; font-size: 10px; border-color:#3871A9;border-width=1px;" onKeyup="autotab(this, document.NSN.fourth)" />
-
<input name="fourth" type="text" size="3" maxlength="3" size="11" tabindex=4 style="font-family: verdana; font-size: 10px; border-color:#3871A9;border-width=1px;" />
<input type="submit" name="Submit" value="Search" size="11" tabindex=5 style="font-family: verdana; font-size: 10px; border-color:#3871A9;border-width=1px;" />
<input type="reset" name="Reset" value="Reset" size="11" tabindex=6 style="font-family: verdana; font-size: 10px; border-color:#3871A9;border-width=1px;" />
</form>
</div></td>
</tr>
</table>
</div>
</center>
</body>
</html>