php - Make the results from a mysql database search selectable -
i have database containing stock items , webpage allows search through database item type or specific item number. results returned , displayed in table under search form.
currently saving results of mysql query array, , printing results of array table.
how can make result selectable , have button such 'add' allow me retrieve information database based on selected item.
edit -
<?php require("header.php"); if(isset($_request['searching'])){ //check if form has been submitted connect('final');//connect db //set values search form $field = $_post['field']; $query = $_post['query']; $query = htmlspecialchars($query); // stop html characters $query = mysql_real_escape_string($query); //stop sql injection $data = mysql_query("select * stock stock.part_number in (select stock.part_number stock upper(stock.$field) like'%$query%')") ;//query db search field in colleumn selected// //$data = mysql_query("select * customer inner join address on customer.id = address.customer_id left outer join sites on address.id = sites.address_id upper(customer.$field) like'%$query%'") ; if($data === false) { $error = 'query error:'.mysql_error(); echo $error; } else { $test = array(); $colnames = array(); while($results = mysql_fetch_assoc($data)){// puts data database array, loops until no more $test[] = $results; } $colnames = array_keys(reset($test)); $anymatches=mysql_num_rows($data); //checks if querys returned results if ($anymatches == 0) { echo "sorry, can not find entry match query<br><br>"; } }
then below in html form create table , have
<?php //print header foreach($colnames $colname) { echo "<th>$colname</th>"; } ?>
and
<?php //print rows foreach($test $results) { echo "<tr>"; foreach($colnames $colname) { echo "<td>".$results[$colname]."</td>"; } echo "</tr>"; } ?>
i wasn't sure start try checkbox method.
well, there many ways adjust search user's liking.
the basic solution requires php , html have checkboxes @ cells want use filter.
then can add new parts old mysql-command and-connection. e.g. checkbox "name"-column next search show entries checked names.
<input type="checkbox" name="names[]" id="chwalter" value="walter" /> <label for="chwalter">chwalter</label>
when posted run through checkbox-array loop , add like
" , name '".$_get['names'][$i]."'"
.
note using groups checkboxes give array of activated element's values.
of course modify how checked checkbox alters request... removing filters, use regular expressions on request-string.
a nicer solution using javascript. e.g. use hidden checkboxes checked click on table-cells.
or use javascript filter elements! using classes ,
document.getelementsbyclassname['class']
will lighten server-traffic , speed request. that, recommend use class each row (row1, row2, etc.) , 1 each column (name, id, etc. ). when click on field, elements of same column class , loop through them.
if content mismatches, go through row-class , set css-attribtue "display:none"... if use table-layout can replace use of row-classes
this.parentnode.style.display="none"
to disable row (<tr>
-tag).
otherwise remove css again show them.
the disadvantage is, reduced result shown user, using reduced version again on server site, need map result again checkboxes or maybe hidden fields , send again.