Move multiple table rows to another table without page refresh - php

I display the table from db. and i have checkbox for each row,I want to move the selected rows from one table to another "selected table" from the page without page refresh. ? the current selection has to be removed from current table. I can do the query like select * from tab-1 where id=$selected. and also can move it to another table with insert into tab_name and so on. but dont know how to do it without refresh and with some nice effects ? may be with jquery any pointers or help.
<table id="tab-1">
<thead>
<tr>
<th scope="col">Select</th>
<th scope="col">ID</th>
<th scope="col">A</th>
<th scope="col">B</th>
<th scope="col">C</th>
<th scope="col">D</th>
<th scope="col">E</th>
<th scope="col">E</th>
<th scope="col">F</th>
<th scope="col">G</th>
<th scope="col">H</th>
<th scope="col">I</th>
<th scope="col">J</th>
<th scope="col">k</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $row['ID']; ?>" /></td>
<td><?php echo $row['ID']; ?></td>
<td><?php echo $row['A']; ?></td>
<td><?php echo $row['B']; ?></td>
<td><?php echo $row['D']; ?></td>
<td><?php echo $row['E']; ?></td>
<td><?php echo $row['F']; ?></td>
<td><?php echo $row['G']; ?></td>
<td><?php echo $row['H']; ?></td>
<td><?php echo $row['I']; ?></td>
<td><?php echo $row['J']; ?></td>
<td><?php echo $row['K']; ?></td>
<td><?php echo $row['L']; ?></td>
<td><?php echo $row['M']; ?></td>
</tr>
</tbody>
<table>

using jQuery , Ajax you can do this .
<script>
$('.checkBox').change(function() {
var selected = $(this).val();
$.post('yourfile.php' , {
selected : selected
} , function(data){
alert(data);
});
});
$('.checkBox').mousedown(function() {
if (!$(this).is(':checked')) {
$(this).trigger("change");
}
});
</script>
in yourfile.php you can execute SELECT and INSERT queries

Related

Php automatic time countdown(timer) as soon as a record is inserted

I have a table for saving details including logging time.Just as soon as a new record is inserted I want the column 'Countdown' to start an automatic time countdown from 30min until it gets to zero(0).How do I go about it?Thanks.
Here is the table php code
`<?php $results = mysqli_query($db, "SELECT
Vehicle_name,Vehicle_make,Vehicle_color,Number_plate,Date,Time FROM
vehicle"); ?>
<div class="table">
<table>
<thead>
<tr>
<th>Vehicle name</th>
<th>Vehicle make</th>
<th>Vehicle color</th>
<th>Reg Number</th>
<th>Date</th>
<th>Time</th>
<th>Countdown</th>
<th colspan="4">Action</th>
</tr>
</thead>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td><?php echo $row['Vehicle_name']; ?></td>
<td><?php echo $row['Vehicle_make']; ?></td>
<td><?php echo $row['Vehicle_color']; ?></td>
<td><?php echo $row['Number_plate']; ?></td>
<td><?php echo $row['Date']; ?></td>
<td><?php echo $row['Time']; ?></td>
<td><?php echo $row['Time']; ?></td>
<td>
<a href="php_code.php?del=<?php echo $row['Number_plate']; ?>"
class="del_btn">Delete</a>
</td>
</tr>
<?php } ?>
`

Give data from database in table numbers

