<table border=0 cellpadding=5 cellspacing=0 width="100%" id="userInvtable">
<thead>
<tr>
<th valign="top" width="16" align="center" class="no_sort"><img src="images/cross.png" /><br /><a href="javascript:void(0);" onClick="javascript: checkAll();" id="chk_txt" style="font-size: 8pt;">(check all)</a></td>
<th valign="top">Part Number</th>
<th valign="top">Alt P/N#<br>or<br>NSN P/N#</th>
<th valign="top">Condition<br>Code</th>
<th valign="top">Quantity</td>
<th valign="top">Description</td>
<th valign="top">Last Updated</td>
</tr>
</thead>
{foreach from=$inventory item=inv}
<tr bgColor="{cycle name="cycle1" values="#f7f6f1,#BEC3E3"}">
<td align="center"><input type="checkbox" name="delete[]" value="{$inv.inventory_id}"></td>
<td><a href="account.php?mode=edit&id={$inv.inventory_id}">{$inv.inventory_part_number|stripslashes}</a></td>
<td>{$inv.inventory_alt_part_number|stripslashes}</td>
<td>{$inv.inventory_condition_code|stripslashes}</td>
<td>{$inv.inventory_quantity|stripslashes}</td>
<td>{$inv.inventory_description|stripslashes}</td>
<td>{$inv.last_update|date_format}</td>
</tr>
{/foreach}
</table>
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
require_once "libs/Core.php";
$db = new Database;
$id = $_SESSION['user_id'];
/*
<td align="center"><input type="checkbox" name="delete[]" value="{$inv.inventory_id}"></td>
<td><a href="account.php?mode=edit&id={$inv.inventory_id}">{$inv.inventory_part_number|stripslashes}</a></td>
<td>{$inv.inventory_alt_part_number|stripslashes}</td>
<td>{$inv.inventory_condition_code|stripslashes}</td>
<td>{$inv.inventory_quantity|stripslashes}</td>
<td>{$inv.inventory_description|stripslashes}</td>
<td>{$inv.last_update|date_format}</td>
*/
$aColumns = array('i.inventory_id', 'i.inventory_part_number', 'i.inventory_alt_part_number', 'i.inventory_condition_code',
'i.inventory_quantity', 'i.inventory_description', 'i.last_update');
/*
* Paging
*/
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) {
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/*
* Ordering
*/
if ( isset( $_GET['iSortCol_0'] ) ) {
$sOrder = "ORDER BY ";
for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ ) {
if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ) {
$sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
}
}
$sOrder = substr_replace( $sOrder, "", -2 );
if ( $sOrder == "ORDER BY" ) {
$sOrder = "";
}
}
/*
* Filtering
* NOTE this does not match the built-in DataTables filtering which does it
* word by word on any field. It's possible to do here, but concerned about efficiency
* on very large tables, and MySQL's regex functionality is very limited
*/
$sWhere = "WHERE i.user_id = ".$id;
if ( $_GET['sSearch'] != "" ) {
$sWhere = " AND (";
for ( $i=0 ; $i<count($aColumns) ; $i++ ) {
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
}
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
}
/* Individual column filtering */
for ( $i=0 ; $i<count($aColumns) ; $i++ ) {
if ( $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' ) {
if ( $sWhere == "" ) {
$sWhere = "WHERE ";
} else {
$sWhere .= " AND ";
}
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
}
}
/*
* SQL queries
* Get data to display
*/
$sQuery = "SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM linv_inventory i
$sWhere
$sOrder
$sLimit";
$rResult = $db->query($sQuery) or die(mysql_error());
/* Data set length after filtering */
$sQuery = "SELECT FOUND_ROWS()";
$rResultFilterTotal = $db->query($sQuery) or die(mysql_error());
$aResultFilterTotal = $db->fetchArray($rResultFilterTotal);
$iFilteredTotal = $aResultFilterTotal[0];
/* Total data set length */
$sQuery = "SELECT COUNT(inventory_id) FROM linv_inventory";
$rResultTotal = $db->query($sQuery) or die(mysql_error());
$aResultTotal = $db->fetchArray($rResultTotal);
$iTotal = $aResultTotal[0];
/* Output */
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = $db->fetchArray( $rResult ) ) {
$row = array();
foreach($aColumns as $name=> $value) {
$row[] = $aRow[$name];
}
$output['aaData'][] = $row;
}
echo json_encode( $output );
?>
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$('td:eq(0)', nRow).html('<input type="checkbox" name="delete[]" value="'+aData[0]+'">');
$('td:eq(0)').css('align', 'center');
return nRow;
}
"aoColumnDefs": [{ "sClass": "center", "aTargets": [ 0 ] }],
It looks like you're new here. If you want to get involved, click one of these buttons!
Get useful and friendly help straight from the source.