I have 2 problem here
I have to remove array which it value is 0
I have to insert a data to database using loop
any response would be appreciated
here my code :
Javascript
for (a = 0; a <= i; a++) {
$(".addmore_" + a).on('click', function (a) {
return function() {
var data = "<tr><td><input class='form-control sedang' type='text' id='packinglist_" + a + "' name='packinglist[]'/></td></tr>";
$("#keatas_" + a).append(data);
} ;
}
(a));
};
My Java script is working properly but the point is when I want to add the input-box to database, a data didn't loop
here my html
for($i=1;$i<=5;$i++)
{
<table id='keatas_$i' class='keatas'>
<tr>
<input class='form-control' type='hidden' id='hiddenlot_$i' name='hiddenlot[]' />
<input class='form-control' type='hidden' id='hiddencustomer_$i' name='hiddencustomer[]' />
<td>
<a><span class='glyphicon glyphicon-plus addmore_$i'></span></a>
</td>
</tr>
</table>
}
so i need to loop my input box everytime i press "addmore" button ,and for some reason i need to loop 'hiddencustomer[]' and 'hiddenlot[]'
and here my query.php
for ($i = 0; $i < 5; $i++) {
$idlot = $_POST['hiddenlot'][$i];
$customer = $_POST['hiddencustomer'][$i];
$a=mysql_query("INSERT INTO item VALUES ('',now(),'$idlot')");
$count = count($_POST['packinglist']);
for ($c = 0; $c < $count; $c++) {
$pack = $_POST['packinglist'];
$packinglist1 = array_values(array_filter($pack));
$packinglist = $packinglist1[$c];
$item = mysql_query("SELECT * FROM item ORDER BY item_id DESC");
$itemid = mysql_fetch_array($item);
$a= mysql_query("INSERT INTO packing_list VALUES('','$packinglist','$itemid[item_id]')");
}
}
I put 2nd loop in 1st loop cause I need a item_id for insert to packing_list table and I got a item_id by last input to item table
sorry for bad explain and bad english
I hope you can understand what I mean
thankyou
I need help!
I have a php page that generates a html table from an array(). This array contains all the lines of a csv (no problem with this):
load_csv.php
<?php
function print_array_of_arrays_to_html_table(&$array_by_reference)
{
echo "<br><table border=1 align=center id=tableID>";
for ($i = 0; $i < count($array_by_reference); $i++)
{
echo "<tr>";
for ($j = 0; $j < count($array_by_reference[$i]); $j++)
{
echo "<td align=right title='f:".$i."\nc:".$j."\nv:".($array_by_reference[$i][$j])."'>".($array_by_reference[$i][$j])."</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
My intention is to indicate a column number in a text field, change all values of all cells in that column. The value would be the same for all cells in that column. For example, change all to '0' o whatever.
For now, with 'jquery' I can individually change any cell:
same load_csv.php:
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<script language="javascript" type="text/javascript">
$('#tableID').click(function(event){
var original = $(event.target).text().toString();
var original_copy = original;
var retValue = prompt("\nChange value? ", original);
//if not empty and OK is pressed
if (retValue !== '' && retValue !== null)
{
//if not the same that 'original'
if (retValue !== original)
{
$(event.target).text(retValue);
}
else
{
alert("has not been modified" + original);
}
}
else
{
//if click Cancel
alert("has not been modified: " + original_copy);
}
})
</script>
But also want to change a whole column at a time. For example, calling the function onclick() of a button:
same load_csv.php:
<form>
<input type='button' value="Go back" onClick="history.go(-1);return true;"/>
<!-- if onclick button all values of all cells in the column are changed -->
<br>Column:
<input type='text'/>
<input type='button' value="Change all column?" onClick="myfunction()"/>
</form>
output example:
enter link description here
Any tips (yes, all code in same php.page. Sorry for my bad english)?
Thanks in advance.
EDIT: Solution:
I created two selectbox, one showing only the columns I intend to change, and one that allows me to choose to add two values (0 or 1). Then with the button I call the function. This includes the selectbox selected values. Next I check single cells (td) having 0 or 1 and "Pum"! success.
<select name="cols_bool" id="cols_bool">
<option value="not_selected" selected="selected">Choose...</option>
<?php
if (count($col_with_bools) > 0)
{
for ($i = 0; $i < count($col_with_bools); $i++)
{
echo "<option value=".$i.">".$col_with_bools[$i]."</option>";
}
}
?>
</select>
<br>New bool values to insert:
<select name="value_to_replace" id="value_to_replace">
<option value="1" selected="selected">1 (TRUE)</option>
<option value="2">0 (FALSE)</option>
</select>
<input type='button' class="change" value="Change all cells?" onClick="replace()"/>
<script language="javascript" type="text/javascript">
function replace()
{
var column_select = $('#cols_bool option:selected').text();
var value_to_insert = $('#value_to_replace option:selected').text();
$("#tableID").find('tr').each(function(){
var $td = $(this).find('td');
var $td_text = $td.eq(column_select).text();
if ($td_text == '1' || $td_text == '0')
{
$td.eq(column_select).text(value_to_insert.substring(0,1));
}
});
}
</script>
you can simply do like this
function replace(value_to_replace)
{
$("#tableID").find('tr').each(function () {
var $td = $(this).find('td');
$td.eq(3).text(value_to_replace);
});
}
Ive been trying to build a web site that retrieves values from the database and then implements features such as sorting and filtering. I am building the query each time a filter is applied as of now, will definitely change to something more efficient. For the sorting, I want to implement it on the client side itself since the data is already present.
I went through a number posts from this forum and arrived at a piece of code that I included in mine. To give you a heads up on the web page, the sorting options are included as radio buttons. Whenever a user clicks on the "Apply" button, a javascript function is triggered which sorts the html table - which is populated using php.
Here is the code:
<script type="text/javascript">
function SortTable() {
var sortedOn = 1;
var table = document.getElementById('venue_list');
var tbody = table.getElementsByTagName('tbody')[0];
var rows = tbody.getElementsByTagName('tr');
var rowArray = new Array();
for (var i=0, length=rows.length; i<length; i++) {
rowArray[i] = new Object;
rowArray[i].oldIndex = i;
rowArray[i].value = rows[i].getElementsByTagName('td')[sortOn].firstChild.nodeValue;
}
//if (sortOn == sortedOn) { rowArray.reverse(); }
//else { sortedOn = sortOn; }
/*
Decide which function to use from the three:RowCompareNumbers,
RowCompareDollars or RowCompare (default).
For first column, I needed numeric comparison.
*/
if (sortedOn == 1) {
rowArray.sort(RowCompareStrings);
}
else {
rowArray.sort(RowCompare);
}
var newTbody = document.createElement('tbody');
for (var i=0, length=rowArray.length ; i<length; i++) {
newTbody.appendChild(rows[rowArray[i].oldIndex].cloneNode(true));
}
table.replaceChild(newTbody, tbody);
}
function RowCompare(a, b) {
var aVal = a.value;
var bVal = b.value;
return (aVal == bVal ? 0 : (aVal > bVal ? 1 : -1));
}
// Compare Strings
function RowCompareStrings(a, b) {
var index = b.localeCompare(a);
return index;
}
</script>
<div style="float: right;margin-right: -100px;" class="box2">
<h2>Sort by :</h2>
<input type="radio" id="s1" name="sort" value="1" />
<label for="f1"><?php echo 'Name'?></label>
<input type="radio" id="s1" name="sort" value="1" />
<label for="f1"><?php echo 'Location'?></label>
<br><br><br>
<div id="ContactForm" action="#">
<input name="sort_button" value="Apply" type = "button" id="sort_button" class="button" onclick="SortTable();"/>
</div>
</div>
<table>
<tbody>
while($row = mysqli_fetch_array($result))
{
$name = $row['NAME'];
$img = $row['IMAGE_SRC'];
$addr = $row['ADDRESS'];
$location = $row['LOCATION'];
echo "<script type='text/javascript'>map_function('{$addr}','{$name}','{$img}');</script>";
?>
<tr>
<td>
<a href="<?php echo $name?>">
<img src="<?php echo $img.".jpg"?>" height="100" width="100">
</a>
</td>
<td>
<a href="<?php echo $name?>">
<h3><?php echo $name?></h3>
</a>
<td>
</tr>
<?php
}
?>
</tbody>
</table>
For now, I'm fixing the sorting column number, sortedOn to 1 just to check if its working but to my dismay it is not. I have been trying to get it work since quite some time now. I am relatively new to Javascript and this is my first take on web development. Looking forward to a solution.
Thanks.
If what you want is to sort the rows of a table with javascript, you can implement sortable.js.
http://www.kryogenix.org/code/browser/sorttable/
I would recommend you that convert your query result to Json format using PHP json_encode(), this way you can deal with javascript all data in a more simple way.
Well I was able to figure out my mistake. There were multiple errors in the javascript function. Secondly the in the table was missing for the second column. In the javascript function, basically, I was comparing the rowArray objects themselves in the RowCompareStrings function. I should actually be comapring the rowArray.value with each other.
I have a MySQL database of orders that each have various activities associated with them. My PHP/HTML page pulls down the activities when you click an order and allows the user to change attributes of the activities with a form. On submit another PHP file loops through activities in the table and runs an update query on the database. Works great!
I have recently added a JavaScript function that will add activities to the list (appendChild, createElement...). I then added to my PHP file an INSERT query for the new activities.
The problem is that when I run the update PHP file it is not looping through the newly added records that were added with JavaScript. I checked it by using <?php print $size = count($_POST['FcastID']) ?> and the value doesn't change when records have been added.
The records look fine when added to the table and the id and name convention match the other records. It seems like the page needs to be refreshed before the PHP file runs.
PHP file with dynamically created html form
<div id="submit"><form method="post" action="Up_Forecast.php"><input type="submit" value="Submit"></div>
....
<table id="fcast">
<?
$i=0;
while($row = mysqli_fetch_array($res_fcast))
{
echo "<tr id='fcastRow[$i]'>";
echo "<td class='medium'><input type='text' id='qtyJan[$i]' name='qtyJan[$i]' value='".$row[Jan]."'/></td>";
echo "<td class='medium'><input type='text' id='qtyFeb[$i]' name='qtyFeb[$i]' value='".$row[Feb]."'/></td>";
echo "<td class='medium'><input type='text' id='qtyMar[$i]' name='qtyMar[$i]' value='".$row[Mar]."'/></td>";
echo "<td class='medium'><input type='text' id='qtyApr[$i]' name='qtyApr[$i]' value='".$row[Apr]."'/></td>";
echo "<td class='medium'><input type='text' id='qtyMay[$i]' name='qtyMay[$i]' value='".$row[May]."'/></td>";
echo "<td class='medium'><input type='text' id='qtyJun[$i]' name='qtyJun[$i]' value='".$row[Jun]."'/></td>";
echo "<td class='medium'><input type='text' id='qtyJul[$i]' name='qtyJul[$i]' value='".$row[Jul]."'/></td>";
echo "<td class='medium'><input type='text' id='qtyAug[$i]' name='qtyAug[$i]' value='".$row[Aug]."'/></td>";
echo "<td class='medium'><input type='text' id='qtySep[$i]' name='qtySep[$i]' value='".$row[Sep]."'/></td>";
echo "<td class='medium'><input type='text' id='qtyOct[$i]' name='qtyOct[$i]' value='".$row[Oct]."'/></td>";
echo "<td class='medium'><input type='text' id='qtyNov[$i]' name='qtyNov[$i]' value='".$row[Nov]."'/></td>";
echo "<td class='medium'><input type='text' id='qtyDec[$i]' name='qtyDec[$i]' value='".$row[Dec]."'/></td>";
echo "<td class='medium'><input type='text' id='Totalqty[$i]' name='Totalqty[$i]' value='".$row[Total]."' disabled/></td>";
echo "</tr>";
++$i;
}
?>
<tr><td class="blank"></td><td class="mini"><input type="button" onclick="addRowYear(this)" value="Add"/></td></tr>
</table>
</form>
</div>
Javascript function to add row
function addRowYear(lastRow){
var rowNo = lastRow.parentNode.parentNode.rowIndex;
var newRow = document.getElementById("fcast").insertRow(rowNo);
newRow.setAttribute("id","fcastRow["+rowNo+"]");
var cell0 = newRow.insertCell(0);
cell0.setAttribute("class","mini");
var input0 = document.createElement("input");
input0.setAttribute("type","text");
input0.setAttribute("name","FcastID["+rowNo+"]");
input0.setAttribute("value","new");
cell0.appendChild(input0);
var cell1 = newRow.insertCell(1);
cell1.setAttribute("class","mini");
var input1 = document.createElement("input");
input1.setAttribute("type","text");
input1.setAttribute("name","Fcast_ActID["+rowNo+"]");
input1.setAttribute("id","Fcast_ActID["+rowNo+"]");
cell1.appendChild(input1);
var curAct = document.getElementById("selAct").innerHTML;
document.getElementById("Fcast_ActID["+rowNo+"]").value = curAct;
var cell2 = newRow.insertCell(2);
cell2.setAttribute("class","mini");
var input2 = document.createElement("input");
input2.setAttribute("type","text");
input2.setAttribute("name","Year["+rowNo+"]");
cell2.appendChild(input2);
var month = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
for (var i = 0; i < month.length; i++) {
//alert(month[i]);
x=3;
var cell = newRow.insertCell(x);
cell.setAttribute("class","medium");
var input = document.createElement("input");
input.setAttribute("type","text");
input.setAttribute("class","numbers");
input.setAttribute("name","qty"+month[i]+"["+rowNo+"]");
input.setAttribute("id","qty"+month[i]+"["+rowNo+"]");
input.setAttribute("onkeyup","findTotal()");
cell.appendChild(input);
x=x+1;
}
var cell15 = newRow.insertCell(15);
cell15.setAttribute("class","medium");
var input15 = document.createElement("input");
input15.setAttribute("type","text");
input15.setAttribute("class","numbers");
input15.setAttribute("name","Totalqty["+rowNo+"]");
input15.setAttribute("id","Totalqty["+rowNo+"]");
cell15.appendChild(input15);
PHP Update - Called on Submit of form
$size = count($_POST['FcastID']);
$i = 0
while ($i < $size) {
$FcastID = $_POST['FcastID'][$i];
$ActID = $_POST['Fcast_ActID'][$i];
$Year = $_POST['Year'][$i];
$Jan = $_POST['qtyJan'][$i];
$Feb = $_POST['qtyFeb'][$i];
$Mar = $_POST['qtyMar'][$i];
$Apr = $_POST['qtyApr'][$i];
$May = $_POST['qtyMay'][$i];
$Jun = $_POST['qtyJun'][$i];
$Jul = $_POST['qtyJul'][$i];
$Aug = $_POST['qtyAug'][$i];
$Sep = $_POST['qtySep'][$i];
$Oct = $_POST['qtyOct'][$i];
$Nov = $_POST['qtyNov'][$i];
$Dec = $_POST['qtyDec'][$i];
$Total = $_POST['Totalqty'][$i];
$update = "UPDATE FCAST SET
Year='$Year',
Jan=replace('$Jan',',',''),
Feb=replace('$Feb',',',''),
Mar=replace('$Mar',',',''),
Apr=replace('$Apr',',',''),
May=replace('$May',',',''),
Jun=replace('$Jun',',',''),
Jul=replace('$Jul',',',''),
Aug=replace('$Aug',',',''),
Sep=replace('$Sep',',',''),
Oct=replace('$Oct',',',''),
Nov=replace('$Nov',',',''),
`Dec`=replace('$Dec',',',''),
Total=replace('$Total',',','')
WHERE
FcastID='$FcastID'";
mysqli_query($link, $update);
Without seeing your code, it is difficult to say. Something I have used in the past that works well is the following:
PHP:
foreach($_POST as $key => $value) {
//... $key is name of field, $value is the value
}
This goes through each individual field in the submitted form and reads the value in each. I've used this exact script for dynamically-created forms, and it works great. You have to be careful, though, if you use the same name for different fields, the values will be stored as arrays.
EDIT
HTML:
<form method="post" action="index.php">
<div>
<div>
<p>
<label class="reg_label" for="field_name">Item:</label>
<input class="text_area" name="field_name[]" type="text" id="testing" tabindex="98" style="width: 150px;"/>
</p>
</div>
</div>
<input type="button" id="btnAdd" value="Add" class="someClass1"/>
<input type="button" id="btnDel" value="Remove" class="someClass2" disabled/><br><br>
<input type="submit" id="submit" name="submit" value="Submit">
</form>
JavaScript:
var j = 0;
$(document).ready(function () {
$('.someClass1').click(function (e) {
var num = $(this).prev().children().length;
var newNum = new Number(num + 1);
var newElem = $(this).prev().children(':last').clone().attr('id', 'input' + newNum);
if(newElem.children().children().last().hasClass('otherOption')){
newElem.children().children().last().remove();
}
newElem.children().children().each(function(){
var curName = $(this).attr('name');
var newName = '';
$(this).attr('id', 'name' + num + '_' + j);
j++;
});
newElem.children().children().each(function(){
$(this).removeAttr('value');
});
$(this).prev().children(':last').after(newElem);
$(this).next().removeAttr('disabled');
});
$('.someClass2').click(function (e) {
var num = $(this).prev().prev().children().length;
$(this).prev().prev().children(':last').remove();
if (num - 1 == 1) $(this).attr('disabled', 'disabled');
});
});
It isn't all that important to know how the JavaScript code works. All you need to know is that clicking on the "Add" button will duplicate the field and clicking on "Remove" will remove the most recently added field. Try it out at the link provided.
PHP:
This is where the magic happens…
<?php
if(isset($_POST['submit'])){
foreach($_POST as $name => $item){
if($name != 'submit'){
for($m=0; $m < sizeof($item); $m++){
echo ($name.' '.$item[$m].'<br>');
}
}
}
}
?>
Looks easy enough, right?
This PHP code is within the same file as the form, so first we check to see if the form has been submitted by checking for the name of the submit button if(isset($_POST['submit'])){…}.
If the form has been submitted, go through each submitted item foreach($_POST as $name => $item){…}.
The submit button counts as one of the fields submitted, but we aren't interested in storing that value, so check to make sure the value you are reading in is not from the submit button if($name != 'submit'){…}.
Finally, all the fields within this form have the same name field_name[]. The square brackets are used for multiple items that share the same name. They are then stored in an array. Read through each item within that array for the length of the array for($m=0; $m < sizeof($item); $m++){…} and then do what you'd like with each value. In this case, I've just printed them to the screen echo ($name.' '.$item[$m].'<br>');
Below are a couple screen-shots of the page…
Before submitting the form:
After submitting the form:
You can go to the page and view the code (right click -> View Source), but the PHP will not show up in the source. I assure you that all the PHP used for this is shown above - just the few lines.
If each item has a completely unique name (which you can achieve via JavaScript when adding fields), then you will not need to loop through the array of values (i.e. will not need for($m=0; $m < sizeof($item); $m++){…} block). Instead, you'll likely read the value using simply $item. If you name your fields with the square brackets (i.e. field_name[]), but only have one of that field, then reading a singular value may require $item or $item[0]. In that case you'll just have to test it and see. Some field types behave differently than others (i.e. input, text area, radio buttons, etc).
The Whole Thing
Here is the entire code for index.php - you can just copy and paste it and run it on your own server. Just make sure to change the name of the file in the action attribute <form> tag…
<?php
if(isset($_POST['submit'])){
foreach($_POST as $name => $item){
if($name != 'submit'){
for($m=0; $m < sizeof($item); $m++){
echo ($name.' '.$item[$m].'<br>');
}
}
}
}
?>
<html>
<head>
<script type="text/javascript" src="../scripts/jquery-1.8.2.min.js"></script>
</head>
<body>
<form method="post" action="index.php">
<div>
<div>
<p>
<label class="reg_label" for="field_name">Item:</label>
<input class="text_area" name="field_name[]" type="text" id="testing" tabindex="98" style="width: 150px;"/>
</p>
</div>
</div>
<input type="button" id="btnAdd" value="Add" class="someClass1"/>
<input type="button" id="btnDel" value="Remove" class="someClass2" disabled/><br><br>
<input type="submit" id="submit" name="submit" value="Submit">
</form>
</body>
<script>
var j = 0;
$(document).ready(function () {
$('.someClass1').click(function (e) {
var num = $(this).prev().children().length;
var newNum = new Number(num + 1);
var newElem = $(this).prev().children(':last').clone().attr('id', 'input' + newNum);
if(newElem.children().children().last().hasClass('otherOption')){
newElem.children().children().last().remove();
}
newElem.children().children().each(function(){
var curName = $(this).attr('name');
var newName = '';
$(this).attr('id', 'name' + num + '_' + j);
j++;
});
newElem.children().children().each(function(){
$(this).removeAttr('value');
});
$(this).prev().children(':last').after(newElem);
$(this).next().removeAttr('disabled');
});
$('.someClass2').click(function (e) {
var num = $(this).prev().prev().children().length;
$(this).prev().prev().children(':last').remove();
if (num - 1 == 1) $(this).attr('disabled', 'disabled');
});
});
</script>
</html>
I'm trying to find out how to use one text field in my form to search any columns in my database table.
Right now it is just searching in sn column on my database table named stock.
I need it to search column name sn or user or status.
So, if you type in a serial number and post form it will search my database and bring back results with no problems. But I want to be able to type a user's name or status and search my database that way too. So I was thinking of some how dynamically changing the
Input name="" with maybe radio buttons to change the value to Input name="sn" or Input name="user" or Input name="status" But I'm not sure how to do that. I've been reading others saying with Javascript or JQuery. I would really appreciate any help. Thanks!
I have my recordset to query only sn column. I'm sure I would need to change this too, but I'm not sure how.
The Form
<form id="form1" name="form1" method="get" action="search.php">
<label>
<input type="radio" name="RadioGroup1" value="sn" id="RadioGroup1_0" />
sn</label><br />
<label>
<input type="radio" name="RadioGroup1" value="user" id="RadioGroup1_1" />
User</label>
<br />
<label>
<input type="radio" name="RadioGroup1" value="status" id="RadioGroup1_2" />
Staus</label>
<br />
</p>
<label for="sn"> Search :</label>
<input name="sn" type="text" id="sn" size="25" />
<input name="submit" type="submit" value="submit" />
</form>
The SQL
SELECT *
FROM stock
WHERE sn = colname
ORDER BY `datetime` DES
The Php
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string ($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_Recordset567 = 10;
$pageNum_Recordset567 = 0;
if (isset($_GET['pageNum_Recordset567'])) {
$pageNum_Recordset567 = $_GET['pageNum_Recordset567'];
}
$startRow_Recordset567 = $pageNum_Recordset567 * $maxRows_Recordset567;
$colname_Recordset567 = "-1";
if (isset($_GET['sn'])) {
$colname_Recordset567 = $_GET['sn'];
}
mysql_select_db($database_stock, $stock);
$query_Recordset567 = sprintf("SELECT * FROM stock WHERE sn = %s ORDER BY `datetime` DESC", GetSQLValueString($colname_Recordset567, "text"));
$query_limit_Recordset567 = sprintf("%s LIMIT %d, %d", $query_Recordset567, $startRow_Recordset567, $maxRows_Recordset567);
$Recordset567 = mysql_query($query_limit_Recordset567, $stock) or die(mysql_error());
$row_Recordset567 = mysql_fetch_assoc($Recordset567);
if (isset($_GET['totalRows_Recordset567'])) {
$totalRows_Recordset567 = $_GET['totalRows_Recordset567'];
} else {
$all_Recordset567 = mysql_query($query_Recordset567);
$totalRows_Recordset567 = mysql_num_rows($all_Recordset567);
}
$totalPages_Recordset567 = ceil($totalRows_Recordset567/$maxRows_Recordset567)-1;
?>
the radiobuttons are a good idea... Make sure they all have the same name. Then use php to identify which value belongs to which action. Make sure you secure all data in the input.
You could also use the mysql term OR to search in different columns at once.
Here is your php:
$radioVal = $_POST['radiobtnVal'];
switch $radioVal{
case 1 :
$col = "sn"; //don't directly write to the variable here, since that would make a security risk
break;
case 2 :
$col = "user";
break;
case 3 :
$col = "status";
break;
}
//now make connection to your database
$search = mysqli_real_escape_string($db,$_POST['searchString']); //This will secure your input from mysql injections
//$db is the variable you made during connection with your database
$result = mysqli_query($db,"SELECT * FROM `Stock` WHERE `" . $col . "`='" . $search . "'");
//or use the mentioned OR term
$result = mysqli_query($db,"SELECT * FROM `Stock` WHERE `sn`='" . $search . "' OR `user`='" . $search . "' OR `status`='" . $search . "'");
//Note that if some search strings are in multiple columns all these rows will be selected
I hope this helps
this is a basic way of doing that and its a good user experience.
Try this solution.
FORM
<Form action="search.php" method="post">
<label>Serial</label>
<input name='search' type='text' size='25'/>
<button type='submit'>Search</button>
</form>
PHP
<?php
$search = $_POST['search'];
$searchColumns = array();
//Will add Serial Number if # was found on search
if(!(strpos("#",$search)===FALSE)){
$searchColumns[] = "sn = '{$search}'";
}
//Will add Status to select if there is no spaces in search.
if(count(explode(" ",$search))==1){
$searchColumns[] = "status = '{$search}'";
}
//Will add user to select if its not a Serial search
//And if its has more than 5 chars (change it to your min char username)
if(strpos("#",$search)===FALSE && strlen($search) > 5){
$searchColumns[] = "user = '{$search}'";
}
$sql = "
SELECT *
FROM stock
WHERE ".(implode(" AND ",$searchColumns))."
ORDER BY datetime DES";
?>