How to add autocomplete data into invoice dynamically - sql

I am looking for a way to add autocomplete data from my code to an "invoice" page automatically. I want the user to be able to also click to add or remove each item(quickbooks style, with multiple form fields available, and adding dynamically) and in the long run, be able to drag elements to a certain position in the invoice. All I am looking for now is this :
good : pseudocode on how to do this
best : basic working code to take off with.
This is what I have so far :
Page that calls the data :
<?php
require 'database.php';
require 'results.php';
if(!empty($_GET['wid'])) { $wid = $_GET['wid']; }
elseif(!empty($_POST['wid'])) { $wid = $_POST['wid']; }
else { $wid = null; }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/engine.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="span10 offset1">
<div class="row">
<h3>Add Item to Workorder</h3>
</div>
<form class="form-horizontal" action="additems.php" method="post">
<?php
// Add Custom Call for values from prior page ?>
<input type="hidden" name="wid" value="<?php echo htmlentities($wid); ?>">
<?php
//not required, but for get link purposes
if(isset($_POST['search']) && $_POST['search']!=''){
$search = $_POST['search'];
} elseif (isset($_GET['search']) && $_GET['search']!=''){
$search = $_GET['search'];
} else {
$search='';
}
//
echo"
<input type='text' class='search_input' name='search' id='search' placeholder='search' value='$search' autofocus>
<div id='search_output' class='search_output'>";
?>
Page that retrieves results :
<?php
require_once"database.php";//connection to database
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_POST['search']) && $_POST['search']){
$search=$_POST['search'];
} elseif(isset($_GET['search']) && $_GET['search']){
$search=$_GET['search'];
}
if(isset($search)){
$search = '%' . strtr($search, ['%' => '\%', '_' => '\_']);
$search = str_replace(" ", "%", $search);
$search= "%$search%";
$sql="select * from products where `model` LIKE ? OR `category` LIKE ? OR `description` LIKE ? OR `subcategory` LIKE ? LIMIT 50;";
$statement = $pdo->prepare($sql);
$statement->execute([$search, $search, $search, $search]);
//configure for your custom data dump to autocomplete
echo "
<table class='table table-striped table-bordered' width='100%'>
<thead>
<tr>
<th>Model</th>
<th>Category</th>
<th>Description</th>
</tr>
</thead>
<tbody>
";
while($row = $statement->fetch()){
$item=$row['model'];
$title=$row['category'];
$description=$row['description'];
echo "
<tr>
<td>
<a href='?item=$item'>
$item
</td><td>
$title
</td><td>
$description
</a>
</td>
</tr>
";
}
//
}

This code contains Javascript and AJAX code which is for making dynamic search from the input and displaying the sql results in the 'search_output'.
<input type='text' class='search_input' onkeyup="performSearch(this.value);" id='search' placeholder='search' value='$search' autofocus>
<div id='search_output' class='search_output'>";
<script>
function performSearch(data) {
if (data.length > 0) {
var xmlhttp = new XMLHttpRequest() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("search_output").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "YOURPHPFILENAME.php?search=" + data, true);
xmlhttp.send();
}
}
</script>
Unfortunately for other Dynamic features you will need to learn JQUERY/AJAX and understand HTML DOM. There may be Third party API which may do this.

Related

Property of object in array is reactive when all elements are changed, but not if only some are changed

