I'm trying to get awsome font icon from myself, by retrieve from MySQL database, in the database query, I put echo with table, like this...
$sql = "SELECT * FROM boxes where categories = 'box' ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
if ($row['status'] == 1)
$visible = "visible";
else
$visible = "hidden";
if ($row['side'] == 1)
$side = "right";
else if ($row['side'] == 2)
$side = "left";
else $side = "not set yet";
echo " <tr>
<td>" . $row['id_boxe'] . "</td>
<td>" . $row['title_boxe'] . "</td>
<td>" . $visible . "</td>
<td>" . $visible . "</td>
<td>" . $side . "</td>
<td> " '<i class = "fa '.$row['icon'].' " ></i>'" </td>
<td><form method='post'><input type='hidden' name='id' value='" . $row['id_boxe'] . "'/>
<input type='submit' name='update' value='Update'/><input type='submit' name='delete' value='Delete'/></form></td>
</tr> ";
}
}
?>
</tbody>
please see the code where it said
<td> " '<i class = "fa '.$row['icon'].' " ></i>'" </td>
I'm trying to put icon column name inside of class but I'm getting the error in the code, my question is that how can I write correct code to show the icon inside of class!
aM
You have a mess with the quotes...
Use backslashes to escape qoutes, read here: https://stackoverflow.com/a/7999163/4195586
Here is working example of the last line in your code:
<td> <i class = \"fa ".$icon."\" ></i> </td> </tr> ";
Related
I have HTML table like below and I need to add a order quantity with other table data in to database for particular customer on click on insert button. Please any help me on this.
HTML Table Image
<?php
//to view all calls
include("connection.php");
$sql="SELECT * FROM items where agencycode='$_SESSION[SESS_FIRST_NAME]'";
$result=mysql_query($sql);
print "
<form class='form-horizontal' action='addorders.php' method='post'>
<div class='table-responsive'>
<table id='pending' class='table table-striped table-hover'>
<thead>
<th>Item Code</th>
<th>Item Name</th>
<th>UPC</th>
<th>RLP</th>
<th>Inv</th>
<th>Company</th>
<th>Brand</th>
<th>Orders</th>
<th>Total</th>
</thead>";
while ($db_field=mysql_fetch_assoc($result))
{
print "<tr>";
print "<td>" . $db_field['itemcode'] . "</td>";
print "<td>" . $db_field['itemname'] . "</td>";
print "<td>" . $db_field['upc'] ."</td>";
print "<td>" . $db_field['rlp'] . "</td>";
print "<td>" . $db_field['inv'] . "</td>";
print "<td>" . $db_field['company'] . "</td>";
print "<td>" . $db_field['brand'] . "</td>";
print "<td><input type='text' class='form-control' name='name[]'/></td>";
print "<td>" . $db_field['rlp'] * 1 . "</td>";
print "<td><input type='hidden' name='id' value='$id' class='formlabel' required></td>";
print "</tr>";
}
print "<td><input type='submit' class='form-control' value='Insert' size='16'/></td>";
print "</form>";
?>
</div>
</div>
</div>
Order field is the only data that is going to be posted, and for the rest of the data, the user is not going to interact with it, so you only need to perform an update query:
HTML:
<input type='hidden' name='itemCode' value=' .$db_field['itemcode'] . ' class='formlabel'>
PHP:
foreach($_POST['name'] as $data){
$sql = "update tablename set order='".$data."' where itemCode=$_POST['itemCode'] and userID=$_GET['id'];
mysql_query($sql);
}
The code below is not required, as you're getting the user id from the URL:
<td><input type='hidden' name='id' value='$id' class='formlabel' required></td>
Hope this helps!
im using ng-repeat to display all values from a database using mysql, im converting the data to string in a php script shown here.
<?php
require("../easyCRUD/Usuarios.class.php");
require("../easyCRUD/TipoUsuario.class.php");
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$usuario = new Usuarios();
$tipousuario = new TipoUsuario();
$usuarios = $usuario->all();
$data="";
$len = count($usuarios);
$i = 0;
foreach($usuarios as $ban){
//echo "i=".$i;
$tipousuario->find($ban['id_tipo_usuario']);
$data .= '{';
$data .= '"id_usuario":"' . $ban['id_usuario'] . '",';
$data .= '"usuario":"' . $ban['usuario'] . '",';
$data .= '"nombre":"' . $ban['nombre'] . '",';
$data .= '"apellido":"' . $ban['apellido'] . '",';
$data .= '"cedula":"' . $ban['cedula'] . '",';
$data .= '"correo":"' . $ban['correo'] . '",';
$data .= '"telefono":"' . $ban['telefono'] . '",';
$data .= '"estado":"' . $ban['estado_cliente'] . '",';
$data .= '"tipo_usuario":"' . $tipousuario->tipo_usuario. '"';
$data .= '}';
if ($i != $len - 1) {
$data .= ',';
}
$i++;
}
echo '{"records":[' . $data . ']}';
?>
then in the controller i bind the data to the scope.
$scope.getAll = function(){
console.log("starto");
$http.get("procesos/read_usuario.php").success(function(response){
$scope.names = response.records;
console.log($scope.names);
console.log("finish");
});
}
and in the view i show the values in with a ng-repeat
<tbody ng-init="getAll()">
<tr ng-repeat="d in names | filter:search | startFrom:(currentPage - 1 )*pageSize | limitTo: pageSize">
<td class="text-align-center" >
<p class="text-center">{{ d.id_usuario }}</p>
</td>
<td>
{{d.usuario}}
</td>
<td>
<p class="text-center" >{{d.tipo_usuario}}</p>
</td>
<td>
<p class="text-center" >{{d.nombre}}</p>
</td>
<td>
<p class="text-center" >{{d.apellido}}</p>
</td>
<td>
<p class="text-center" >{{d.cedula}}</p>
</td>
<td>
<p class="text-center" >{{d.correo}}</p>
</td>
<td>
<p class="text-center" >{{d.telefono}}</p>
</td>
<td>
<p class="text-center" >{{d.estado_cliente}}</p>
</td>
<td>
<a ng-click="readOne(d.id_usuario)" class="btn btn-primary" id={{"aElement"+d.id}} >Edit</a>
<a ng-click="deleteElement(d.id_usuario)" class="btn btn-Danger">Delete</a>
</td>
</tr>
in my console it displays all the data correctly even "usuario" but when i render it in the view the only value that doesn't show is "usuario".
edit: it seems to be a problem with pagination, im using angular-bootstrap pagination, if i click next it shows the missing values.
You are trying to render tipo_usuario but in your console log the property is called usuario.
turns out it was the pagination, i didnt set the value of the current page and the page size.
$scope.pageSize=5;
$scope.currentPage=1;
I build dynamic input by add row table, and user input by autocomplete, then I store PRODUCT_ID in <input name="idp" value="">
E.g User input twice times (HP & Computer)
Name Product | PRODUCT_ID
HP = 2945
COMPUTER = 8654
Should be in array is = (2945,8654)
This is for Controller:
class ControllerItemItem extends Controller { //Controller/Item/Item.php
private $error = array();
public function index() {
$this->language->load('item/item');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('item/item');
$this->getList();
}
protected function getList(){
if (isset($this->request->get['head_text_field'])){
$head_text_field = $this->request->get['head_text_field'];
} else {
$head_text_field = null;
}
if (isset($this->request->get['title_text_field'])){
$title_text_field = $this->request->get['title_text_field'];
} else {
$title_text_field = null;
}
if (isset($this->request->get['max'])){
$max = $this->request->get['max'];
} else {
$max = null;
}
if(isset($this->request->get['idp'])){
$product = $this->request->get['idp'];
$product2 = array();
foreach($product as $p)
{
$product2[] = $p;
}
}else {
$product = null;
}
// BREADCRUMBS //
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('module/item', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
// END //
// Call Language //
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['entry_head'] = $this->language->get('entry_head');
$this->data['entry_title'] = $this->language->get('entry_title');
$this->data['entry_product'] = $this->language->get('entry_product');
$this->data['entry_max_item'] = $this->language->get('entry_max_item');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
// END //
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
$this->data['action'] = $this->url->link('item/item/insert', 'token=' . $this->session->data['token'], 'SSL');
$this->data['token'] = $this->session->data['token'];
$data = array(
'head_text_field' => $head_text_field,
'title_text_field' => $title_text_field,
'max' => $max
);
$this->template = 'item/item.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
public function insert()
{
$this->language->load('item/item');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('item/item');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
//$this->model_item_item->insert_head($this->request->post);
$this->model_item_item->insert_detail($this->request->post);
//$this->session->data['success'] = $this->language->get('text_success');
//$this->redirect($this->url->link('item/item', 'token=' . $this->session->data['token'], 'SSL'));
}
}
protected function validateForm() {
if (!$this->user->hasPermission('modify', 'item/item')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if ((utf8_strlen($this->request->post['head_text_field']) < 1) || (utf8_strlen($this->request->post['head_text_field']) > 64)) {
$this->error['head'] = $this->language->get('error_head');
}
if (!$this->request->post['title_text_field']) {
$this->error['title'] = $this->language->get('error_title');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
This is for Model :
class ModelItemItem extends Model {
public function insert_head($data)
{
$this->db->query("INSERT INTO " . DB_PREFIX . "show_product SET head_text = '" . $this->db->escape($data['head_text_field']) . "', title_text = '" . $this->db->escape($data['title_text_field']) . "', max_item = '" . $this->db->escape($data['max']) . "'");
}
public function insert_detail($product2)
{
foreach($product2 as $detail)
{
//$this->db->query("INSERT INTO " . DB_PREFIX . "show_product_detail SET product_id = '". $this->db->escape($detail['product']) . "'");
}
echo $detail[0];
}
}
This is for view :
<?php echo $header; ?>
<div id="content">
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><?php echo $breadcrumb['text']; ?>
<?php } ?>
</div>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php if ($success) { ?>
<div class="success"><?php echo $success; ?></div>
<?php } ?>
<div class="box">
<div class="heading">
<h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?></h1>
<div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><?php echo $button_cancel; ?></div>
</div>
<div class="content">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_head; ?></td>
<td><input type="text" name="head_text_field" value="" placeholder="Input Head Text" size="40"/>
<?php if ($error_head) { ?>
<span class="error"><?php echo $error_head; ?></span>
<?php } ?>
</td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_title; ?></td>
<td><textarea name="title_text_field" placeholder="Input Title Text" style="width:230px;"/></textarea>
<?php if ($error_title) { ?>
<span class="error"><?php echo $error_title; ?></span>
<?php } ?>
</td>
</tr>
<tr>
<td><?php echo $entry_max_item; ?></td>
<td>
<select name="max" id="maxitem">
<?php
for($i=1; $i<=6; $i++)
{
if($i == 1)
echo "<option selected='selected' value=".$i.">".$i."</option>";
else
echo "<option value=".$i.">".$i."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td><?php echo $entry_product; ?></td>
<td><input type="text" id="product" name="product" value="" placeholder="Input Product" size="40"/></td>
<td><input type="hidden" id="idp" name="idp" value="" /></td>
</tr>
<tr>
<td></td>
<td>
<table>
<tr>
<td><input type="button" id="ADD" value="Add Item"></td>
<td><input type="reset" id="RESET" value="Reset"></td>
</tr>
</table>
</td>
</tr>
<tr>
</tr>
</table>
<table border="1" id="tblname" cellpadding="5" cellspacing="5">
<thead>
<tr>
<td>
Total Item
</td>
<td>
Id Item
</td>
<td>
Name Item
</td>
<td>
DELETE
</td>
<tr>
</thead>
<tbody align="center">
</tbody>
</table>
</form>
</div>
</div>
</div>
<script type="text/javascript"><!--
$('input[name=\'product\']').autocomplete({
delay: 100,
source: function(request, response) {
$.ajax({
url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent(request.term),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
label: item.name,
value: item.product_id
}
}));
}
});
},
select: function(event, ui) {
$('input[name=\'product\']').val(ui.item.label);
$('input[name=\'idp\']').val(ui.item.value);
return false;
},
focus: function(event, ui) {
return false;
}
});
//--></script>
<Script type="text/javascript">
$(document).ready(function(){
var item = 1;
var isAllowed = 3;
var isSet = 0;
$('#ADD').click(function(){
var maxitem = parseInt($("#maxitem").val(), 10); //from max item in html
var iCount = 0;
if($('#product').val()){ // check input product
if( item <= maxitem )
{
iCount = $('#tblname tbody tr').length + 1;
szTr = "<tr><td>";
szTr = szTr + iCount + "</td>";
szTr = szTr + "<td>" +$('#idp').val() +"</td>";
szTr = szTr + "<td>" +$('#product').val() +"</td>";
szTr = szTr + "<td><input type='button' class='DEL' value='DELETE'></td>";
szTr = szTr + "</tr>";
$('#tblname tbody').append(szTr);
item +=1;
isSet = 1;
restFormOpts();
}
else
{
alert ("Max Limit !!!");
}
}else{alert('Enter Product !!! ');}
});
// for delete row
$('body').on('click','#RESET', function() {
item = 1;
isAllowed = 3;
isSet = 0;
$("#maxitem").attr("disabled",false);
$('.DEL').parents('tr').remove();
});
$('body').on('click', 'input.DEL', function() {
$(this).parents('tr').remove();
item -= 1;
});
function restFormOpts()
{
if(isSet === isAllowed) {
$("#ADD").attr("disabled",true);
$("#maxitem").attr("disabled",false);
}
else {
$("#ADD").attr("disabled",false);
$("#maxitem").attr("disabled",true);
}
}
});
</script>
<?php echo $footer; ?>
When I try insert query to my database, value only 1 number.
Then I try Echo for make sure variable is correct but it's wrong, the result is the last user input (Computer, in array(8,6,5,4))? it's should be (2945,8654) not (8,6,5,4)?
Can some one help me for fix this?? I already try fix this problem for 1 week still no hope :(
If you want to insert array variables in database, First you need encode them and then insert them .
Ex. $abc = array(3,45,6,78,89) ;
Query : "INSERT INTO " . DB_PREFIX . "show_product_detail SET product_id = '". $this->db->escape(json_encode($abc)) . "'
I have just downloaded dompdf-0.6.1 and want to use it in my CakePHP 2.0.5 application.
I have included Router::parseExtensions('json', 'pdf'); in routes.php and created a default.ctp in app -> View -> Layouts.
<?php
require_once(APP . 'Vendor' . DS . 'dompdf' . DS . 'dompdf_config.inc.php');
spl_autoload_register('DOMPDF_autoload');
$dompdf = new DOMPDF();
$dompdf->set_paper = 'A4';
$dompdf->load_html(utf8_decode($content_for_layout), Configure::read('App.encoding'));
$dompdf->render();
echo $dompdf->output();
I want to allow a user to view an income statement as a .pdf file - which can be printed. The income statement takes the parameters of startDate and endDate for generation.
The file below is the income_statement.ctp. What do I need to do in order to allow a user to view the statement as .pdf by pressing on a link on the browser page?
.......some code......
<div style="text-align: center">
<h1><?php echo $this->Session->read("Business.name"); ?><br>Income Statement</h1>
<h3>
For period starting <?php echo $startDate; ?> to <?php echo $endDate; ?>
</h3>
<table align="center" width="400px;">
<tr>
<th style="text-align: left;" colspan="2">Revenue</td>
</tr>
........code.........
<td style="text-align: left;">
<?php
$space = " ";
for ($i = 0; $i < 12; $i++)
echo $space;
?>
<b>Total Operating Expenses</b>
</td>
<td style="text-align: right;"><b><?php echo number_format($totalExpenses + $saleDiscount, 2); ?></b></td>
</tr>
<tr>
<th style="text-align: right"><?php echo $totalDescription; ?></th>
<th style="text-align: right"><?php echo number_format($net, 2); ?></th>
</tr>
</table>
....Link for view as pdf.....
</div>
You can either save the pdfs as actual files and then link to them (link to site.com/pdf/filename.pdf):
public function action() {
$view = new View(null, false);
$view->set(compact('variable1', 'variable2'));
$view->viewPath = 'Folder';
$output = $view->render('income_statement', 'layout');
spl_autoload_register('DOMPDF_autoload');
$dompdf = new DOMPDF();
$dompdf->set_paper = 'A4';
$dompdf->load_html(utf8_decode($output), Configure::read('App.encoding'));
$dompdf->render();
file_put_contents(APP . 'webroot' . DS . 'pdf' . DS .'filename.pdf');
}
Or, you can just echo what $dompdf returns from the render, and just change your page's headers (link to site.com/controller/action.pdf):
public function action() {
$this->layout = $this->autoRender = false;
$this->response->header(array('Content-type' => 'application/pdf'));
//Code for generating pdf data similar to above
echo $dompdf->render();
}
I have been working on an app in codeigniter which takes a series of optional fields and does a query on the database to return results based on the fields selected. These results are then paginated using the codeigniter pagination library.
The pagination work fine and the results are paginated, the problem is when i for instance get gender to 'male' so that only male results are returned, even though the first page works perfectly, the create_links() function renders pages for every result in the table, and when i change the page all 'where' parameters for the db->get() function are ignored. Any advice with this would be much appreciated.
Code:
Controller:
public function searchcharacter() {
$data = $this->input->post();
$gender = $data['gender'];
$age = $data['approx_age'];
$hairColour = $data['hair_colour'];
$hairLength = $data['hair_length'];
$eyeColour = $data['eye_colour'];
$earType = $data['ear_type'];
$weapons = $data['weapons'];
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/ci-animedb/site/searchcharacter';
$config['total_rows'] = $this->db->get('characters')->num_rows();
$config['per_page'] = 10;
$config['uri_segment'] = 3;
$config['num_links'] = 20;
$this->pagination->initialize($config);
$this->load->model('get_db');
$results['characters'] = $this->get_db->getCharacterList($gender, $age, $hairColour, $hairLength, $eyeColour, $earType, $weapons, $config['per_page']);
$this->load->view('header');
$this->load->view('characterlist', $results, FALSE);
$this->load->view('footer');
}
Model:
function getCharacterList($gender, $age, $hairColour, $hairLength, $eyeColour, $earType, $weapons, $limit) {
if ($gender != "None" && !empty($gender))
{
$this->db->where('gender', $gender);
}
if ($age != "None" && !empty($age))
{
$this->db->where('approx_age', $age);
}
if ($hairColour != "None" && !empty($hairColour))
{
$this->db->where('hair_colour', $hairColour);
}
if ($hairLength != "None" && !empty($hairLength))
{
$this->db->where('hair_length', $hairLength);
}
if ($eyeColour != "None" && !empty($eyeColour))
{
$this->db->where('eye_colour', $eyeColour);
}
if ($earType != "None" && !empty($earType))
{
$this->db->where('ear_type', $earType);
}
if ($weapons != "None" && !empty($weapons))
{
$this->db->where('weapons', $weapons);
}
$query = $this->db->get('characters', $limit, $this->uri->segment(3));
return $query->result();
}
View:
<div class="container">
<div class="row">
<div class="span12">
<img src="<?php echo base_url(); ?>img/banner1.png" alt="AnimeDB.me" />
</div>
</div>
<div class="row">
<div class="span12" style="height:1px; background-color: #cccccc; margin-top: 20px; margin-bottom: 15px;"></div>
</div>
<div class="row">
<div class="span12" id="ajaxcontainer">
<table class='table table-striped' id='resulttable' >
<thead>
<th>Image</th>
<th>Name</th>
<th>Anime</th>
</thead>
<tbody>
<?php
foreach ($characters as $row) {
echo "<tr class='resulttr'><td><a href='" . base_url('site/character'). '/' . $row->character_id . "' ><image height=140 width=140 src='" . base_url('img/characterimage') . "/" . $row->file_path . "' /></a></td>";
echo "<td>" . $row->character_name . "</td>";
echo "<td>" . $row->anime . "</td>";
echo "<td class='rowid' style='display:none;'>" . $row->character_id . "</td></tr>";
}
?>
</tbody>
</table>
<div class="form-actions">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
</div>
</div> <!-- /container -->
$config['total_rows'] = $this->db->get('characters')->num_rows();
This is what the Pagination class uses to determine the number of links to create. You're telling it to use every row in the characters table.
You'll need to add your WHERE constraints to this query as well to get the correct number of total records.