?php foreach($participants as $participant) {
echo "<tr>";
echo "<td>" . $participant['Vorname'] . "</td>";
echo "<td>" . $participant['Auto'] . "<img id=$participant[name_id] onclick='deleteDriver()' class='delete' src='img/tonne.gif' align='right' data-url='backend/queries.php?decision=deleteDriver&id=".$participant['name_id']."'/></td>";
echo "</tr>";
}
?>
function deleteDriver()
{
var dataString = "decision=deleteDriver";
$.ajax({
type: 'POST',
url: 'queries.php',
data: dataString
}
})
}
</script>
When I push the button the function is not called. Why?
try with this code.
<?php
foreach($participants as $participant) {
echo "<tr>";
echo "<td>" . $participant['Vorname'] . "</td>";
echo "<td><a onclick='deleteDriver()'>" . $participant['Auto'] . "<img id=$participant[name_id] class='delete' src='img/tonne.gif' align='right' data-url='backend/queries.php?decision=deleteDriver&id=".$participant['name_id']."'/></a></td>";
echo "</tr>";
}
?>
<script>
function deleteDriver()
{
var dataString = "decision=deleteDriver";
$.ajax({
type: 'POST',
url: 'queries.php',
data: dataString
})
}
</script>
You have missed <script> open tag before function deleteDriver(). Please add and retry. Try as below :
<?php
foreach($participants as $participant) {
echo "<tr>";
echo "<td>" . $participant['Vorname'] . "</td>";
echo "<td>" . $participant['Auto'] . "<img id='".$participant['name_id']."' onclick='deleteDriver()' class='delete' src='img/tonne.gif' align='right' data-url='backend/queries.php?decision=deleteDriver&id=".$participant['name_id']."'/></td>";
echo "</tr>";
}
?>
<script>
function deleteDriver()
{
var dataString = "decision=deleteDriver";
$.ajax({
type: 'POST',
url: 'queries.php',
data: dataString
}
});
}
</script>
Related
enter image description here
Please help me..
auto fill works for the first field
but I have problem in the second row and next row too. When I change the select option on second row, the previous field changed (not same row as what I have changed):
enter image description here
var Nomor = $('#TabelTambahBarang tbody tr').length + 1;
var Baris = "<tr>";
Baris += "<td class='txt-center'>"+Nomor+"</td>"var Baris = "<tr>";
Baris += "<td class='txt-center'>"+Nomor+"</td>";
Baris += "<td>";
Baris += "<select placeholder='Items Name' class='form-control input-sm select2' name='nama_barang[]' id='nama_barang" + Nomor + "' data-Nomor='" + Nomor + "'>";
Baris += "<option disabled value='' name='nama_barang[]' id='nama_barang" + Nomor + "' data-Nomor='" + Nomor + "' selected hidden>-- Silahkan Nama Barang --</option>";;enter code here
<?php
if (!empty($dataBarang)) {
foreach ($dataBarang as $k) { ?>
Baris += "<option value='<?php echo $k->nama_barang; ?>'><?php echo $k->nama_barang; ?></option>";
<?php }
}
?>
Baris += "</select>";
Baris += "</td>";
Baris += "<td class='txt-center'><input class='form-control input-sm' id='harga_barang' placeholder='Harga Barang' name='harga_barang'/></td>";
Baris += "<td align='center'><a id='HapusBaris'>Delete</a></td>";
Baris += "</tr>";
$('#TabelTambahBarang tbody').append(Baris);
Nomor++;
select2();
}
$(document).on("change", ".select2", function(e) {
var select = $(this);
var nama_barang = select.val();
$.ajax({
type : "POST",
url : "<?php echo base_url('get_barang')?>",
dataType : "json",
data : {nama_barang: nama_barang},
cache:false,
success: function(data){
$.each(data,function(harga_barang){
$('[id="harga_barang"]').val(data.harga_barang);
});
}
});
});
function select2(){
$('.select2').select2()
}
Controller
public function get_barang(){
$nama_barang = $this->input->post('nama_barang');
$data = $this->m_testing->get_barang($nama_barang);
echo json_encode($data);
}
Model
function get_barang($nama_barang){
$hsl = $this->db->query("SELECT * FROM tabel_barang WHERE nama_barang='$nama_barang'");
if($hsl->num_rows()>0){
foreach ($hsl->result() as $data) {
$hasil=array(
'nama_barang' => $data->nama_barang,
'harga_barang' => $data->harga_barang,
);
}
}
return $hasil;
}
I have a table where data is fetched from the MYSQLi table, I have a column as 'status' where it has two values of ACTIVE and DEACTIVE. I need deactive in different bg color/font color and active status in the different color, how could I achieve this through if else statement. At least td is changed also no problem.
<?php
// Include config file
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM retail";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table js-dynamitable table-bordered table-striped table-condensed'>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>operator_name</th>";
echo "<th>zone</th>";
echo "<th>nas_ip</th>";
echo "<th>switch_name</th>";
echo "<th>switch_ip</th>";
echo "<th>switch_port</th>";
echo "<th>connected_port</th>";
echo "<th>vlan</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['operator_name'] . "</td>";
echo "<td>" . $row['zone'] . "</td>";
echo "<td>" . $row['nas_ip'] . "</td>";
echo "<td>" . $row['switch_name'] . "</td>";
echo "<td>" . $row['switch_ip'] . "</td>";
echo "<td>" . $row['switch_port'] . "</td>";
echo "<td>" . $row['connected_port'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>";
echo "<a href='readr.php?id=". $row['id'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='updater.php?id=". $row['id'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='deleter.php?id=". $row['id'] ."' data-toggle='modal' data-target='#exampleModalLong' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
I am Using this script too, which is correct format for header
var $table = $('table');
$table.bootstrapTable({
search: true,
pagination: true,
buttonsClass: 'primary',
minimumCountColumns: 2,
columns: [{
field: 'id',
title: 'ID',
sortable: true,
}, {
field: 'operator_name',
title: 'OPERATOR NAME',
sortable: true,
}, {
field: 'zone',
title: 'zone',
sortable: true,
},
{
field: 'nas_ip',
title: 'nas_ip',
sortable: true,
},
{
field: 'switch_name',
title: 'SWITCH NAME',
sortable: true,
},
{
field: 'switch_ip',
title: 'SWITCH IP',
sortable: true,
},
{
field: 'switch_port',
title: 'SWITCH PORT ',
sortable: true,
},
{
field: 'connected_port',
title: 'connected_port',
sortable: true,
},
{
field: 'vlan',
title: 'VLAN',
sortable: true,
},
{
field: 'operation',
title: 'Action',
},
],
});
So you're using bootstrab table plugin. You need to add rowStyle handler.
In your JS script you can try add.
function rowStyle(row, index) {
var classes = ['success','danger'];
if(row.vlan=="ACTIVE")
return {
classes: classes[0]
};
if(row.vlan=="DEACTIVE")
return {
classes: classes[1]
};
return {};
}
In your PHP file:
Change:
echo "<table class='table js-dynamitable table-bordered table-striped table-condensed'>";
To:
echo "<table data-row-style='rowStyle' class='table js-dynamitable table-bordered table-striped table-condensed'>";
Change:
echo "<th>vlan</th>";
To:
echo "<th data-field='vlan'>vlan</th>";
Demo: http://jsfiddle.net/jyjafk8v/
http://bootstrap-table.wenzhixin.net.cn/documentation/ - search 'rowStyle' if you need more info about it.
I have changed status td (column) . Add inline style and apply background color on if else base. Check the code below.
<?php
// Include config file
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM retail";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table js-dynamitable table-bordered table-striped table-condensed'>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>operator_name</th>";
echo "<th>zone</th>";
echo "<th>nas_ip</th>";
echo "<th>switch_name</th>";
echo "<th>switch_ip</th>";
echo "<th>switch_port</th>";
echo "<th>connected_port</th>";
echo "<th>vlan</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['operator_name'] . "</td>";
echo "<td>" . $row['zone'] . "</td>";
echo "<td>" . $row['nas_ip'] . "</td>";
echo "<td>" . $row['switch_name'] . "</td>";
echo "<td>" . $row['switch_ip'] . "</td>";
echo "<td>" . $row['switch_port'] . "</td>";
echo "<td>" . $row['connected_port'] . "</td>";
echo "<td style='color:white;background-color:".($row['status'] == 'ACTIVE'?'green':'grey').";'>" . $row['status'] . "</td>";
echo "<td>";
echo "<a href='readr.php?id=". $row['id'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='updater.php?id=". $row['id'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='deleter.php?id=". $row['id'] ."' data-toggle='modal' data-target='#exampleModalLong' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " .
mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
I need to check/uncheck a table checkbox based on a value stored in a database. I'm not an experienced programmer. I've been Google-ing this for a whole day with no luck. Hope someone's going to help me.
Here's the code :
echo "<table data-toggle='table' data-click-to-select='true' id='potable'>";
echo "<thead>";
echo "<tr>";
echo "<th data-field='state' data-checkbox='true'></th>";
echo "<th data-field='code'>Code</th>";
echo "<th data-field='description'>Description</th>";
echo "<th data-field='verb'>Verb</th>";
echo "<th>Actions</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
echo "<tr>";
echo "<td>"; ?>
<script>
var select = <?php echo "{$selected}"; ?>;
if (select == 1) {
// INSERT HERE JAVASCRIPT LINE THAT CHECKS THE CURRENT CHECKBOX
else {
//UNCHECK THE CURRENT CHECKBOX
}
</script>
<?php
echo "</td>";
echo "<td>{$code}</td>";
echo "<td>{$description}</td>";
echo "<td>{$verb}</td>";
echo "<a type='button' class='btn btn-primary left-margin' href='po-info.php?id={$id}'>Info</a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
Finally managed to make it work
Used
echo "<th data-field='selected' data-checkbox='true' data-formatter='stateFormatter'></th>";
then
<script>
function stateFormatter(value, row, index) {
if (value == 1) {
return {
checked: true
};
} else {
return {
checked: false
};
}
return value;
}
</script>
Try
$("th[data-checkbox='true'] input[type=checkbox]").attr('checked', <?=$selected?'true':'false'?>);
<table>
<?php
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
$checked_ids = array();
$checked_ids[] = $id;
$chk_str = '<input data-index="%s" name="chk" type="checkbox">';
echo "<tr>";
echo "<td>";
printf($chk_str, $id);
echo "</td>";
echo "</tr>";
}
?>
</table>
<input type="hidden" id="db_checked" value="<?php echo implode(",",$checked_ids); ?>" />
<script>
// need jquery.js
$(function () {
var $table = $('#potable'),
var string = $('#db_checked').val();
var array = string.split(',');
for (var ck_id in array) {
$table.bootstrapTable('check', parseInt(ck_id, 10));
// check or uncheck
}
}
</script>
maybe "data-index" is write at "tr" tags
I guys, I need yo help for this. I have this code, wich shows me the products I have in my shopping cart:
for($i=0;$i<count($_SESSION['productos']);$i++)
{
$id = $_SESSION['productos'][$i];
$prods = mysql_query('SELECT * from productos where idprod='.$id.'');
$row = mysql_fetch_array($prods);
echo "<tr>";
echo "<td>" . $row['nombre']; echo "</td>";
if($_GET[action]=="suma")
{
$_SESSION['unidades'][$i] = $_SESSION['unidades'][$i] + 1;
}
elseif($_GET[action]=="resta")
{
$_SESSION['unidades'][$i] = $_SESSION['unidades'][$i] - 1;
}
echo "<td><input name=".$i." type='text' value=" . $_SESSION['unidades'][$i]; echo " size='5'/></td>";
echo "<td><a href='carro_detalle.php?action=suma'><img src='images/flecharriba.png' width='10x' height='10px'/></a></td>";
echo "<td><a href='carro_detalle.php?action=resta'><img src='images/flechabajo.png' width='10px' height='10px'/></a></td>";
echo "<td>" . $row['precio']; echo "</td>";
echo "<td>" . $row['precio'] * $_SESSION['unidades'][$i]; echo "</td>";
echo "</tr>";
}
I need to sum 1 unity or rest 1 unity to $_SESSION['unidades'][$i] just to the selected product, when I click the two images respectively.
The thing is that when I click, it adds me 1 to all the products. Any easy way of doing this without using $_GET vars? I dont have high knowledge about JavasScript.
Thanks!!
You probably should remove your condition from the loop and put it outside of it:
if($_GET[action]=="suma")
{
$_SESSION['unidades'][$i] = $_SESSION['unidades'][$i] + 1;
}
elseif($_GET[action]=="resta")
{
$_SESSION['unidades'][$i] = $_SESSION['unidades'][$i] - 1;
}
for($i=0;$i<count($_SESSION['productos']);$i++)
{
$id = $_SESSION['productos'][$i];
$prods = mysql_query('SELECT * from productos where idprod='.$id.'');
$row = mysql_fetch_array($prods);
echo "<tr>";
echo "<td>" . $row['nombre']; echo "</td>";
echo "<td><input name=".$i." type='text' value=" . $_SESSION['unidades'][$i]; echo " size='5'/></td>";
echo "<td><a href='carro_detalle.php?action=suma'><img src='images/flecharriba.png' width='10x' height='10px'/></a></td>";
echo "<td><a href='carro_detalle.php?action=resta'><img src='images/flechabajo.png' width='10px' height='10px'/></a></td>";
echo "<td>" . $row['precio']; echo "</td>";
echo "<td>" . $row['precio'] * $_SESSION['unidades'][$i]; echo "</td>";
echo "</tr>";
}
I have used this function to pop up a window, when a user clicked the table row
<script type="text/javascript">
$(document).ready(function() {
$("td.abc").click(function() {
var t = 'Ticket ID: ' + $(this).find('td:eq(0)').html()+'\n'+'\n';
var r = 'Subject: ' + $(this).find('td:eq(1)').html()+'\n'+'\n';
var e = 'Messege: ' + $(this).find('td:eq(2)').html()+'\n'+'\n';
var f = 'Developer: ' + $(this).find('td:eq(3)').html()+'\n'+'\n';
var w = 'Current Status: ' + $(this).find('td:eq(4)').html()+'\n'+'\n';
var q = 'Uploaded Date & Time: ' + $(this).find('td:eq(5)').html()+'\n'+'\n';
var o = $("#79").attr("name")+'\n'+'\n';
alert(t+r+e+f+w+q+o);
});
});
</script>
my table is as follows
echo "<br> <table border='0' id='example' width='980' align='center'>
<tr>
<th width='60'>Ticket ID</th>
<th width='150'>Subject</th>
<th width='670'>Messege</th>
<th width='60'>Developer</th>
<th width='70'>Status</th>
<th width='105'>Date - Time</th>
</tr>";
while($row = mysql_fetch_array($result)) {
//echo $row['jobSatus'];
echo "<tr>";
echo "<td class=\"abc\" width='60'>" . $row['id'] . "</td>";
echo "<td class=\"abc\" width='150'>" . $row['subject'] . "</td>";
echo "<td class=\"abc\" width='670'>" . $row['msg'] . "</td>";
echo "<td class=\"abc\" width='60'>" . $row['developer'] . "</td>";
echo "<td class=\"abc\"width='60'>" . $row['jobstatus'] . "</td>";
echo "<td class=\"abc\" width='105'>" . $row['date_time'] . "</td>";
echo "<input class=\"abc\" type='hidden' name=".$row['image']." id=".$row['id'].">";
echo "</tr>";
}
echo "</table>";
Now inside the pop window I don't get any values. It says "undefined". I would be very thankful if someone could show what I have done wrong.
try to change this...
var t = 'Ticket ID: ' + $(this).find('td:eq(0)').html()+'\n'+'\n';
to this
var t = 'Ticket ID: ' +$(this).closest('td:eq(0)').attr('class');
Hope this will help....
You are clicking on a table cell, not a table row
$("td.abc").click(function() {
^^
Change it to look at the table
$("#example").on("click", "tr", function () {
or
$("#example").on("click", "tr:has(td.abc)", function () {
And your HTML markup is invalid since an input element can not be a child element of a tr.
Set onclick on table-row
$("tr.ticker-row").click(function(ev) {
var $this = $(ev.currentTarget);
var t = 'Ticket ID: ' + $this.find('td:eq(0)').html()+'\n'+'\n';
var r = 'Subject: ' + $this.find('td:eq(1)').html()+'\n'+'\n';
var e = 'Messege: ' + $this.find('td:eq(2)').html()+'\n'+'\n';
var f = 'Developer: ' + $this.find('td:eq(3)').html()+'\n'+'\n';
var w = 'Current Status: ' + $this.find('td:eq(4)').html()+'\n'+'\n';
var q = 'Uploaded Date & Time: ' + $this.find('td:eq(5)').html()+'\n'+'\n';
var o = $this.find('input').attr('name') + '\n'+'\n';
alert(t+r+e+f+w+q+o);
});
On php, do not insert any node in tr except td
while($row = mysql_fetch_array($result)) {
//echo $row['jobSatus'];
echo "<tr class=\"ticket-row\" data-row-index=\"".$row['id']."\">";
echo "<td class=\"abc\" width='60'>" . $row['id'] . "<input class=\"abc\" type='hidden' name=".$row['image']." ></td>";
echo "<td class=\"abc\" width='150'>" . $row['subject'] . "</td>";
echo "<td class=\"abc\" width='670'>" . $row['msg'] . "</td>";
echo "<td class=\"abc\" width='60'>" . $row['developer'] . "</td>";
echo "<td class=\"abc\"width='60'>" . $row['jobstatus'] . "</td>";
echo "<td class=\"abc\" width='105'>" . $row['date_time'] . "</td>";
echo "</tr>";
}
echo "</table>";