I have this selectAllToggle function, which reactively selects or deselects all elements in the array. Reactively in that when the selectButton is used, all the checkboxes in the browser show selected or deselected.
The problem arise when one or more (but not all) checkboxes were manually selected. If any checkboxes are selected, the selectButtonName changes to "Deselect All", and when pressed, I want it to deselect all.
The code I have correctly updates the array, in that it sets the 'selected' property to false for every student in the array, but the reactivity of it doesn't work - the tick boxes of the students that were selected manually, remain ticked in the browser.
selectAllToggle: function(key, row, $event) {
var setTo = false;
var newname = "Select All";
if (this.selectButtonName === "Select All") {
setTo = true;
newname = "Deselect All";
}
if (this.selectButtonName === "Deselect All") {
setTo = false;
newname = "Select All";
}
if (this.students.length > 0) {
for (var i = 0; i < this.students.length; i++) {
this.students[i]['selected'] = setTo;
}
}
this.selectButtonName = newname;
console.log(this.students); //shows the correct 'selected' state for all
},
The view looks like this (using vue-tables-2)
<v-client-table
v-if="gridReady"
v-model.sync="students"
:columns="gridcolumns"
:options="gridoptions"
ref="grid">
<input type="checkbox"
slot="selected"
slot-scope="{row, update}"
v-model="row.selected"
#change="selectStudent('select', row, $event)">
</v-client-table>
What can I do to make this function reactive?
For deselecting after one or more element selection, you may use a computed property as the snippet below for reactively perform.
new Vue({
el: '#app',
data: {
selected: [],
clientList: [1, 2, 3, 4, 5]
},
computed: {
selectAll: {
get: function() {
return this.selected.length > 0 &&
this.selected.length <= this.clientList.length
},
set: function(value) {
let list = [];
if (value) {
this.selected = this.clientList
} else {
this.selected = []
}
}
}
},
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.7/vue.js"></script>
<div id='app'>
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Client Name</th>
<th style="width: 10%"><input type="checkbox" v-model="selectAll" /></th>
</tr>
</thead>
<tbody>
<tr v-for="(item,index) in clientList">
<td style="font-weight: bold;width: 75%">{{item}}
</td>
<td style="width: 25%">
<input type="checkbox" :value="item" v-model="selected" />
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

Php 7 error for a simple form getting Object of class mysqli could not be converted to int

The code gets error saying Object of class mysqli could not be converted to int. When i try to load the page i get this error,i checked other questions but it was not helpful
<?php
$conn = mysqli_connect("localhost", "root", "", "coinlion");
if ($conn == 0) {
echo "could not connect";
} else {
mysqli_select_db("coinlion");
echo "connected";
}
?>
<form method="post">
<style>
#newlink {
width: 600px
}
</style>
<div id="newlink">
<div>
<table border=0>
<tr>
<td> Link URL:</td>
<td><input type="text" name="linkurl" value="" required></td>
</tr>
<tr>
<td> Link Description:</td>
<td><textarea name="linkdesc" cols="50" rows="5" required></textarea>
</td>
</tr>
</table>
</div>
</div>
<p>
<br>
<input type="submit" name="submit1">
<input type="reset" name="reset1">
</p>
php code
<?php
if (isset($_POST['submit1'])) {
$linkurl = $_POST['linkurl'];
$linkdesc = $_POST['linkdesc'];
mysqli_query($conn, "insert into
test(linkurl,linkdesc)values('$_POST[linkurl]','$_POST[linkdesc]')");
echo "data inserted";
}
?>
Well the issue was with the line if($conn==0) ,This value was taken as an integer so the error occured and an Connection variable to Mysqli_select_db was missing , after fixing it , the code ran successfully

Custom multilingual inputs - opencart

What is the pattern for creating a multilingual input in opencart for admin side.
For example I want to have two List Description Limit inputs, one for each language.
Like in this image. So I can control from admin side the list limit for every language.
Currently I use this pattern to create a custom input, but this is not language dependent:
File: admin/view/template/extension/theme/theme_default.tpl
<fieldset>
<div class="form-group required">
<label class="col-sm-2 control-label" for="inputId"><span data-toggle="tooltip" title="<?php echo $help_inputName; ?>"><?php echo $label_inputName; ?></span></label>
<div class="col-sm-10">
<input type="text" name="theme_default_inputName" value="<?php echo $theme_default_inputName; ?>" placeholder="<?php echo $label_inputName; ?>" id="inputId" class="form-control" />
<?php if ($error_inputName) { ?>
<div class="text-danger"><?php echo $error_inputName; ?></div>
<?php } ?>
</div>
</div>
</fieldset>
File: admin/language/en-gb/extension/theme/theme_default.php
//Language strings
$_['help_inputName'] = 'helpTxt';
$_['label_inputName'] = 'labelForInput';
$_['error_inputName'] = 'errorForInput';
File: admin/controller/extension/theme/theme_default.php
//Language strings
$text_strings = array(
'help_inputName',
'label_inputName',
'error_inputName'
);
foreach ($text_strings as $text) {
$data[$text] = $this->language->get($text);
}
//Error handling
if (isset($this->error['inputName'])) {
$data['error_inputName'] = $this->error['inputName'];
} else {
$data['error_inputName'] = '';
}
//Custom field
if (isset($this->request->post['theme_default_inputName'])) {
$data['theme_default_inputName'] = $this->request->post['theme_default_inputName'];
} elseif (isset($setting_info['theme_default_inputName'])) {
$data['theme_default_inputName'] = $setting_info['theme_default_inputName'];
} else {
$data['theme_default_inputName'] = "customText";
}
//Validation
if (!$this->request->post['theme_default_inputName']) {
$this->error['inputName'] = $this->language->get('error_inputName');
}

Error number: 1052. Column 'id' in field list is ambigious

I am trying to make a pagination table in codeigniter using php and bootstrap. As far as i want to run my code in browser i face the error subscribed in the title. I would be very pleasant and grateful if anyone could help me. Here is my code.
employees_model.php
<?php
class employees_model extends CI_Model{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
//fetch department details from database
function get_employees_list($limit, $start)
{
$sql = 'select (id, employee_emer, mbiemer, adresa, email), department_emer from employee, department where department.id = employee.id_departament order by employee_emer limit ' . $start . ', ' . $limit;
$query = $this->db->query($sql);
return $query->result();
}
}
?>
employees.php
<?php
class employees extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->database();
$this->load->library('pagination');
//load the department_model
$this->load->model('employees_model');
}
public function index()
{
//pagination settings
$config['base_url'] = site_url('employees/index');
$config['total_rows'] = $this->db->count_all('employee');
$config['per_page'] = "5";
$config["uri_segment"] = 3;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = floor($choice);
//config for bootstrap pagination class integration
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
//call the model function to get the department data
$data['emplist'] = $this->employees_model->get_employees_list($config["per_page"], $data['page']);
$data['pagination'] = $this->pagination->create_links();
//load the department_view
$this->load->view('employees_view',$data);
}
}
?>
employees_view.php
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP CodeIgniter Pagination with Bootstrap Styles | Example</title>
<!--link the bootstrap css file-->
<link rel="stylesheet" href="<?php echo base_url("bootstrap/css/bootstrap.css"); ?>">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>Employee ID</th>
<th>Employee Number</th>
<th>Employee Name</th>
<th>Employee Surname</th>
<th>Employee Address</th>
<th>Employee Email</th>
</tr>
</thead>
<tbody>
<?php for ($i = 0; $i < count($emplist); ++$i) { ?>
<tr>
<td><?php echo ($page+$i+1); ?></td>
<td><?php echo $emplist[$i]->id; ?></td>
<td><?php echo $emplist[$i]->employee_emer; ?></td>
<td><?php echo $emplist[$i]->mbiemer; ?></td>
<td><?php echo $emplist[$i]->adresa; ?></td>
<td><?php echo $emplist[$i]->email; ?></td>
<td><?php echo $emplist[$i]->department_emer; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<?php echo $pagination; ?>
</div>
</div>
</div>
</body>
</html>
Please HELP ME. THANK YOU IN ADVANCE!
Try to alias Table names. check this
$sql = ' select employee.id, employee_emer, mbiemer, adresa, email, department_emer from employee, department
where department.id = employee.id_departament order by employee_emer limit ' . $start . ', ' . $limit;
Or
$sql = ' select e.id, employee_emer, mbiemer, adresa, email, department_emer
from employee e inner join department d on d.department.id = e.id_departament
order by employee_emer limit ' . $start . ', ' . $limit;

Notice: Undefined index: province in D:\wamp\www\PDO\sampleCRUD\update.php on line 13?

I have here the page for update.php my problem was I keep getting this error
Notice: Undefined index: province in D:\wamp\www\PDO\sampleCRUD\update.php on line 13
every time I select this value "---" in my dropdown list it keeps showing this error but if select the rest of the list in the dropdown there's no error I tried to set the province but I still getting this error.
here my code for update.php
<?php
include_once 'dbconfig.php';
$username = isset($_GET['username']) ? $_GET['username'] : '';
$password = isset($_GET['password']) ? $_GET['password'] : '';
$province = isset($_GET['province']) ? $_GET['province'] : '';
if(isset($_POST['btn-update']))
{
$user_id = $_GET['user_id'];
$username = $_POST['username'];
$password = $_POST['password'];
$province = $_POST['province'];
if($crud->update($user_id,$username,$password,$province))
{
echo "<script type='text/javascript'>alert('Record was updated Successfully!');</script>";
}
else
{
echo "<script type='text/javascript'>alert('Updating Failed!'); </script>";
}
}
if(isset($_GET['user_id']))
{
$user_id = $_GET['user_id'];
extract($crud->getID($user_id));
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<title>Survey Update Landholdings</title>
<link rel="shortcut icon" href="image/icon.ico"/>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<div class="container">
<p><strong>Survey Update</strong></p>
<br />
<div id="Survey-Update">
<form method='post'>
<table class='table table-bordered'>
<tr>
<td>First Name</td>
<td><input type='text' name='username' class='form-control' value="<?php echo $username; ?>" required></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type='text' name='password' class='form-control' value="<?php echo $password; ?>" required></td>
</tr>
<tr>
<td>Province</td>
<?php
include_once 'dbconfig.php';
$sql = "SELECT username FROM sample";
$stmt = $DB_con->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($stmt->rowCount() > 0)
{
?>
<td><select class='form-control' name='province'>
<option selected="selected" disabled>---</option>
<?php foreach ($results as $row)
{
?>
<option value="<?php echo $row['username']; ?>"><?php echo $row['username']; ?></option>
<?php
}
?>
</select>
<?php
}
?>
</td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-update">
<span class="edit"></span>Update</button>
CANCEL
</td>
</tr>
</table>
</form>
</div>
the error is in this line
$province = $_POST['province'];
Change this line
<option selected="selected" disabled>---</option>
to
<option selected="selected" value="" disabled>---</option>
to send an empty value for province instead of none.
Edit: the above code does not work.
The issue here is the disabled and selected="selected". It seems, disabled options don't get submitted.
If you want to stick with disabled and selected I suggest using
$province = isset($_POST['province']) ? $_POST['province'] : '';