I have a foreach in the table. I foreach a row for every row in my database. So my database has got 10 records, I and my table is showing all those records underneath eachother. So far so good.
I want to number them, from 1 to 10, displayed in front of every row.
This is my table:
<table class="table table-striped mt-3">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Team</th>
<th scope="col">Player</th>
<th scope="col">P</th>
<th scope="col">W</th>
<th scope="col">D</th>
<th scope="col">L</th>
<th scope="col">GF</th>
<th scope="col">GA</th>
<th scope="col">GD</th>
<th scope="col">P</th>
</tr>
</thead>
<tbody>
<?php $count = count($table); ?>
<?php foreach($table as $t): ?>
<tr>
<td><?php for($i = 1; $i < $count; $i++;)
{
echo $i; ?>}
</td>
<td><?php echo $t['team']; ?></td>
<td><?php echo $t['speler']; ?></td>
<td><?php echo $t['gw']; ?></td>
<td><?php echo $t['w']; ?></td>
<td><?php echo $t['g']; ?></td>
<td><?php echo $t['v']; ?></td>
<td><?php echo $t['dv']; ?></td>
<td><?php echo $t['dt']; ?></td>
<td><?php echo $t['ds']; ?></td>
<td><?php echo $t['points']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
This is my method
public function fifaLeagueTable() {
$getTable = "SELECT * FROM fifa_league ORDER BY points DESC";
$table = $this->model->readAll($getTable);
$count = count($table);
include('app/views/fifaLeagueTable.php');
}
If I var_dump the $count, I receive int(10). So it's counting the amount of rows and I have access to the 10. I am getting a white page, so there might be something wrong in the for loop or something. What did I do wrong?
You just need to create one more variable and its done. Here is updated code :
<table class="table table-striped mt-3">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Team</th>
<th scope="col">Player</th>
<th scope="col">P</th>
<th scope="col">W</th>
<th scope="col">D</th>
<th scope="col">L</th>
<th scope="col">GF</th>
<th scope="col">GA</th>
<th scope="col">GD</th>
<th scope="col">P</th>
</tr>
</thead>
<tbody>
<?php $count = count($table); $num = 1; ?>
<?php foreach($table as $t): ?>
<tr>
<td><?php echo $num; ?>
</td>
<td><?php echo $t['team']; ?></td>
<td><?php echo $t['speler']; ?></td>
<td><?php echo $t['gw']; ?></td>
<td><?php echo $t['w']; ?></td>
<td><?php echo $t['g']; ?></td>
<td><?php echo $t['v']; ?></td>
<td><?php echo $t['dv']; ?></td>
<td><?php echo $t['dt']; ?></td>
<td><?php echo $t['ds']; ?></td>
<td><?php echo $t['points']; ?></td>
</tr>
<?php $num++ ; endforeach; ?>
</tbody>
</table>

show multiple rows for each result value

I have two tables one for products and another for items.
I want to show all items details for each product in one table like this:
I have tried to make a nested while loops but the result not as I want.
<table border="1">
<thead>
<th>Product No.</th>
<th>Product Name</th>
<th>T.Qty</th>
<th>Item No.</th>
<th>Item Name</th>
<th>Qty </th>
</thead>
<tbody>
<tr>
<td><?php echo $Product_no ?></td>
<td><?php echo $Product_name?></td>
<td><?php echo $TQty ?></td>
<?php
// my problem is here
$Items= $connect->prepare("Query Statment?");
$Items->execute();
$res = $Items->get_result();
while($GetItems = $res->fetch_assoc()){
?>
<td><?php echo GetItems['Item_no'];?></td>
<td><?php echo GetItems['Item_name']; ?></td>
<td><?php echo GetItems['Qty']; ?></td>
<?php } ?>
</tr>
</tbody>
</table>
but the items displayed beside each other not below.
You have a problem in your html table code. You should close the tag for each row you have, and, in case it is not the first line for that element, insert 3 cells with no data:
<tbody>
<tr>
<td><?php echo $Product_no ?></td>
<td><?php echo $Product_name?></td>
<td><?php echo $TQty ?></td>
<?php
// my problem is here
$Items= $connect->prepare("Query Statment?");
$Items->execute();
$res = $Items->get_result();
$i=0;
while($GetItems = $res->fetch_assoc()){
if ($i!=0){
echo "<td></td><td></td><td></td>";
}
?>
<td><?php echo GetItems['Item_no'];?></td>
<td><?php echo GetItems['Item_name']; ?></td>
<td><?php echo GetItems['Qty']; ?></td>
<?php
echo "</tr>";
$i++;
} ?>
</tbody>

I want ziparchive or other php script to download all files from a folder in zip

