Database search function in php
-
Experts, I have a table in php which displays all serial numbers in the program. What i would like to do is when the user for example wants to find serial number ABCDEF123 they will type it in the text box and then press submit. I would then like all the other serial numbers to dissapear/hide and then just show tht serial number. I have created the text box and button in php but dont know how to do the above. If anybody could help that would be great Many thanks Dan
-
Experts, I have a table in php which displays all serial numbers in the program. What i would like to do is when the user for example wants to find serial number ABCDEF123 they will type it in the text box and then press submit. I would then like all the other serial numbers to dissapear/hide and then just show tht serial number. I have created the text box and button in php but dont know how to do the above. If anybody could help that would be great Many thanks Dan
the simple way would be to make a form and have the page post to itself. At the top of the page in php
<?php ... ?>
check to see if the field has been submitted using isset() and if so run a sql query and output the info below the form in a table. Be extra careful with checking the input value before you run it in a query. I run a scrubber function that only permits valid characters to be used. Also read up on mysql_escape_string(), add_slashes() and related function and the user comments. A lot of good info in there.
-
Experts, I have a table in php which displays all serial numbers in the program. What i would like to do is when the user for example wants to find serial number ABCDEF123 they will type it in the text box and then press submit. I would then like all the other serial numbers to dissapear/hide and then just show tht serial number. I have created the text box and button in php but dont know how to do the above. If anybody could help that would be great Many thanks Dan
-
Experts, I have a table in php which displays all serial numbers in the program. What i would like to do is when the user for example wants to find serial number ABCDEF123 they will type it in the text box and then press submit. I would then like all the other serial numbers to dissapear/hide and then just show tht serial number. I have created the text box and button in php but dont know how to do the above. If anybody could help that would be great Many thanks Dan
I note that you'd like the other numbers to disappear/hide - implying that they're already visible on the page. If that's the case, then why use php for that I wonder? Surely the approach to use is one of JavaScript? I'd achieve what I understand as the aim with code resembling the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.style1 {
font-size: 24px;
font-weight: bold;
}
.hiddenTxt {
display: none;
}
</style>
<script type="text/javascript">
function byId(e){return document.getElementById(e)}
function doFind()
{
var table = byId("table1");
var row , x, y
var searchStrsearchStr = byId("serialInput").value for (y=0; y<5; y++) { row = table.rows\[y\] for (x=0; x<5; x++) { if (row.cells\[x\].innerHTML != searchStr) row.cells\[x\].className = "hiddenTxt" else row.cells\[x\].className = "" } }
}
function doReset()
{
var table = byId("table1"), row , cell, x, yfor (y=0; y<5; y++) { row = table.rows\[y\] for (x=0; x<5; x++) { cell = row.cells\[x\] cell.className = "" } }
}
</script>
</head><body>
<table width="300" border="2" bordercolor="#333333" id="table1">
<caption>
<span class="style1">Serial Numbers</span>
</caption>
<tr>
<td>1234</td>
<td>5678</td>
<td>9012</td>
<td>3456</td>
<td>8901</td>
</tr>
<tr>
<td>abcd</td>
<td>efgh</td>
<td>ijkl</td>
<td>mnop</td>
<td>qrst</td>
</tr>
<tr>
<td>uvwx</td>
<td>yz</td>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>d</td>
<td>e</td>
<td>f</td>
<td>g</td>
<td>h</td>
</tr>
<tr>
<td>i</td>
<td>j</td>
<td>k</td>
<td>l</td>
<td>m</td>
</tr>
</table>
<p>Search for
<