I have a database
that have two tables.
The sql query fetching data correctly.
I want to sort fields data by typing table heading in text box and click on go that in table footer.
Many Thanks
<table border="0" cellpadding="0" cellspacing="0" width="50%">
<thead>
<tr>
<th class="capt" colspan="6">Available Projects</th>
</tr>
<tr>
<th>Select</th>
<th>Project</th>
<th>Crawler</th>
<th>Description</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
include(dirname(__file__)."/includes/dbConn.php");
$result = mysql_query("SELECT *, ( SELECT name FROM projects WHERE projects.id = crawlers.pid ) AS pname FROM `crawlers`", $appConn);
while($row = mysql_fetch_array($result))
{
?>
<tr id="crawler_<?php echo $row['id']; ?>">
<td>
<input value="" id="check" type="checkbox">
<input id="crawler_id_<?php echo $row['id']; ?>" type="hidden" value="<?php $row['id']; ?>" /> <!-- crawler id -->
</td>
<td><?php echo $row['pname']; ?></td>
<td><?php echo $row['name']; ?></td>
<td>username#domain.com</td>
<td>Enabled</td>
<td><a class="edit" href="#">edit</a><a class="add" href="#">run</a><a class="delete" href="#">delete</a></td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th colspan="6"> Sort Fields by <input value="type here" id="field" type="text"> Go </th>
</tr>
</tfoot>
</table>
I think, you are looking for ORDER BY
Have a look at the MySQL Documentation about the SELECT syntax: http://dev.mysql.com/doc/refman/5.0/en/select.html
Related
Table name :- add_user
data is inserting in it, there is a column due_date storing date in (dd-mm-yyyy) format
now i want to create a filter for due_date. But my code is not working. When i'm running the code it is showing all data, it is not filtering it.
here is my code
<form class="form-inline" method="post" action="">
<label> <b>From Date : </b></label>
<input type="date" name="s_date" class="form-control">
<input type="date" name="e_date" class="form-control">
<button type="submit" name="search" class="btn btn-success">Search</button>
</form>
<?php
error_reporting(0);
include_once "config2.php";
if(count($_POST)>0) {
$s_date=date("dd-mm-yyyy", strtotime($_POST['s_date']));
$e_date=date("dd-mm-yyyy", strtotime($_POST['e_date']));
$result = mysqli_query($conn,"SELECT * FROM add_user WHERE due_date BETWEEN '$s_date' AND '$e_date'");
}
?>
<center>
<table class='table table-bordered'>
<thead class="thead-dark">
<tr>
<th>Action</th>
<th>Pet Photo</th>
<th>Owner</th>
<th>Mobile Number</th>
<th>Category</th>
<th>Pet Id</th>
<th>Pet Name</th>
<th>Address</th>
</tr>
<?php
$i=0;
while($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><button class="btn btn-info">View</button></td>
<td><img src="/pet_img/<?php echo $row["signature"]; ?>"width="60px"height="80px"> </td>
<td><img src="/pet_img/<?php echo $row["photo"]; ?>"width="60px"height="80px"> <br><b> <?php echo $row["name"]; ?> </td>
<td><?php echo $row["mobile"]; ?></td>
<td><?php echo $row["type"]; ?></td>
<td><b><font color="green"><?php echo $row["pet_id"]; ?></font></b></td>
<td><?php echo $row["pet_name"]; ?></td>
<td><?php echo $row["add1"]; ?> <?php echo $row["add2"]; ?> <?php echo $row["add3"]; ?> <?php echo $row["pin"]; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
</body>
</html>
Your column data type needs to be either timestamp or date/datetime. You can't compare date strings in this format.
I am buildingd a library management system in PHP and HTMl.
I have some problem with the borrowing system where user can borrow books.
Here is my emitere-carti.php:
<form action="imprumutare.php" method="POST">
<table class="table table-dark">
<thead>
<tr>
<th>Imprumutare</th>
<th scope="col">Titlu </th>
<th scope="col">Autor</th>
<th scope="col">Categorie</th>
<th scope="col">Stoc</th>
</tr>
</thead>
<tbody>
<?php
$selectare="SELECT * FROM carti";
$rezultat=mysqli_query($conn,$selectare);
if(mysqli_num_rows($rezultat)>0){
while($row=mysqli_fetch_assoc($rezultat)){
$carte_nume=$row['titlu'];
$disabled=$row['stoc']>0 ? "" :"disabled";
?>
<tr>
<td><input type="submit" name="test" class="btn btn-secondary"
value="Imprumutare" <?php echo $disabled;?>></input>
<td><input type="text" name="nume" value="<?php echo $row['titlu'];?
>"></input></td>
<td><?php echo $row['autor'];?></td>
<td><?php echo $row['categorie'];?></td>
<td><?php echo $row['stoc'];?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</form>
Here is my imprumutare.php(that means borrowing):
include('conexiune.php');
//sfarsit if
//Imprumutare
if(isset($_POST['test'])){
$id=$_POST['identificator'];
$nume_carte=$_POST['nume'];
$sql_rezervare="UPDATE carti SET stoc=stoc-1 WHERE
titlu='$nume_carte' ";
if( mysqli_query($conn,$sql_rezervare)){
header('location:emitere_carti.php');
}
else{
die(mysqli_error($conn));
}
}
Here is a screenshot about what I am talking:
So my problem is both buttons are decrementeing the same value(the value of stoc).
Can someone help me?
I am trying to sort the output of the echo data that i am trying to bring from mysql database. There are different rows in the table and i want to sort by one of the rows named city. But it is showing data has last in first out. The code is here:
<?=APP::getElement()->triggerMessage(); ?>
<div class="panel">
<?php include_once(APP_HTML.'sub_menu.php');
$data=$model->data['data'];
// echo"<pre>";
// print_r($data);
?>
</div>
<?php include_once('search.php'); ?>
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">All County</div>
<form name="List" id="List" class="form-horizontal" role="form" method="post" action="<?php echo $base_url.'delete';?>">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th><input type="checkbox" id="checkAll" name="checkAll" class="selectAll" /></th>
<th>County Name</th>
<!--<th> Parent County</th>
<th> County Status</th>-->
<!--<th> Product Type</th>
<th> Model No.</th>
<th> Image</th>
<th> Description</th>-->
<!-- <th>Country Name</th> -->
<th>Added Date</th>
<th>Updated Date</th>
<!-- <th>Weightage</th> -->
<th>Status</th>
<th width="12%">Action</th>
</tr>
</thead>
<tbody>
<?php
$pagination=$model->data['pagination'];
foreach($data as $row){
// echo $row['project_name'];
?>
<tr>
<td><input type="checkbox" id="id" name="id[]" class="checkID" value="<?php echo $row['id']; ?>"/></td>
<td><?php echo $row['city'] ?></td>
<td><?php echo $row['added_date']; ?></td>
<td><?php echo $update = empty($row['updated_date'])?'N/A':$row['updated_date']; ?></td>
<td><?php echo APP::getElement()->getStatus($row['status']); ?></td>
<td>
<?php $fields=array('update','delete','status'); ?>
<?=APP::getElement()->getActionButton($fields,$row);?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
</div>
<?php echo $pagination; ?>
please help.
Try to put ORDER BY in your SQL query.
Documentation
I have a table with multiple columns (index.php). One column is a checkbox. Whenever the checkbox is checked, it displays another row where you can select a quantity. You can then hit a button called "Add to Order" and it will take you to a confirmation page (index-order.php) where I want it to display each row along with all of the data in that specified row that has the checkbox checked. Currently, I am getting no errors in my console, but no data is being displayed at all.
What do I need to change to make this happen? Here is what I have so far.
Index.php code:
<form name="form1" method="POST" action="index-order.php">
<section id="addToOrder">
<button type="submit" class="order" id="order" name="order" value="AddToOrder">Add to Order</button>
</section>
<br>
<div id="my-div2" class="ui-widget">
<div class="ui-widget">
<table id="merchTable" cellspacing="5" class="sortable">
<thead>
<tr class="ui-widget-header">
<th class="sorttable_nosort"></th>
<th class="sorttable_nosort">Loc</th>
<th class="merchRow">Report Code</th>
<th class="merchRow">SKU</th>
<th class="merchRow">Special ID</th>
<th class="merchRow">Description</th>
<th class="merchRow">Quantity</th>
<th class="sorttable_nosort">Unit</th>
<th style="display: none;" class="num">Quantity #</th>
</tr>
</thead>
<tbody>
<?php foreach ($dbh->query($query) as $row) {?>
<tr>
<td class="ui-widget-content"><input type="checkbox" class="check" name="check"></td>
<td name="rows[0][0][loc]" class="loc ui-widget-content" id="loc-<?php echo intval ($row['Loc'])?>"><?php echo $row['Loc'];?></td>
<td name="rows[0][0][rp-code]" class="rp-code ui-widget-content" align="center" id="rp-code-<?php echo intval ($row['Rp-Code'])?>"><?php echo $row['Rp-Code'];?></td>
<td name="rows[0][0][sku]" class="sku ui-widget-content" id="sku-<?php echo intval ($row['SKU'])?>"><?php echo $row['SKU'];?></td>
<td name="rows[0][0][special-id]" class="special-id ui-widget-content" align="center" id="special-id-<?php echo intval ($row['Special-ID'])?>"><?php echo $row['Special-ID'];?></td>
<td name="rows[0][0][description]" class="description ui-widget-content" id="description-<?php echo intval ($row['Description'])?>"><?php echo $row['Description'];?></td>
<td name="rows[0][0][quantity]" class="quantity ui-widget-content" data-quantity="<?php echo $row['Quantity'] ?>" align="center" id="quantity-<?php echo intval ($row['Quantity'])?>"><?php echo $row['Quantity'];?></td>
<td name="rows[0][0][unit]" class="unit ui-widget-content" id="unit-<?php echo intval ($row['Unit'])?>"><?php echo $row['Unit'];?></td>
<td name="rows[0][0][quant]" style="display: none;" class="quantity_num ui-widget-content"><input type="textbox" style="width: 100px;" class="spinner" name="value" id="test"></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</form>
Index-order.php:
<?php if(isset($_POST['rows'])): ?>
<table cellspacing="20">
<tr align="center">
<th>Loc</th>
<th>Report Code</th>
<th>SKU</th>
<th>Special ID</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit</th>
<th>Quantity #</th>
</tr>
<?php
foreach($_POST['rows'][0] as $row):
?>
<tr align="center">
<td><?php echo $row['loc']; ?></td>
<td><?php echo $row['rp-code']; ?></td>
<td><?php echo $row['sku']; ?></td>
<td><?php echo $row['special-id']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quant']; ?></td>
</tr>
<?php
endforeach;
?>
</table>
I am okay with the precedent answer, I never heard about this kind of method with PHP and it doesn't seems to be the right solution. Anyway, the following post would maybe help you : How to get value from td's via $_POST.
You cannot transfer datas through POST by using td ; but an alternative would be to use the "hidden" type of forms element :
<form action="script.php" method="post">
<td class=".."><input type="hidden" name="td1" value="...">value</td>
...
</form>
In PHP, you'll grab the data with the $_POST array and the td1 name :
<?php var_dump($_POST); ?>
Itwould in my opinion be the easier way to get what you want in a proper way ; the link I gave upper is also talking about DOMDocument, but it looks more complex to manage with.
I am having trouble when bootstrap table is installed. When I use data-toggle="table" to activate bootstrap I am not able to post checked value it always display NULL that means it is not checked . If I create normal table everything works great.
Does anyone know how to solve this issue, is this a bug?
<form method="post" action="unos.php">
<button type="submit" class="btn btn-primary" name="izmjena">Izmjena</button>
<table data-toggle="table" data-show-columns="true" data-click-to-select="true"
data-search="true" data-show-refresh="true" data-show-export="true" >
<tr>
<th data-field="artikli" data-checkbox="true" name="artikli"> </th>
<th data-field="sifra" data-sortable="true">Sifra</th>
<th data-field="name" data-sortable="true">Naziv</th>
</tr>
$q = $conn->query($sql);
while ($r = $q->fetch()): ?>
<tr>
<td><input type="checkbox" name="artikli" value="<?php echo $r['ArtId'];?>"></td>
<td><?=$r['ArtSifra'] ?></td>
<td><?=$r['ArtNaziv'] ?></td>
</tr>
<?php endwhile; ?>
</table>
</form>
// unos.php file
if (isset($_POST["izmjena"])) {
$id=(!empty($_POST["artikli"])) ? $_POST["artikli"] : '';
var_dump($id);
echo $id;
}