<table id="b" class="table table-hover" border="1" cellspacing="0" cellpadding="5">
<tr>
<th>Serial No</th>
<th>Student Name</th>
<th>Student ID</th>
<th>Point ID</th>
<th>CV</th>
<th>USI</th>
<th>Reference</th>
<th>Academic Certificate</th>
<th>Training Documents</th>
<th>Pay Slips</th>
<th>Work Pictures</th>
<th>Other Documents</th>
<th>Work Documents</th>
<th>Applicants Form</th>
<th>Employer Form</th>
<th>Action</th>
</tr>
<?php
$result = mysql_query("select * from student_portal");
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['student_id']; ?></td>
<td><?php echo $row['point_id']; ?></td>
<td><?php echo $row['cv']; ?></td>
<td><?php echo $row['usi']; ?></td>
<td><?php echo $row['reference']; ?></td>
<td><?php echo $row['academic_certificate']; ?></td>
<td><?php echo $row['training_documents']; ?></td>
<td><?php echo $row['Pay_slips']; ?></td>
<td><?php echo $row['work_pictures']; ?></td>
<td><?php echo $row['other_documents']; ?></td>
<td><?php echo $row['work_documents']; ?></td>
<td><?php echo $row['declaraction_form']; ?></td>
<td><?php echo $row['declaraction_employer']; ?></td>
</tr>
Here is the code, I want to download all file in a zip format. In zip file all in a folder.
You will probably have to create a row HTML file of the output and run it through a php zipper function.
Here's one to get you started
function unzip_file($location,$newLocation){
if(exec("unzip $location",$arr)){
mkdir($newLocation);
for($i = 1;$i< count($arr);$i++){
$file = trim(preg_replace("~inflating: ~","",$arr[$i]));
copy($location.'/'.$file,$newLocation.'/'.$file);
unlink($location.'/'.$file);
}
return TRUE;
}else{
return FALSE;
}
}

Submitting Form using Dynamic Text Link

