I have the following smarty code to display in table....
<table id="hor-zebra" summary="DIsh Information">
<thead>
<tr>
<th scope="col">Item Name</th>
<th scope="col">Item Price</th>
<th scope="col">Item Type</th>
<th scope="col">Quantity</th>
</tr>
</thead>
{foreach name=f1
item=k
from=$res}
<tbody><tr class="odd">
<td id="bn"> {$k->b_name}</td>
<td> {$k->b_price}</td>
<td> {$k->b_type}</td>
<td> {$k->b_quantity}</td></tr>
<tr><td>Remove</td>
<td id="resId"></td></tr>
{/foreach}
</tbody></table>
And the ajax code is....
function remove(){
var http = GetXmlHttpObject();
http.onreadystatechange = function()
{
if(http.readyState==4)
{
document.getElementById("resId").innerHTML = http.responseText;
//alert(http.responseText);
}
}
var name = document.getElementById("bn").innerHTML;
alert(name);
var url = "index.php?menu=rmv&ajax=ajax&q="+name;
http.open('POST',url,true);
http.send(null);
}
Now the problem is that var name is returning only the first Item Name whether i click 2nd or 3rd or so on.........I need the name which i want to remove.But alert showing only the 1st.......
Try this :
<table id="hor-zebra" summary="DIsh Information">
<thead>
<tr>
<th scope="col">Item Name</th>
<th scope="col">Item Price</th>
<th scope="col">Item Type</th>
<th scope="col">Quantity</th>
</tr>
</thead>
{foreach name=f1 item=k key = ky from=$res}
<tbody><tr class="odd">
<td id="bn{$ky}"> {$k->b_name}</td>
<td> {$k->b_price}</td>
<td> {$k->b_type}</td>
<td> {$k->b_quantity}</td></tr>
<tr><td>Remove</td>
<td id="resId{$ky}"></td></tr>
{/foreach}
</tbody>
</table>
And change you javascript to :
function remove(key){
var http = GetXmlHttpObject();
http.onreadystatechange = function()
{
if(http.readyState==4)
{
document.getElementById("resId"+key).innerHTML = http.responseText;
//alert(http.responseText);
}
}
var name = document.getElementById("bn"+key).innerHTML;
alert(name);
var url = "index.php?menu=rmv&ajax=ajax&q="+name;
http.open('POST',url,true);
http.send(null);
}
Let me know if it worked or not .
Related
I am trying to hide the table row for user_id. I only want to show the full name, user name, and actions in the table. I tried to remove the code for the user id row, but it affected the other functionalities like the edit and delete.
here is the code:
<form method="post" id="editForm">
<table class="table">
<tbody>
<tr>
<th scope="col">USER ID</th>
<th scope="col">FULL NAME</th>
<th scope="col">USER NAME</th>
<th scope="col">ACTIONS</th>
</tr>
<?php $a = 0?>
<?php while ($row = mysqli_fetch_array($res)) {
echo "<tr id=".$a++.">
<th scope='row' class='row-data'>".$row['user_id']."</th>
<td class='row-data'>".$row['full_name']."</td>
<td class='row-data'>".$row['user_name']."</td>
<td><input type='button'
value='EDIT'
onclick='editUser()'' /></td>
<td><input type='button'
value='DELETE'
onclick='deleteUser()' /></td>
</tr>
</tbody>";
}; ?>
You could try modifying the editUser() and deleteUser() Javascript methods to accept a userId parameter. It would probably clean up some of the code as well on the JS side. Just a suggestion though. That snippet then might look something like this:
<form method="post" id="editForm">
<table class="table">
<tbody>
<tr>
<th scope="col">FULL NAME</th>
<th scope="col">USER NAME</th>
<th scope="col">ACTIONS</th>
</tr>
<?php $a = 0?>
<?php while ($row = mysqli_fetch_array($res)) {
echo "<tr id='".$a++."'>
<td class='row-data'>".$row['full_name']."</td>
<td class='row-data'>".$row['user_name']."</td>
<td><input type='button'
value='EDIT'
onclick='editUser(".$row['user_id'].")'' /></td>
<td><input type='button'
value='DELETE'
onclick='deleteUser(".$row['user_id'].")' /></td>
</tr>
</tbody>";
}; ?>
Otherwise you could use Ken's solution which would probably work with your existing code.
Instead of removing the column, you can set the display style to 'none' for this column
(add style="display:none;")
Hence (1) change
<th scope="col">USER ID</th>
to
<th scope="col" style="display:none;">USER ID</th>
and (2) change
<th scope='row' class='row-data'>".$row['user_id']."</th>
to
<th scope='row' class='row-data' style="display:none;">".$row['user_id']."</th>
EDIT: May I ask for assistance regarding this code?
This is my modal. My input text receives a value of AAA-123-0001
This script is being included into the main page via include()
<input type="hidden" class="decid" id="id" name="id">
<?php include 'includes/services_payslip_list_payslip-selection.php'; ?>
This is my services_payslip_list_payslip-selection.php
<script>
$(document).ready(function() {
$("#id").change(function() {
var id = $(this).val();
if(id != "") {
$.ajax({
url:"services_payslip_list-payslip-table.php",
data:{id:id},
type:'POST',
success:function(response) {
var resp = $.trim(response);
$("#id").html(resp);
}
});
}
});
</script>
This is my services_payslip_list-payslip-table.php
<table id="example2" class="table table-bordered">
<thead>
<th>Schedule Date</th>
<th>Schedule Name</th>
<th>Recorded In</th>
<th>Recorded Out</th>
<th>Day Count</th>
<th>Day Value</th>
<th>N.D. Value</th>
<th>Leave Count</th>
<th>R.H. Count</th>
<th>R.H. Value</th>
</thead>
<tbody>
<?php
include 'includes/session.php';
if(isset($_POST['id'])) {
$id=$_POST['id']
}
$user = $user['fingerscanno'];
$sql = "SELECT fingerscanno, scheduledate, schedulename, recordin, recordout, noofdays, rate, nightdifferential, leaveday, regularholiday, specialholiday, referenceno
FROM payrollrecords WHERE fingerscanno='$user' and referenceno='$id'";
$query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
echo "
<tr>
<td>".$row['scheduledate']."</td>
<td>".$row['schedulename']."</td>
<td>".$row['recordin']."</td>
<td>".$row['recordout']."</td>
<td>".$row['noofdays']."</td>
<td>".$row['rate']."</td>
<td>".$row['nightdifferential']."</td>
<td>".$row['leaveday']."</td>
<td>".$row['regularholiday']."</td>
<td>".$row['specialholiday']."</td>
</tr>
";
}
?>
</tbody>
</table>
What seems to be the problem here? services_payslip_list_payslip-selection.php won't load into the modal.
How can I retrieve this line of echo code from my php file to my jquery and I am expecting rows of values.
my php file
foreach($stmt as $warrior){
echo '<td>'.$warrior['warrior_id'].'</td><td>'.$warrior['warrior_name'].'</td><td>'.$warrior['warrior_type'].'</td>';
}
my js script
<script>
function createWarrior() {
$.post( "create_warrior.php", {
"wname": $("#txtWname").val(),
"wtype": $("#txtWtype").val()
},
function(msg){
//What should I put here
});
return false;
}
</script>
my html code
<table>
<tr>
<th colspan="3">Warrior</th>
</tr>
<tr>
<th>Warrior ID</th>
<th>Warrior Name</th>
<th>Warrior Type</th>
</tr>
<tr>
//the output should be here
</tr>
add tags <tr> at the beginning and end
foreach($stmt as $warrior){
echo '<tr><td>'.$warrior['warrior_id'].'</td><td>'.$warrior['warrior_name'].'</td><td>'.$warrior['warrior_type'].'</td></tr>';
}
the result will be
<tr><td>warrior_id_1</td><td>warrior_name_1</td><td>warrior_type_1</td></tr>
<tr><td>warrior_id_2</td><td>warrior_name_2</td><td>warrior_type_2</td></tr>
....
this answer you need to get in the js and append to html:
<script>
$.ajax({
url: 'create_warrior.php',
//Send data to php if you need. In php use $_POST['wname'] to read this data.
data: {wname: $("#txtWname").val(),wtype: $("#txtWtype").val() },
success: function(data) {
$('#dataTable').append(data);
}
});
</script>
HTML
<table id = "dataTable">
<tr>
<th colspan="3">Warrior</th>
</tr>
<tr>
<th>Warrior ID</th>
<th>Warrior Name</th>
<th>Warrior Type</th>
</tr>
</table>
Something like (note the added <tr></tr>)
foreach($stmt as $warrior){
echo '<tr><td>'.$warrior['warrior_id'].'</td><td>'.$warrior['warrior_name'].'</td><td>'.$warrior['warrior_type'].'</td></tr>';
}
with
<script>
function createWarrior() {
$.post( "create_warrior.php", {
"wname": $("#txtWname").val(),
"wtype": $("#txtWtype").val()
},
function(msg){
$('#mytable').append(msg);
});
return false;
}
</script>
and
<table id="mytable">
<tr>
<th colspan="3">Warrior</th>
</tr>
<tr>
<th>Warrior ID</th>
<th>Warrior Name</th>
<th>Warrior Type</th>
</tr>
</table>
should work I believe, didn't try it.
I have a spinner and what happens is that whatever number is in the spinner, when the form is submitted, it should display the word "quest" as many times as the number in the spinner.. E.g if number in spinner is 3, then it will display "quest" 3 times in the table.
The problem is displaying it in the table.
At the moment with my current code it is displaying it like this:
quest
quest
quest
Question Id, Option Type, Duration .... These are table headings
It is displaying the words quest outside the table
Instead I want the word "quest" to be displayed in the Question Id column like this:
Question Id, Option Type, Duration...
quest
quest
quest
How can I get it to display it like the example above?
Below is code
<table border=1 id="qandatbl" align="center">
<tr>
<th class="col1">Question No</th>
<th class="col2">Option Type</th>
<th class="col1">Duration</th>
<th class="col2">Weight(%)</th>
<th class="col1">Answer</th>
<th class="col2">Video</th>
<th class="col1">Audio</th>
<th class="col2">Image</th>
</tr>
<?php
$spinnerCount = $_POST['txtQuestion'];
if($spinnerCount > 0) {
for($i = 1; $i <= $spinnerCount; $i++) {
echo "<tr>quest";
}
}
?>
<td class='qid'></td>
<td class="options"></td>
<td class="duration"></td>
<td class="weight"></td>
<td class="answer"></td>
<td class="video"></td>
<td class="audio"></td>
<td class="image"></td>
</tr>
</table>
I did try echo "<td class='qid'></td>"; but this completely failed as well
Try this:
<table border=1 id="qandatbl" align="center">
<tr>
<th class="col1">Question No</th>
<th class="col2">Option Type</th>
<th class="col1">Duration</th>
<th class="col2">Weight(%)</th>
<th class="col1">Answer</th>
<th class="col2">Video</th>
<th class="col1">Audio</th>
<th class="col2">Image</th>
</tr>
<?php
$spinnerCount = $_POST['txtQuestion'];
if($spinnerCount > 0) {
for($i = 1; $i <= $spinnerCount; $i++) {
?>
<tr>
<td class='qid'><?php echo $quest; ?></td>
<td class="options"></td>
<td class="duration"></td>
<td class="weight"></td>
<td class="answer"></td>
<td class="video"></td>
<td class="audio"></td>
<td class="image"></td>
</tr>
<?php
} // For
} // If
?>
</table>
Is this what you want to do? Display "quest" in the first column?
<table border=1 id="qandatbl" align="center">
<tr>
<th class="col1">Question No</th>
<th class="col2">Option Type</th>
<th class="col1">Duration</th>
<th class="col2">Weight(%)</th>
<th class="col1">Answer</th>
<th class="col2">Video</th>
<th class="col1">Audio</th>
<th class="col2">Image</th>
</tr>
<?php
$spinnerCount = $_POST['txtQuestion'];
if($spinnerCount > 0) {
for($i = 1; $i <= $spinnerCount; $i++) { ?>
<tr>
<td class='qid'>quest</td>
<td class="options"></td>
<td class="duration"></td>
<td class="weight"></td>
<td class="answer"></td>
<td class="video"></td>
<td class="audio"></td>
<td class="image"></td>
</tr>
<?php
}
}
?></table>
?>
I have the following code:
<table id="box-table-a" class="tablesorter">
<thead>
<tr>
<th scope="col">B-House/Dorm Name</th>
<th scope="col">Address</th>
<th scope="col">Price Range</th>
<th scope="col">Date Added</th>
<th scope="col">Status</th>
</tr>
</thead>
<?php
$q=mysql_query("select * from property");
while( $f=mysql_fetch_array($q, MYSQL_ASSOC))
{ $p_id=$f["p_id"];
echo"
<tbody>
<tr>
<td onblurr='hover2()' onmouseover='hover(".$p_id.")' onclick='showUser(".$p_id.")'>
<span style='cursor:pointer'>".$f['p_name']."</span></td>
<td id='pretty'>".$f['address']."</td>
<td>".$f['p_name']."</td> <td>".$f['payment_type']."</td> <td>".$status."</td> </tr>
</tbody>
";
}
?>
</table>
Any idea what may be wrong here?
Don't add <tbody></tbody> to every loop in the while! Tablesorter is very sensitive.
You did'nt sort your DB :
$q=mysql_query("select * from property ORDER BY p_name");