Not Able to access MySQL data through php function - php
I've added clients in clients.php sown on the following screenshot:
UPDATE: If I add new client from manange_sale page, The List Shows up soon after!
When I try to access them in another page through this function:
function get_client_info($client_id, $term) {
global $db;
$query = "SELECT * from clients WHERE client_id='".$client_id."'";
$result = $db->query($query) or die($db->error);
$row = $result->fetch_array();
return $row[$term];
}
It just does not show any clients list on that page:
Please help me resolve this issue.
Note: Same script is working perfectly on Online host but causing issues in localhost.
Rest of the client class:
<?php
//Notes Class
class Client {
public $full_name;
public $business_title;
public $mobile;
public $phone;
public $address;
public $city;
public $state;
public $zipcode;
public $country;
public $email;
public $price_level;
public $notes;
function get_client_info($client_id, $term) {
global $db;
$query = "SELECT * from clients WHERE client_id='".$client_id."'";
$result = $db->query($query) or die($db->error);
$row = $result->fetch_array();
return $row[$term];
}//get user email ends here.
function add_client($full_name, $business_title, $mobile, $phone, $address, $city, $state, $zipcode, $country, $email, $price_level, $notes) {
global $db;
$query = "SELECT * from clients WHERE full_name='".$full_name."' AND store_id='".$_SESSION['store_id']."'";
$result = $db->query($query) or die($db->error);
$num_rows = $result->num_rows;
if($num_rows > 0) {
return 'A client with same name already exists.';
} else {
$query = "INSERT into clients(client_id, full_name, business_title, mobile, phone, address, city, state, zipcode, country, email, price_level, notes, store_id)
VALUES(NULL, '".$full_name."', '".$business_title."', '".$mobile."', '".$phone."', '".$address."', '".$city."', '".$state."', '".$zipcode."', '".$country."', '".$email."', '".$price_level."', '".$notes."', '".$_SESSION['store_id']."')
";
$result = $db->query($query) or die($db->error);
$_SESSION['cn_id'] = $db->insert_id;
return 'Client added successfuly.';
}
}//add warehouse ends here.
function set_client($client_id) {
global $db;
$query = 'SELECT * from clients WHERE client_id="'.$client_id.'" AND store_id="'.$_SESSION['store_id'].'"';
$result = $db->query($query) or die($db->error);
$row = $result->fetch_array();
extract($row);
$this->full_name = $full_name;
$this->business_title = $business_title;
$this->mobile = $mobile;
$this->phone = $phone;
$this->address = $address;
$this->city = $city;
$this->state = $state;
$this->zipcode = $zipcode;
$this->country = $country;
$this->email = $email;
$this->price_level = $price_level;
$this->notes = $notes;
}//Set Warehouse ends here..
function update_client($client_id, $full_name, $business_title, $mobile, $phone, $address, $city, $state, $zipcode, $country, $email, $price_level, $notes) {
global $db;
$query = 'UPDATE clients SET
full_name = "'.$full_name.'",
business_title = "'.$business_title.'",
mobile = "'.$mobile.'",
phone = "'.$phone.'",
address = "'.$address.'",
city = "'.$city.'",
state = "'.$state.'",
zipcode = "'.$zipcode.'",
country = "'.$country.'",
email = "'.$email.'",
price_level = "'.$price_level.'",
notes = "'.$notes.'"
WHERE client_id="'.$client_id.'" AND store_id="'.$_SESSION['store_id'].'"';
$result = $db->query($query) or die($db->error);
return 'Client updated Successfuly!';
}//update user level ends here.
function list_clients() {
global $db;
$query = 'SELECT * from clients WHERE store_id="'.$_SESSION['store_id'].'" ORDER by full_name ASC';
$result = $db->query($query) or die($db->error);
$content = '';
$count = 0;
while($row = $result->fetch_array()) {
extract($row);
$count++;
if($count%2 == 0) {
$class = 'even';
} else {
$class = 'odd';
}
$content .= '<tr class="'.$class.'">';
$content .= '<td>';
$content .= $client_id;
$content .= '</td><td>';
$content .= $full_name;
$content .= '</td><td>';
$content .= $business_title;
$content .= '</td><td>';
$content .= $mobile;
$content .= '</td><td>';
$content .= $phone;
$content .= '</td><td>';
$content .= $address.' '.$city.' '.$state.' '.$zipcode.' '.$country;
$content .= '</td><td>';
$content .= $email;
$content .= '</td><td>';
$content .= $price_level;
$content .= '</td><td>';
$content .= currency_format($this->get_client_balance($client_id));
$content .= '</td>';
if(partial_access('admin')) {
$content .= '<td><form method="post" name="edit" action="manage_client.php">';
$content .= '<input type="hidden" name="edit_client" value="'.$client_id.'">';
$content .= '<input type="submit" class="btn btn-default btn-sm" value="Edit">';
$content .= '</form>';
$content .= '</td><td>';
$content .= '<form method="post" name="delete" onsubmit="return confirm_delete();" action="">';
$content .= '<input type="hidden" name="delete_client" value="'.$client_id.'">';
$content .= '<input type="submit" class="btn btn-default btn-sm" value="Delete">';
$content .= '</form>';
$content .= '</td>';
}
$content .= '</tr>';
unset($class);
}//loop ends here.
echo $content;
}//list_notes ends here.
function delete_client($client_id) {
global $db;
$query = "SELECT * FROM customer_log WHERE client_id='".$client_id."'";
$result = $db->query($query) or die($db->error);
$num_rows = $result->num_rows;
if($num_rows > 0) {
return 'Please delete sale invoices, receivings, return invoices, return payments for related client first.';
} else {
$query = "DELETE FROM clients WHERE client_id='".$client_id."'";
$result = $db->query($query) or die($db->error);
return 'Client deleted successfuly!';
}
}//delete client ends here.
function client_options($client_id) {
global $db;
$query = 'SELECT * from clients WHERE store_id="'.$_SESSION['store_id'].'" ORDER by full_name ASC';
$result = $db->query($query) or die($db->error);
$options = '';
if($client_id != '') {
while($row = $result->fetch_array()) {
if($client_id == $row['client_id']) {
$options .= '<option selected="selected" value="'.$row['client_id'].'">'.$row['full_name'].' ('.$row['mobile'].')</option>';
} else {
$options .= '<option value="'.$row['client_id'].'">'.$row['full_name'].' ('.$row['mobile'].')</option>';
}
}
} else {
while($row = $result->fetch_array()) {
$options .= '<option value="'.$row['client_id'].'">'.$row['full_name'].' ('.$row['mobile'].')</option>';
}
}
return $options;
}//vendor options ends here.
function add_log($datetime, $client_id, $transaction_type, $type_table_id) {
global $db;
$query = "INSERT into customer_log(customer_log_id, datetime, client_id, transaction_type, type_table_id, store_id) VALUES(NULL, '".$datetime."', '".$client_id."', '".$transaction_type."', '".$type_table_id."', '".$_SESSION['store_id']."')";
$result = $db->query($query) or die($db->error);
return $db->insert_id;
}//add log ends here.
function add_receiving($date, $method, $ref_no, $memo, $amount, $client_id) {
global $db;
$query = "INSERT into receivings(receiving_id, datetime, method, ref_no, memo, amount, client_id, agent_id, store_id) VALUES(NULL, '".$date."', '".$method."', '".$ref_no."', '".$memo."', '".$amount."', '".$client_id."', '".$_SESSION['user_id']."', '".$_SESSION['store_id']."')";
$result = $db->query($query) or die($db->error);
return $db->insert_id;
}//add_payment ends here.
function add_return_payment($date, $method, $ref_no, $memo, $amount, $client_id) {
global $db;
$query = "INSERT into sale_return_payment(return_payment_id, datetime, method, ref_no, memo, amount, client_id, agent_id, store_id) VALUES(NULL, '".$date."', '".$method."', '".$ref_no."', '".$memo."', '".$amount."', '".$client_id."', '".$_SESSION['user_id']."', '".$_SESSION['store_id']."')";
$result = $db->query($query) or die($db->error);
return $db->insert_id;
}//add_payment ends here.
function get_client_balance($client_id) {
global $db;
$creditQuery = "SELECt * from creditors WHERE client_id='".$client_id."' AND store_id='".$_SESSION['store_id']."'";
$creditResult = $db->query($creditQuery) or die($db->error);
$receiveable = 0;
while($creditRow = $creditResult->fetch_array()) {
$receiveable += $creditRow['receiveable'];
if($creditRow['receiveable'] == 0) {
$receiveable -= $creditRow['received'];
}
}
$receivingQuery = "SELECt * from receivings WHERE client_id='".$client_id."' AND store_id='".$_SESSION['store_id']."'";
$receivingResult = $db->query($receivingQuery) or die($db->error);
while($recevingRow = $receivingResult->fetch_array()) {
$receiveable -= $recevingRow['amount'];
}
$sale_return_payment = "SELECt * from sale_return_payment WHERE client_id='".$client_id."' AND store_id='".$_SESSION['store_id']."'";
$sale_payment_result = $db->query($sale_return_payment) or die($db->error);
while($sale_return_row = $sale_payment_result->fetch_array()) {
$receiveable -= $sale_return_row['amount'];
}
return $receiveable;
}//get vendor balance ends here.
function list_receivings() {
global $db;
$query = 'SELECT * from receivings WHERE store_id="'.$_SESSION['store_id'].'" ORDER by receiving_id DESC';
$result = $db->query($query) or die($db->error);
$content = '';
while($row = $result->fetch_array()) {
extract($row);
$datetime = strtotime($datetime);
$date = date('d-M-Y', $datetime);
$client = $this->get_client_info($client_id, 'full_name');
$user = new Users;
$agent = $user->get_user_info($agent_id, 'first_name').' '.$user->get_user_info($agent_id, 'last_name');
$content .= '<tr><td>';
$content .= $receiving_id;
$content .= '</td><td>';
$content .= $date;
$content .= '</td><td>';
$content .= $method;
$content .= '</td><td>';
$content .= $ref_no;
$content .= '</td><td>';
$content .= $agent;
$content .= '</td><td>';
$content .= $client;
$content .= '</td><td>';
$content .= $memo;
$content .= '</td><td>';
$content .= $amount;
$content .= '</td>';
if(partial_access('admin')) {
$content .= '<td><form method="post" name="delete" onsubmit="return confirm_delete();" action="">';
$content .= '<input type="hidden" name="delete_receiving" value="'.$receiving_id.'">';
$content .= '<input type="submit" class="btn btn-default btn-sm" value="Delete">';
$content .= '</form>';
$content .= '</td>'; }
$content .= '</tr>';
unset($class);
}//loop ends here.
echo $content;
}//list_notes ends here.
function delete_receiving($receiving_id) {
global $db;
$query = "DELETE from receivings WHERE receiving_id='".$receiving_id."'";
$result = $db->query($query) or die($db->error);
$query = "DELETE from customer_log WHERE transaction_type='Sale Receiving' AND type_table_id='".$receiving_id."'";
$result = $db->query($query) or die($db->error);
$query = "DELETE from customer_log WHERE transaction_type='Receiving' AND type_table_id='".$receiving_id."'";
$result = $db->query($query) or die($db->error);
return 'Receiving deleted Successfuly.';
}//delete_purchase return receiving.
function list_return_payments() {
global $db;
$query = 'SELECT * from sale_return_payment WHERE store_id="'.$_SESSION['store_id'].'" ORDER by return_payment_id DESC';
$result = $db->query($query) or die($db->error);
$content = '';
while($row = $result->fetch_array()) {
extract($row);
$datetime = strtotime($datetime);
$date = date('d-M-Y', $datetime);
$client = $this->get_client_info($client_id, 'full_name');
$user = new Users;
$agent = $user->get_user_info($agent_id, 'first_name').' '.$user->get_user_info($agent_id, 'last_name');
$content .= '<tr><td>';
$content .= $return_payment_id;
$content .= '</td><td>';
$content .= $date;
$content .= '</td><td>';
$content .= $method;
$content .= '</td><td>';
$content .= $ref_no;
$content .= '</td><td>';
$content .= $agent;
$content .= '</td><td>';
$content .= $client;
$content .= '</td><td>';
$content .= $memo;
$content .= '</td><td>';
$content .= $amount;
$content .= '</td>';
if(partial_access('admin')) {
$content .= '<td><form method="post" name="delete" onsubmit="return confirm_delete();" action="">';
$content .= '<input type="hidden" name="delete_sale_return_payment" value="'.$return_payment_id.'">';
$content .= '<input type="submit" class="btn btn-default btn-sm" value="Delete">';
$content .= '</form>';
$content .= '</td>'; }
$content .= '</tr>';
}//loop ends here.
echo $content;
}//list_notes ends here.
function delete_sale_return_payment($return_payment_id) {
global $db;
$query = "DELETE from sale_return_payment WHERE return_payment_id='".$return_payment_id."'";
$result = $db->query($query) or die($db->error);
$query = "DELETE from customer_log WHERE transaction_type='Sale Return Refund' AND type_table_id='".$return_payment_id."'";
$result = $db->query($query) or die($db->error);
return 'Return Payment deleted Successfuly.';
}//delete_purchase return receiving.
function clear_creditors($amount, $client_id){
global $db;
$query = "SELECT * FROM creditors WHERE client_id='".$client_id."' ORDER by credit_id ASC";
$result = $db->query($query) or die($db->error);
while($row = $result->fetch_array()) {
extract($row);
if($receiveable == 0 || $receiveable == $received || $amount == 0) {
//do nothing.
} else {
if($received == 0) {
if($amount < $receiveable) {
$receive = $amount;
} else {
$receive = $receiveable;
}
$query_up = "UPDATE creditors SET
received = '".$receive."'
WHERE credit_id='".$credit_id."'
";
$amount -= $receive;
} else if($received != 0) {
$difference = $receiveable-$received;
if($amount < $difference) {
$receive = $amount+$received;
} else {
$receive = $difference+$received;
}
$query_up = "UPDATE creditors SET
received = '".$receive."'
WHERE credit_id='".$credit_id."'
";
$amount -= $difference;
}
$result_up = $db->query($query_up) or die($db->error);
}//main if ends here.
}//main loop ends.
}//debts clear ends here.--
function customers_balance_summary() {
global $db;
$query = "SELECT * FROM clients WHERE store_id='".$_SESSION['store_id']."' ORDER by full_name ASC";
$result = $db->query($query) or die($db->error);
$content = '';
$grand_total = 0;
while($row = $result->fetch_array()) {
extract($row);
//getting balance.
$balance = $this->get_client_balance($client_id);
$grand_total += $balance;
$content .= '<tr><td>';
$content .= $full_name;
$content .= '</td><td>';
$content .= $business_title;
$content .= '</td><td align="right">';
$content .= currency_format($grand_total);
$content .= '</td></tr>';
}
$new_store = new Store;
$currency = $new_store->get_store_info($_SESSION['store_id'], 'currency');
$content .= '<tr><th colspan="2" align="right">Grand Total</th><th align="right">'.$currency.' '.currency_format($grand_total).'</tH></tr>';
echo $content;
}//customers balance summary ends here.
function customer_ledger_summary($client) {
global $db;
$query = "SELECT * from customer_log WHERE client_id='".$client."' ORDER by customer_log_id ASC";
$result = $db->query($query) or die($db->error);
$balance = 0;
$content = '';
$balance = 0;
while($row = $result->fetch_array()) {
extract($row);
$datetime = strtotime($datetime);
$date = date('d-M-Y', $datetime);
$content .= '<tr><td>';
$content .= $transaction_type;
$content .= '</td><td>';
$content .= $date;
$content .= '</td><td>';
$content .= $type_table_id;
$content .= '</td><td>';
if($transaction_type == 'Sale Invoice' || $transaction_type == 'Cash Sale') {
//Invoice Details.
$sale_query = "SELECT * from sales WHERE sale_id='".$type_table_id."'";
$sale_result = $db->query($sale_query) or die($db->error);
while($sale_row = $sale_result->fetch_array()) {
$content .= $sale_row['memo'];
$content .= '</td><td>';
}
$sale_detail_query = "SELECT * from sale_detail WHERE sale_id='".$type_table_id."'";
$sale_detail_result = $db->query($sale_detail_query) or die($db->error);
$invoice_total = 0;
while($sale_detail_row = $sale_detail_result->fetch_array()) {
$credit_query = "SELECT * from creditors WHERE credit_id='".$sale_detail_row['credit_id']."'";
$credit_result = $db->query($credit_query) or die($db->error);
while($credit_row = $credit_result->fetch_array()) {
$invoice_total += $credit_row['receiveable'];
}
}
$balance = $invoice_total+$balance;
$content .= currency_format($invoice_total);
$content .= '</td><td>';
$content .= currency_format($balance);
$content .= '</td></tr>';
} else if($transaction_type == 'Sale Receiving' || $transaction_type == 'Receiving') {
//Cash receivign.
$receiving_query = "SELECT * from receivings WHERE receiving_id='".$type_table_id."'";
$receiving_result = $db->query($receiving_query) or die($db->error);
while($receiving_row = $receiving_result->fetch_array()) {
$content .= $receiving_row['memo'];
$content .= '</td><td>';
$balance = $balance-$receiving_row['amount'];
$content .= '('.currency_format($receiving_row['amount']).')';
$content .= '</td><td>';
$content .= currency_format($balance);
$content .= '</td></tr>';
}
} else if($transaction_type == 'Invoice Return' || $transaction_type == 'Sale Return') {
//sale return invoice.
$sale_query = "SELECT * from sale_returns WHERE sale_rt_id='".$type_table_id."'";
$sale_result = $db->query($sale_query) or die($db->error);
while($sale_row = $sale_result->fetch_array()) {
$content .= $sale_row['memo'];
$content .= '</td><td>';
}
$sale_detail_query = "SELECT * from sale_return_detail WHERE sale_rt_id='".$type_table_id."'";
$sale_detail_result = $db->query($sale_detail_query) or die($db->error);
$invoice_total = 0;
while($sale_detail_row = $sale_detail_result->fetch_array()) {
$credit_query = "SELECT * from creditors WHERE credit_id='".$sale_detail_row['credit_id']."'";
$credit_result = $db->query($credit_query) or die($db->error);
while($credit_row = $credit_result->fetch_array()) {
$invoice_total += $credit_row['received'];
}
}
$balance = $balance-$invoice_total;
$content .= '('.currency_format($invoice_total).')';
$content .= '</td><td>';
$content .= currency_format($balance);
$content .= '</td></tr>';
} else if($transaction_type == 'Sale Return Refund') {
//sale Return Payment.
$receiving_query = "SELECT * from sale_return_payment WHERE return_payment_id='".$type_table_id."'";
$receiving_result = $db->query($receiving_query) or die($db->error);
while($receiving_row = $receiving_result->fetch_array()) {
$content .= $receiving_row['memo'];
$content .= '</td><td>';
$balance = $balance+$receiving_row['amount'];
$content .= currency_format($receiving_row['amount']);
$content .= '</td><td>';
$content .= currency_format($balance);
$content .= '</td></tr>';
}
}
}//main loop ends here.
echo $content;
}//customer ledger summary ends here.
}//class ends here.
The shown screen code where this class functions are being used:
`
<?php
include('system_load.php');
//This loads system.
//user Authentication.
authenticate_user('subscriber');
//creating company object.
if(partial_access('admin') || $store_access->have_module_access('sales')) {} else {
HEADER('LOCATION: store.php?message=products');
}
if(!isset($_SESSION['store_id']) || $_SESSION['store_id'] == '') {
HEADER('LOCATION: stores.php?message=1');
} //select company redirect ends here.
if(isset($_POST['edit_purchase'])){ $page_title = 'Edit Sale'; } else { $page_title = 'Add Sale';}; //You can edit this to change your page title.
require_once("includes/header.php"); //including header file.
?>
<?php if(isset($_GET['sale_id'])) { ?>
<script type="text/javascript">
window.open('reports/view_sale_invoice.php?sale_id=<?php echo $_GET['sale_id']; ?>', '_blank');
</script>
<?php } ?>
<?php
//display message if exist.
if(isset($_GET['message']) && $_GET['message'] != '') {
echo '<div class="alert alert-success">';
echo $_GET['message'];
echo '</div>';
}
if(isset($message) && $message != '') {
echo '<div class="alert alert-success">';
echo $message;
echo '</div>';
}
?>
<style type="text/css">
textarea:hover, textarea:focus, #items td.total-value textarea:hover, #items td.total-value textarea:focus, .delme:hover { background-color:#EEFF88; }
#items input[type=text] {width:60px;border:0px;}
.delete-wpr { position: relative; }
.delme { display: block; color: #000; text-decoration: none; position: absolute; background: #EEEEEE; font-weight: bold; padding: 0px 3px; border: 1px solid; top: -6px; left: -22px; font-family: Verdana; font-size: 12px; }
</style>
<script type="text/javascript">
jQuery(function($) {
$('form[data-async]').on('submit', function(event) {
var $form = $(this);
var $target = $($form.attr('data-target'));
$.ajax({
type: $form.attr('method'),
url: 'includes/otherprocesses.php',
data: $form.serialize(),
dataType: 'json',
success: function(response) {
var message = response.message;
var client_options = response.client_options;
var client_id = response.client_id;
$('#client_id').html(client_options);
$("#client_id").select2().select2('val', client_id);
$('#success_message').html('<div class="alert alert-success">'+message+'</div>');
}
});
event.preventDefault();
});
});
</script>
<!-- Add new vendor modal starts here. -->
<div class="modal fade" id="addnewclient" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add new client</h4>
</div>
<div class="modal-body">
<form data-async data-target="#addnewclient" method="POST" enctype="multipart/form-data" role="form">
<div id="success_message"></div>
<table style="width:100%;">
<tr>
<td>
<div class="form-group">
<label class="control-label">Full Name*</label>
<input type="text" class="form-control" name="full_name" placeholder="Client full name" value="" required="required" />
</div>
</td>
<td>
<div class="form-group">
<label class="control-label">Business Title</label>
<input type="hidden" name="add_client" value="1" />
<input type="submit" id="submit" class="btn btn-primary" value="Add client">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!--add new vendor modal ends here.-->
<form action="includes/process_sale.php" method="post">
<div class="row">
<div class="col-sm-5">
<table border="0" cellpadding="5">
<tr>
<td width="110">Date</td>
<td width="300"><input type="text" name="date" class="form-control datepick" readonly="readonly" value="<?php echo date('Y-m-d'); ?>" /></td>
</tr>
<tr>
<td>Custom Inv#</td>
<td><input type="text" placeholder="Custom Invoice number" name="custom_inv_no" class="form-control" /></td>
</tr>
<tr>
<td>Memo</td>
<td><textarea placeholder="Memo" name="memo" class="form-control"></textarea></td>
</tr>
<tr>
<th>Select Client</th>
<td>
<select name="client_id" id="client_id" class="autofill" style="width:100%">
<option value="">Select Client by full name or mobile</option>
<?
=$client->client_options($client->client_id);
?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><a class="btn btn-default btn-xs" data-toggle="modal" href="#addnewclient">Add new Client</a></td>
</tr>
</table>
</div><!--left-side-form ends here.-->
<script type="text/javascript">
function update_total() {
var grand_total = 0;
i = 1;
$('.total').each(function(i) {
var total = $(this).html();
total = parseFloat(total);
grand_total = total+grand_total;
});
$('#grand_total').html(grand_total.toFixed(2));
}//Update total function ends here.
<?php
require_once("includes/footer.php");
?>
What plattform do you use for the localhost? Online linux server and local a Windows machine? As it is run on the localhost, do you get warnings, notices or the sort? Or even a fatal?
<?
=$client->client_options($client->client_id);
?>
That looks odd. Why the '='?
Okay I finally figured how to make it work by the hint provided above. Actually this Syntax doesn't work in this case:
<?=$client->client_options($client->client_id);?>
The Solution is:
<?php echo $client->client_options($client->client_id); ?>
Thanks all anyway for brainstorming.
Related
datatable and jquery doesn't working
Guys I'm driving crazy with this code: I'm trying to populate my datagrid with the datatable plugin but I'm not understanding why it doesn't working. I have a message whith: DataTables warning: table id=item_data - Invalid JSON response. $(document).ready(function() { $('#item_data').DataTable( { "processing": true, "serverSide": true, "ajax":{ url:"item_fetch.php", type:"POST" }, "columnDefs":[ { "targets":[7, 8, 9], "orderable":false, }, ], "pageLength": 10 }); }); <script src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap.min.js"></script> <script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <table id="item_data" class="table table-bordered table-striped"> <thead> <tr> <th>Item Code</th> <th>Item Description</th> <th>Product Line</th> <th>Purchase Standard Cost</th> <th>Last Receipt</th> <th>Status</th> <th></th> <th></th> <th></th> </tr> </thead> <?php //include("item_list.php"); ?> </table> Theoretically item_fetch execute the query to populate my datagrid but, the java code doesn't reading the table id. Above my item_fetch code <?php //item_fetch.php include('phpfunc/database_connection.php'); include('phpfunc/function.php'); $query = ''; $output = array(); $query .= " SELECT * FROM item INNER JOIN i_prodline ON i_prodline,prodline_id = item.item_prodline "; if(isset($_POST["search"]["value"])) { $query .= 'WHERE i_prodline.prodline_cod LIKE "%'.$_POST["search"]["value"].'%" '; $query .= 'OR i_prodline.prodline_desc LIKE "%'.$_POST["search"]["value"].'%" '; $query .= 'OR item.item_code LIKE "%'.$_POST["search"]["value"].'%" '; $query .= 'OR item.item_desc LIKE "%'.$_POST["search"]["value"].'%" '; } if(isset($_POST['order'])) { $query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].' '; } else { $query .= 'ORDER BY item_code DESC '; } if($_POST['length'] != -1) { $query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length']; } $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); $data = array(); $filtered_rows = $statement->rowCount(); foreach($result as $row) { $status = ''; if($row['item_status'] == 'active') { $status = '<span class="label label-success">Active</span>'; } else { $status = '<span class="label label-danger">Inactive</span>'; } $sub_array = array(); $sub_array[] = $row['item_code']; $sub_array[] = $row['item_desc']; $sub_array[] = $row['prodline_cod']; $sub_array[] = $row['item_standardcost']; $sub_array[] = $row['item_datareceipt']; $sub_array[] = $status; $sub_array[] = '<button type="button" name="view" id="'.$row["item_id"].'" class="btn btn-info btn-xs view">View</button>'; $sub_array[] = '<button type="button" name="update" id="'.$row["item_id"].'" class="btn btn-warning btn-xs update">Update</button>'; $sub_array[] = '<button type="button" name="delete" id="'.$row["item_id"].'" class="btn btn-danger btn-xs delete" data-status="'.$row["item_status"].'">Delete</button>'; $data[] = $sub_array; } function get_total_all_records($connect) { $statement = $connect->prepare('SELECT * FROM item'); $statement->execute(); return $statement->rowCount(); } $output = array( "draw" => intval($_POST["draw"]), "recordsTotal" => $filtered_rows, "recordsFiltered" => get_total_all_records($connect), "data" => $data ); echo json_encode($output); ?> Please how can I fix it? I'm not understanding where is the mistake.
Looks like you left some debugging echo in your php code that is producing invalid JSON (thus the message from Datatable API). Please comment line 32 in your php code. Here is how it should look like later: <?php //item_fetch.php include('phpfunc/database_connection.php'); include('phpfunc/function.php'); $query = ''; $output = array(); $query .= " SELECT * FROM item INNER JOIN i_prodline ON i_prodline,prodline_id = item.item_prodline "; if(isset($_POST["search"]["value"])) { $query .= 'WHERE i_prodline.prodline_cod LIKE "%'.$_POST["search"]["value"].'%" '; $query .= 'OR i_prodline.prodline_desc LIKE "%'.$_POST["search"]["value"].'%" '; $query .= 'OR item.item_code LIKE "%'.$_POST["search"]["value"].'%" '; $query .= 'OR item.item_desc LIKE "%'.$_POST["search"]["value"].'%" '; } if(isset($_POST['order'])) { $query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].' '; } else { $query .= 'ORDER BY item_code DESC '; } //forgot to comment out debug echos //echo $query; if($_POST['length'] != -1) { $query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length']; } $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); $data = array(); $filtered_rows = $statement->rowCount(); foreach($result as $row) { $status = ''; if($row['item_status'] == 'active') { $status = '<span class="label label-success">Active</span>'; } else { $status = '<span class="label label-danger">Inactive</span>'; } $sub_array = array(); $sub_array[] = $row['item_code']; $sub_array[] = $row['item_desc']; $sub_array[] = $row['prodline_cod']; $sub_array[] = $row['item_standardcost']; $sub_array[] = $row['item_datareceipt']; $sub_array[] = $status; $sub_array[] = '<button type="button" name="view" id="'.$row["item_id"].'" class="btn btn-info btn-xs view">View</button>'; $sub_array[] = '<button type="button" name="update" id="'.$row["item_id"].'" class="btn btn-warning btn-xs update">Update</button>'; $sub_array[] = '<button type="button" name="delete" id="'.$row["item_id"].'" class="btn btn-danger btn-xs delete" data-status="'.$row["item_status"].'">Delete</button>'; $data[] = $sub_array; } function get_total_all_records($connect) { $statement = $connect->prepare('SELECT * FROM item'); $statement->execute(); return $statement->rowCount(); } $output = array( "draw" => intval($_POST["draw"]), "recordsTotal" => $filtered_rows, "recordsFiltered" => get_total_all_records($connect), "data" => $data ); echo json_encode($output); ?>
Foreign Key In Php to get data from another table
function show_username($connect) { $output = ''; $query = "SELECT * from users"; $res = mysqli_query($connect, $query); while($row = mysqli_fetch_array($res)) { $output .= '<option value="'.$row["id"].'">'.$row["name"].'</option>'; { } return $output; } function show_offer($connect) { $output = ''; $query = "SELECT * FROM add_offer ORDER BY id DESC"; $res = mysqli_query($connect, $query); while($row = mysqli_fetch_array($res)) { $output .= '<div class="col-md-3 col-sm-4 col-lg-6">'; $output .= '<div class="panel panel-default">'; $output .= '<div class="panel-body">'; $output .= '<div style="padding:1px;float:left;font-weight:bold;">'.$row["part_no"].'</div>'; $output .= '<div style="padding:1px;float:left;">'.$row["make"].'</div>'; $output .= '<div style="padding:1px;float:left;">'.$row["date_code"].'</div>'; $output .= '<div style="padding:1px;float:left;">'.$row["qty"].'</div>'; $output .= '<br>'; $output .= '<div style="float:left;font-size:9px;">'.$row["time"].'</div>'; $output .= '</div>'; $output .= '</div>'; $output .= '</div>'; } echo $output; } <div class="container"> <div class="row"> <div class="col-lg-offset-3 col-lg-6"> <div class="panel"> <div class="panel panel-default" style="border: 1px solid #66512c;"> <div class="panel-heading" style="background-color: #66512c;color: white;"> Market Offers </div> <div class="panel-body" style="padding: 0px;padding-left: 5px;border-bottom: 1px solid #66512c;"> <div class="nav nav-pills nav-stacked"> <select name="category" id="user" class="form-control"> <option selected="" value="" class="form-control">All User Offers</option> <?php echo show_username($connect); ?> </select> <div class="panel panel-body" id="show_offer"> <?php echo show_offer($connect);?> </div> </div> </div> </div> </div> </div> <div class="col-lg-3"></div> </div> <script> $(document).ready(function(){ $('#user').change(function(){ var user_id = $(this).val(); $.ajax({ url:"load_data.php", method:"POST", data:{user_id:user_id}, success:function(data){ $('#show_offer').html(data); } }); }); });</script> <?php //load_data.php $connect = mysqli_connect("localhost", "root", "", "customer"); $output = ''; if(isset($_POST["user_id"])) { if($_POST["user_id"] != '') { $query = "SELECT * FROM add_offer WHERE user_id = '".$_POST["user_id"]."' ORDER BY id DESC"; } else { $query = "SELECT * FROM add_offer ORDER BY id DESC"; } $res = mysqli_query($connect, $query); while($row = mysqli_fetch_array($res)) { $output .= '<div class="col-md-3 col-sm-4 col-lg-6">'; $output .= '<div class="panel panel-default">'; $output .= '<div class="panel-body">'; $output .= '<div style="padding:1px;float:left;font-weight:bold;">'.$row["part_no"].'</div>'; $output .= '<div style="padding:1px;float:left;">'.$row["make"].'</div>'; $output .= '<div style="padding:1px;float:left;">'.$row["date_code"].'</div>'; $output .= '<div style="padding:1px;float:left;">'.$row["qty"].'</div>'; $output .= '<br>'; $output .= '<div style="float:left;font-size:9px;">'.$row["time"].'</div>'; $output .= '</div>'; $output .= '</div>'; $output .= '</div>'; } echo $output; }?> In this above code I have used functions to take data from 2 seperate table and I want to display the table in the following format as name from users table part_no,make,date_code,qty from add_offers table the image shows my output market_offers page I want the data not to be selected by dropdown but has to display whole data as first with name from users table and followed by users part_no from add_offers table. Also the timestamp display as 2018-03-22 12.40.55 which i want as 22-03-2018 12.40.55
You've to change your code as bellow: function show_username($connect) { $output = ''; $query = "SELECT * from users order by id asc"; $res = mysqli_query($connect, $query); while($row = mysqli_fetch_array($res)) { $output .= '<option value="'.$row["id"].'">'.$row["name"].'</option>'; { } return $output; } function show_offer($connect) { $output = ''; $user_query = "SELECT * from users order by id asc"; $user_res = mysqli_query($connect, $user_query ); $user_row = mysqli_fetch_array($user_res); $query = "SELECT * FROM add_offer where user_id = ".$user_row['id']." ORDER BY id DESC"; $res = mysqli_query($connect, $query); while($row = mysqli_fetch_array($res)) { $output .= '<div class="col-md-3 col-sm-4 col-lg-6">'; $output .= '<div class="panel panel-default">'; $output .= '<div class="panel-body">'; $output .= '<div style="padding:1px;float:left;font-weight:bold;">'.$row["part_no"].'</div>'; $output .= '<div style="padding:1px;float:left;">'.$row["make"].'</div>'; $output .= '<div style="padding:1px;float:left;">'.date('d-m-Y H:i:s',strtotime($row["date_code"])).'</div>'; $output .= '<div style="padding:1px;float:left;">'.$row["qty"].'</div>'; $output .= '<br>'; $output .= '<div style="float:left;font-size:9px;">'.$row["time"].'</div>'; $output .= '</div>'; $output .= '</div>'; $output .= '</div>'; } echo $output; } Html Code: <div class="container"> <div class="row"> <div class="col-lg-offset-3 col-lg-6"> <div class="panel"> <div class="panel panel-default" style="border: 1px solid #66512c;"> <div class="panel-heading" style="background-color: #66512c;color: white;"> Market Offers </div> <div class="panel-body" style="padding: 0px;padding-left: 5px;border-bottom: 1px solid #66512c;"> <div class="nav nav-pills nav-stacked"> <select name="category" id="user" class="form-control"> <option selected="" value="" class="form-control">All User Offers</option> <?php echo show_username($connect); ?> </select> <div class="panel panel-body" id="show_offer"> <?php echo show_offer($connect);?> </div> </div> </div> </div> </div> </div> <div class="col-lg-3"></div> </div> Java Script Code: <script> $(document).ready(function(){ $('#user').change(function(){ var user_id = $(this).val(); $.ajax({ url:"load_data.php", method:"POST", data:{user_id:user_id}, success:function(data){ $('#show_offer').html(data); } }); }); });</script> PHP Code: <?php //load_data.php $connect = mysqli_connect("localhost", "root", "", "customer"); $output = ''; if(isset($_POST["user_id"])) { if($_POST["user_id"] != '') { $query = "SELECT * FROM add_offer WHERE user_id = '".$_POST["user_id"]."' ORDER BY id DESC"; } else { $query = "SELECT * FROM add_offer ORDER BY id DESC"; } $res = mysqli_query($connect, $query); while($row = mysqli_fetch_array($res)) { $output .= '<div class="col-md-3 col-sm-4 col-lg-6">'; $output .= '<div class="panel panel-default">'; $output .= '<div class="panel-body">'; $output .= '<div style="padding:1px;float:left;font-weight:bold;">'.$row["part_no"].'</div>'; $output .= '<div style="padding:1px;float:left;">'.$row["make"].'</div>'; $output .= '<div style="padding:1px;float:left;">'.$row["date_code"].'</div>'; $output .= '<div style="padding:1px;float:left;">'.$row["qty"].'</div>'; $output .= '<br>'; $output .= '<div style="float:left;font-size:9px;">'.$row["time"].'</div>'; $output .= '</div>'; $output .= '</div>'; $output .= '</div>'; } echo $output; }?>
Where do I edit to change the search results design?
I have created a simple search engine who gets data from a PHP table and post the results. But as of right now it posts the results in a single line and nothing to show that they're in fact 4 different columns. What I'm looking for is a way to create a table so it looks more presentable. I have the search engine divided into 2 .php files. 1st file: <?php error_reporting(1); include('system_admin.inc.php'); $title = 'Leonard'; make_header($title,array('enable_ajax' => true)); ?> <html> <head> <title>Leonard</title> <script type=text/javascript src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type=text/javascript "> function searchq() { var searchTxt = $("input[name='search']").val(); $.post("testsearch.php", {searchVal: searchTxt}, function(output) { $("#output") .html(output); }); } </script> </head> <body> <h1>Search</h1> <form class="odd" action="leonard.php" method="post"> <input type="text" name="search" placeholder="Search" onkeyup="searchq();" /> <div id="output"> </div> </form> </body> </html> 2nd file: mysql_connect ("localhost","root","xxxxxx") or die ("Connectionissues"); mysql_select_db ("xxxxxx") or die("Can't find DB"); $output = ''; if(isset($_POST['searchVal'])) { $searchq = $_POST['searchVal']; $searchq = preg_replace ("#^0-9#"," ",$searchq); $query = mysql_query("SELECT * FROM ds_OrderItem WHERE idProduct LIKE '%$searchq%' LIMIT 100") or die("Search invalid!"); $count = mysql_num_rows ($query); if($count == 0){ $output = 'Order have never been made before'; }else{ while($row = mysql_fetch_array($query)) { $idproduct = $row['idProduct']; $idorder = $row['idOrder']; $title = $row['title']; $qty = $row['qty']; $output .= '<div> '.$idproduct.' '.$idorder.' '.$title.' '.$qty.' </div>'; } if($_POST['searchVal'] == NULL) { $output = ""; } } } I want these four columns to be displayed in a presentable manner: $idproduct = $row['idProduct']; $idorder = $row['idOrder']; $title = $row['title']; $qty = $row['qty']; Can anyone help me with this? :-) Thanks in advance for reading and any advice given!
Change this portion while($row = mysql_fetch_array($query)) { $idproduct = $row['idProduct']; $idorder = $row['idOrder']; $title = $row['title']; $qty = $row['qty']; $output .= '<div> '.$idproduct.' '.$idorder.' '.$title.' '.$qty.' </div>'; } to $output .='<table>'; while($row = mysql_fetch_array($query)) { $output .= '<tr><td>'.$row['idProduct'].'</td><td>'.$row['idOrder'].'</td><td>'.$row['title'].'</td><td>'.$row['qty'].'</td></tr>'; } $output .='</table>';
Solution for pagination and $_post meaning
Hello i just finish my pagination and face a problem with my filter system i use from to filter and $_POST to extract data but the thing is when i go to second page the post meaning get to nothing and i am missing some data then in my case i got more then i filter it , i mean if i filter by location (london) i get 32 of 36 but when i go to second page i will get all 36 because $_post loses his meaning hare is my code and live page : My website Top code : $cat1 = ''; $perpage = 10; if(isset($_GET["catid"])){ $p1 = ''; $p2 = ''; $catid = $_GET["catid"]; $l1 = substr($catid,0,1); $l2 = substr($catid,1,1); $p1 = "CAT".$l1; if(!empty($l2)){ $p2 = "CAT".$l1."-".$l2; $p3 = $p2; } $cat1 = #$lang[$p1]; $cat2 = #$lang[$p2]; } $postid = ''; $userid = ''; $pricemin = ''; $pricemax = ''; $location = ''; if(isset($_POST["filter"])){ $pricemin = $_POST["min"]; $pricemax = $_POST["max"]; $location = $_POST["location"]; } ///////////////////////////////////////PAGINATION ////////////////// if(empty($p1) && empty($p2)){ $sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE p.id > 0 "; if(!empty($location)){ $sql .= "AND location='$location'"; } if(!empty($pricemin)){ $sql .= "AND price>='$pricemin' "; } if(!empty($pricemax)){ $sql .= "AND price<='$pricemax' "; } } else if(!empty($p2)){ $sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE catid='$p2' "; if(!empty($location)){ $sql .= "AND location='$location'"; } if(!empty($pricemin)){ $sql .= "AND price>='$pricemin' "; } if(!empty($pricemax)){ $sql .= "AND price<='$pricemax' "; } } else { $sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE p.catid LIKE '$p1%' "; if(!empty($location)){ $sql .= "AND location='$location'"; } if(!empty($pricemin)){ $sql .= "AND price>='$pricemin' "; } if(!empty($pricemax)){ $sql .= "AND price<='$pricemax' "; } } $res = mysqli_query($connect,$sql); $rows = mysqli_num_rows($res); $last = ceil($rows/$perpage); if($last < 1){ $last = 1; } $pagenum = 1; if(isset($_GET["pn"])){ $pagenum = preg_replace("#[^0-9]#", "", $_GET["pn"]); } if($pagenum < 1){ $pagenum = 1; } else if($pagenum > $last){ $pagenum = $last; } $limit = 'LIMIT ' .($pagenum - 1) * $perpage.',' .$perpage; $paginationCtrls = ''; if($last != 1){ if ($pagenum > 1) { $previous = $pagenum - 1; $paginationCtrls .= 'Previous '; for($i = $pagenum-4; $i < $pagenum; $i++){ if($i > 0){ $paginationCtrls .= ''.$i.' '; } } } $paginationCtrls .= ''.$pagenum.' '; for($i = $pagenum+1; $i <= $last; $i++){ $paginationCtrls .= ''.$i.' '; if($i >= $pagenum+4){ break; } } if ($pagenum != $last) { $next = $pagenum + 1; $paginationCtrls .= ' Next '; } } ?> and main html code with mysql query : <div class="fp"> <div class="filter"> <b style="padding-left: 10px;">Filters:</b> <form class="filterform" action="" method="post"><br> Location: <br> <input name="location" ><br> Price Range:<br> Min:<input type="text" name="min" size="5"> Max:<input type="text" name="max" size="5"><br><br> <input class="submit-button" type="submit" name="filter" value="Filter"> </form> </div> <div class="posts"> <div id="adcat"><?php if(!empty($cat2)){ ?> <a href="cat.php?catid=<?php echo $l1; ?>" ><?php echo $cat1." » "; ?></a><span><?php echo $cat2; ?></span> <?php } else { echo "<font color='grey'>".$cat1."</font>"; } ?> </div> <div id="totalrez"> <?php echo "Total: ".$rows; ?><br> <?php echo "Page".$pagenum." of ".$last; ?> </div> <br><br> <div id="detailformscat"> <?php if(empty($p1) && empty($p2)){ $sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE p.id > 0 "; if(!empty($location)){ $sql .= "AND location='$location'"; } if(!empty($pricemin)){ $sql .= "AND price>='$pricemin' "; } if(!empty($pricemax)){ $sql .= "AND price<='$pricemax' "; } $sql .= "$limit"; } else if(!empty($p2)){ $sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE catid='$p2' "; if(!empty($location)){ $sql .= "AND location='$location'"; } if(!empty($pricemin)){ $sql .= "AND price>='$pricemin' "; } if(!empty($pricemax)){ $sql .= "AND price<='$pricemax' "; } $sql .= "$limit"; } else { $sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE p.catid LIKE '$p1%' "; if(!empty($location)){ $sql .= "AND location='$location'"; } if(!empty($pricemin)){ $sql .= "AND price>='$pricemin' "; } if(!empty($pricemax)){ $sql .= "AND price<='$pricemax' "; } $sql .= "$limit"; } $res = mysqli_query($connect,$sql); $rows = mysqli_num_rows($res); while ($row = mysqli_fetch_assoc($res)) { $postid = $row["postid"]; ?> <div id="ads"> <div id="adfavcat"> <?php if(!isset($_SESSION["userid"])) { ?> <?php } else { $userid = $_SESSION["userid"]; $sql2 = "SELECT * FROM fav WHERE userid='$userid' AND postid='$postid' "; $res2 = mysqli_query($connect,$sql2); $rowcount = mysqli_num_rows($res2); if ($rowcount > 0){ ?> <?php } else { ?> <?php } } ?> </div> <div id="titlepic"> <?php echo $row["title"]; ?><br> <img src="<?php if(!empty($row["path1"])) { echo $row["path1"]; } else echo "image/noimage.png"; ?>" height="100px" width="150px"> </div> <div id="datescat"> <b>Date Added:</b> <?php echo date('m/d/Y H:i', $row["dateadded"]); ?><br> <b>Renew Date:</b> <?php if($row["renewdate"] > 0){ echo date('m/d/Y H:i', $row["renewdate"]); } ?><br> <b>Location:</b> <?php echo $row["location"]; ?><br> <b>Price:</b> <?php echo $row["price"]."£"; ?><br> </div> </div> <hr width="100%"> <?php } ?> <div id="paginationctrl"><br> <?php echo $paginationCtrls; ?> </div> </div> </div> </div> i need a possible solution for that , to catch post data and keep there until u change hare with a post method again or some other solution because now $_POST will be equal to null if u pass the second page on pagination
For this case you can instead change from $_POST to $_GET as this will be easier so solve your problem as well as any problems you might encounter in future. I think the majority of websites with pagination use variables in URL because it's much easier to track. Moreover, you're not sending any private data, so I don't see a reason why not switch to other method. You will have an option to use something like $_POST['page'] and accordingly to that you can retrieve other rows.
adding new page to opencart admin
I am trying to add a new page in the admin section in opencart and have managed to create all the necessary files and permissions for it to show up, but it wont display any results. I am trying to make a page where I can add/edit/delete minecraft recipes. But instead of showing the results for each recipe in the database it just shows "No results!" Please help me i am stuck. Database Table: CREATE TABLE IF NOT EXISTS `oc_recipes` ( `recipe_id` int(255) NOT NULL AUTO_INCREMENT, `item1` int(255) NOT NULL, `item2` int(255) NOT NULL, `item3` int(255) NOT NULL, `item4` int(255) NOT NULL, `item5` int(255) NOT NULL, `item6` int(255) NOT NULL, `item7` int(255) NOT NULL, `item8` int(255) NOT NULL, `item9` int(255) NOT NULL, `product_id` int(11) NOT NULL, `sort_order` int(255) NOT NULL, PRIMARY KEY (`recipe_id`), UNIQUE KEY `product_id` (`product_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; INSERT INTO `oc_recipes` (`recipe_id`, `item1`, `item2`, `item3`, `item4`, `item5`, `item6`, `item7`, `item8`, `item9`, `product_id`, `sort_order`) VALUES (1, 89, 0, 0, 0, 0, 0, 0, 0, 0, 90, 0); admin/controller/catalog/recipe.php: class ControllerCatalogRecipe extends Controller { private $error = array(); public function index() { $this->language->load('catalog/recipe'); $this->document->setTitle($this->language->get('heading_title')); $this->load->model('catalog/recipe'); $this->getList(); } protected function getList() { if (isset($this->request->get['sort'])) { $sort = $this->request->get['sort']; } else { $sort = 'name'; } if (isset($this->request->get['order'])) { $order = $this->request->get['order']; } else { $order = 'ASC'; } if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } $url = ''; if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } if (isset($this->request->get['page'])) { $url .= '&page=' . $this->request->get['page']; } $data['breadcrumbs'] = array(); $data['breadcrumbs'][] = array( 'text' => $this->language->get('text_home'), 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL') ); $data['breadcrumbs'][] = array( 'text' => $this->language->get('heading_title'), 'href' => $this->url->link('catalog/recipe', 'token=' . $this->session->data['token'] . $url, 'SSL') ); $data['add'] = $this->url->link('catalog/recipe/add', 'token=' . $this->session->data['token'] . $url, 'SSL'); $data['delete'] = $this->url->link('catalog/recipe/delete', 'token=' . $this->session->data['token'] . $url, 'SSL'); $data['recipes'] = array(); $filter_data = array( 'sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $this->config->get('config_limit_admin'), 'limit' => $this->config->get('config_limit_admin') ); $recipe_total = $this->model_catalog_recipe->getTotalRecipes(); $results = $this->model_catalog_recipe->getRecipes($filter_data); foreach ($results as $result) { $data['recipes'][] = array( 'recipe_id' => $result['recipe_id'], 'name' => $this->model_catalog_recipe->getRecipeName($result['product_id']), 'sort_order' => $result['sort_order'], 'edit' => $this->url->link('catalog/recipe/edit', 'token=' . $this->session->data['token'] . '&recipe_id=' . $result['recipe_id'] . $url, 'SSL') ); } $data['heading_title'] = $this->language->get('heading_title'); $data['text_list'] = $this->language->get('text_list'); $data['text_no_results'] = $this->language->get('text_no_results'); $data['text_confirm'] = $this->language->get('text_confirm'); $data['column_name'] = $this->language->get('column_name'); $data['column_sort_order'] = $this->language->get('column_sort_order'); $data['column_action'] = $this->language->get('column_action'); $data['button_add'] = $this->language->get('button_add'); $data['button_edit'] = $this->language->get('button_edit'); $data['button_delete'] = $this->language->get('button_delete'); if (isset($this->error['warning'])) { $data['error_warning'] = $this->error['warning']; } else { $data['error_warning'] = ''; } if (isset($this->session->data['success'])) { $data['success'] = $this->session->data['success']; unset($this->session->data['success']); } else { $data['success'] = ''; } if (isset($this->request->post['selected'])) { $data['selected'] = (array)$this->request->post['selected']; } else { $data['selected'] = array(); } $url = ''; if ($order == 'ASC') { $url .= '&order=DESC'; } else { $url .= '&order=ASC'; } if (isset($this->request->get['page'])) { $url .= '&page=' . $this->request->get['page']; } $data['sort_name'] = $this->url->link('catalog/recipe', 'token=' . $this->session->data['token'] . '&sort=name' . $url, 'SSL'); $data['sort_sort_order'] = $this->url->link('catalog/recipe', 'token=' . $this->session->data['token'] . '&sort=sort_order' . $url, 'SSL'); $url = ''; if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } $pagination = new Pagination(); $pagination->total = $recipe_total; $pagination->page = $page; $pagination->limit = $this->config->get('config_limit_admin'); $pagination->url = $this->url->link('catalog/recipe', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL'); $data['pagination'] = $pagination->render(); $data['results'] = sprintf($this->language->get('text_pagination'), ($recipe_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($recipe_total - $this->config->get('config_limit_admin'))) ? $recipe_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $recipe_total, ceil($recipe_total / $this->config->get('config_limit_admin'))); $data['sort'] = $sort; $data['order'] = $order; $data['header'] = $this->load->controller('common/header'); $data['column_left'] = $this->load->controller('common/column_left'); $data['footer'] = $this->load->controller('common/footer'); $this->response->setOutput($this->load->view('catalog/recipe_list.tpl', $data)); } } admin/language/english/catalog/recipe.php: // Heading $_['heading_title'] = 'Recipes'; // Text $_['text_success'] = 'Success: You have modified a recipe!'; $_['text_list'] = 'Recipe List'; $_['text_add'] = 'Add Recipe'; $_['text_edit'] = 'Edit Recipe'; $_['text_default'] = 'Default'; $_['text_percent'] = 'Percentage'; $_['text_amount'] = 'Fixed Amount'; // Column $_['column_name'] = 'Recipe Name'; $_['column_sort_order'] = 'Sort Order'; $_['column_action'] = 'Action'; // Entry $_['entry_name'] = 'Recipe Name'; $_['entry_store'] = 'Stores'; $_['entry_keyword'] = 'SEO Keyword'; $_['entry_image'] = 'Image'; $_['entry_sort_order'] = 'Sort Order'; $_['entry_type'] = 'Type'; // Help $_['help_keyword'] = 'Do not use spaces, instead replace spaces with - and make sure the keyword is globally unique.'; // Error $_['error_permission'] = 'Warning: You do not have permission to modify recipes!'; $_['error_name'] = 'Recipe Name must be between 2 and 64 characters!'; $_['error_keyword'] = 'SEO keyword already in use!'; $_['error_product'] = 'Warning: This recipe cannot be deleted as it is currently assigned to %s products!'; admin/model/catalog/recipe.php: class ModelCatalogRecipe extends Model { public function getRecipe($recipe_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "recipes"); return $query->row; } public function getRecipes($data = array()) { $sql = "SELECT * FROM " . DB_PREFIX . "recipes"; if (!empty($data['filter_name'])) { $sql .= " WHERE name LIKE '" . $this->db->escape($data['filter_name']) . "%'"; } $sort_data = array( 'name', 'sort_order' ); if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { $sql .= " ORDER BY " . $data['sort']; } else { $sql .= " ORDER BY name"; } if (isset($data['order']) && ($data['order'] == 'DESC')) { $sql .= " DESC"; } else { $sql .= " ASC"; } if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 20; } $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; } $query = $this->db->query($sql); return $query->rows; } public function getRecipeName($product_id) { $sql = "SELECT name FROM " . DB_PREFIX . "product_description WHERE product_id = ".$product_id; $query = $this->db->query($sql); return $query->row['name']; } public function getTotalRecipes() { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "recipes"); return $query->row['total']; } } admin/view/template/catalog/recipe_list.tpl: <?php echo $header; ?><?php echo $column_left; ?> <div id="content"> <div class="page-header"> <div class="container-fluid"> <div class="pull-right"><i class="fa fa-plus"></i> <button type="button" data-toggle="tooltip" title="<?php echo $button_delete; ?>" class="btn btn-danger" onclick="confirm('<?php echo $text_confirm; ?>') ? $('#form-recipe').submit() : false;"><i class="fa fa-trash-o"></i></button> </div> <h1><?php echo $heading_title; ?></h1> <ul class="breadcrumb"> <?php foreach ($breadcrumbs as $breadcrumb) { ?> <li><?php echo $breadcrumb['text']; ?></li> <?php } ?> </ul> </div> </div> <div class="container-fluid"> <?php if ($error_warning) { ?> <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?> <button type="button" class="close" data-dismiss="alert">×</button> </div> <?php } ?> <?php if ($success) { ?> <div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $success; ?> <button type="button" class="close" data-dismiss="alert">×</button> </div> <?php } ?> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title"><i class="fa fa-list"></i> <?php echo $text_list; ?></h3> </div> <div class="panel-body"> <form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form-manufacturer"> <div class="table-responsive"> <table class="table table-bordered table-hover"> <thead> <tr> <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td> <td class="text-left"><?php if ($sort == 'name') { ?> <?php echo $column_name; ?> <?php } else { ?> <?php echo $column_name; ?> <?php } ?></td> <td class="text-right"><?php if ($sort == 'sort_order') { ?> <?php echo $column_sort_order; ?> <?php } else { ?> <?php echo $column_sort_order; ?> <?php } ?></td> <td class="text-right"><?php echo $column_action; ?></td> </tr> </thead> <tbody> <?php if ($recipes) { ?> <?php foreach ($recipes as $recipe) { ?> <tr> <td class="text-center"><?php if (in_array($recipe['recipe_id'], $selected)) { ?> <input type="checkbox" name="selected[]" value="<?php echo $recipe['recipe_id']; ?>" checked="checked" /> <?php } else { ?> <input type="checkbox" name="selected[]" value="<?php echo $recipe['recipe_id']; ?>" /> <?php } ?></td> <td class="text-left"><?php echo $recipe['name']; ?></td> <td class="text-right"><?php echo $recipe['sort_order']; ?></td> <td class="text-right"><i class="fa fa-pencil"></i></td> </tr> <?php } ?> <?php } else { ?> <tr> <td class="text-center" colspan="4"><?php echo $text_no_results; ?></td> </tr> <?php } ?> </tbody> </table> </div> </form> <div class="row"> <div class="col-sm-6 text-left"><?php echo $pagination; ?></div> <div class="col-sm-6 text-right"><?php echo $results; ?></div> </div> </div> </div> -EDIT- On the View page I printed out $recipes and it just displays array(), so I am guessing the problem is somewhere inside the Controller where $recipes gets its data inserted into it. But as far as I can tell it looks like its all set up correctly! I am confused lol.
you need enable controller in admin panel to display your controller admin menu > Setting> user group> enable your controller after that you can open your new page by this pattern [admin url]/index.php?route=catalog/recipe