I'm at lost. What I wanted to do is, I want my website to allow the users to select a certain row(records) in my database and then redirect them to another webpage that will show them the full information about that certain record.. I don't know how could I connect those two web pages together using dynamic table/text..
Below is a portion of my code: ( This is the first webpage: )
mysql_select_db($database_rfq_portal, $rfq_portal);
$query_rfqrecord = "SELECT tblrfq.`RFQ_ID`, tblrfq.`Company_Name`, tblrfq.Service,
tblrfq.`Kind_of_Request`, tblrfq.Status, tblrfq.`Date` FROM tblrfq";
$rfqrecord = mysql_query($query_rfqrecord, $rfq_portal) or die(mysql_error());
$row_rfqrecord = mysql_fetch_assoc($rfqrecord);
$totalRows_rfqrecord = mysql_num_rows($rfqrecord);
<form id="viewform" name="viewform" method="get" action="ViewSpecificRFQ.php">
<table width="716" border="1" align="center" cellpadding="5">
<tr>
<td>RFQ ID</td>
<td>Company Name</td>
<td>Service</td>
<td>Kind of Request</td>
<td>Status</td>
<td>Date</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rfqrecord['RFQ_ID']; ?></td>
<td><?php echo $row_rfqrecord['Company_Name']; ?></td>
<td><?php echo $row_rfqrecord['Service']; ?></td>
<td><?php echo $row_rfqrecord['Kind_of_Request']; ?></td>
<td><?php echo $row_rfqrecord['Status']; ?></td>
<td><?php echo $row_rfqrecord['Date']; ?></td>
</tr>
<?php } while ($row_rfqrecord = mysql_fetch_assoc($rfqrecord)); ?>
</table>
}
</form>
This is the webpage that will get the form..(portion of my code)
$RFQID = $_GET['RFQ_ID'];
mysql_select_db($database_rfq_portal, $rfq_portal);
$query_rfqrecord = "SELECT * FROM tblrfq WHERE $RFQID";
$rfqrecord = mysql_query($query_rfqrecord, $rfq_portal) or die(mysql_error());
$row_rfqrecord = mysql_fetch_assoc($rfqrecord);
$totalRows_rfqrecord = mysql_num_rows($rfqrecord);
mysql_select_db($database_rfq_portal, $rfq_portal);
$query_user = "SELECT tbluser.Username, tbluser.Password FROM tbluser";
$user = mysql_query($query_user, $rfq_portal) or die(mysql_error());
$row_user = mysql_fetch_assoc($user);
$totalRows_user = mysql_num_rows($user);
<table width="716" border="0" align="center">
<tr>
<th colspan="2" scope="row">RFQ ID:</th>
<td><?php echo $row_rfqrecord['RFQ_ID']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Company Name:</th>
<td width="511"><?php echo $row_rfqrecord['Company_Name']; ?></td>
</tr>
<tr>
<th width="101" rowspan="2" scope="row">Address:</th>
<th width="90" scope="row">Site A:</th>
<td><?php echo $row_rfqrecord['Address_A']; ?></td>
</tr>
<tr>
<th scope="row">Site B:</th>
<td><?php echo $row_rfqrecord['Address_B']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Contact Number:</th>
<td><?php echo $row_rfqrecord['Contact_Number']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Contact Person:</th>
<td><?php echo $row_rfqrecord['Contact_Person']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Service:</th>
<td><?php echo $row_rfqrecord['Service']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Bandwidth:</th>
<td><?php echo $row_rfqrecord['Bandwidth']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Telco:</th>
<td><?php echo $row_rfqrecord['Telco']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Account Manager:</th>
<td><?php echo $row_rfqrecord['Account_Manager']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Status:</th>
<td><?php echo $row_rfqrecord['Status']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Kind of Request:</th>
<td><?php echo $row_rfqrecord['Kind_of_Request']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Date:</th>
<td><?php echo $row_rfqrecord['Date']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Remarks:</th>
<td><?php echo $row_rfqrecord['Remarks']; ?></td>
</tr>
</table>
</form>
this redirects the user to the next page but my problem is it keeps on showing the same record, which is the first record in my database.
1- Consider page1.php is the first page that user selects a record and then in page2.php you show full detail.
for page1.php
you need to send some parameters like record id or any other key in order to be able to identify the record and select the detail in database.
for example:
Record 1 once user clicked on this link you have to do something like this in page2.php, remember our parameter is record_id
<?php
$id = $_GET['record_id'];
//we have to check it for validity
//if id is an integer (numbers) then simply we can check it
//if(!is_numeric($id)) { die("invalid id") }
// now the id is there
//lets build query
$query = "SELECT * from tablename where id= '$id' ";
?>
for your code it must be like this:
//adding where clause
$query_rfqrecord = "SELECT * FROM tblrfq where RFQ_ID = '$id' ";
$rfqrecord = mysql_query($query_rfqrecord, $rfq_portal) or die(mysql_error());
$row_rfqrecord = mysql_fetch_assoc($rfqrecord);
$totalRows_rfqrecord = mysql_num_rows($rfqrecord);
If you want your users to get to load a specific record when they click a specific row, you have to be sure you're redirecting them to a specific url. In your sample you have <a href="ViewSpecificRFQ.php"> in your do-while, so every row in your table will have the same link and then the same destination page.
You probably want something like <a href="ViewSpecificRFQ.php?recordId=<?php echo $row_rfqrecord['RFQ_ID'] ?>"> and then in your landing page the query will be performed against the key you will have in $_GET['recordId'].
EDIT: The do-while problem
You use a do-while, and so in your first iteration you have no record loaded, because the fetch instruction is located at the bottom of the code block, so you should change it to:
<?php
while ($row_rfqrecord = mysql_fetch_assoc($rfqrecord)) {
?>
<tr>
<td><?php echo $row_rfqrecord['RFQ_ID']; ?></td>
<td><?php echo $row_rfqrecord['Company_Name']; ?></td>
<td><?php echo $row_rfqrecord['Service']; ?></td>
<td><?php echo $row_rfqrecord['Kind_of_Request']; ?></td>
<td><?php echo $row_rfqrecord['Status']; ?></td>
<td><?php echo $row_rfqrecord['Date']; ?></td>
</tr>
<?php
}
?>

Categories