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>
Related
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 } ?>
`
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 tried to highlight records whose certain columns have some values other than NULL. I'm using dataTable plugin.
<table class="table table-striped table-hover" id="checkin-checkout-record-table">
<thead>
<tr>
<th>Employee Name</th>
<th>Check-in-date</th>
<th>Check-in-time</th>
<th>Check-out-date</th>
<th>Check-out-time</th>
<th class="col-lg-2">Late Check-in Remarks</th>
<th class="col-lg-2">Early Check-out Remarks</th>
</tr>
</thead>
<tbody>
<?php
foreach ($checkinCheckoutList as $member): ?>
<tr <?php
if(isset($member['early_checkout_remarks']) ||isset($member['delayed_checkin_remarks']))
{?>
style="background-color:red;"
<?php } ?> >
<td><?php echo $member['fullname'] ?></td>
<td> <?php echo $member['checkin_date']; ?></td>
<td> <?php echo $member['checkin_time']; ?></td>
<td><?php echo $member['checkout_date']; ?></td>
<td><?php echo $member['checkout_time']; ?></td>
<td><?php echo $member['delayed_checkin_remarks']; ?></td>
<td><?php echo $member['early_checkout_remarks']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
But the result is not as expected. Some records are not highlighted. This works well with other normal table. Please help.
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
I'm a PHP noob, I keep getting this error:
Parse error: syntax error, unexpected end of file...
The line it points to is at the very last line. My 'header.php' declares the !DOCTYPE html and my 'config.php' holds the database properties.
Any help would be greatly appreciated.
<?php
include 'config.php';
include 'header.php';
?>
<div id='wrapper'>
<div style='height:50em;width:100%;z-index:10;margin-top:1em;text-align:left;'>
<table id='mainDPUtable'>
<th class='cen'>NUM</th>
<th class='cen'>TYP</th>
<th class='cen'>LVL</th>
<th class='cen'>Job No.</th>
<th class='cen'>Responsible</th>
<th class='cen'>Rep</th>
<th class='cen'>Initiated</th>
<th class='cen'>Age</th>
<th class='cen'>Part Number</th>
<th class='cen'>Qty</th>
<th class='cen'>Description</th>
<th class='cen'>Location</th>
<th class='cen'>Complete</th>
<?php
$db = new PDO("mysql:host=localhost;dbname=".$dbname.",".$user.",".$pswd);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$result = $db->prepare("SELECT NUM, TYP, LVL, JOBNO, RESP, REP, DATE_INITIATED, AGE, PARTNO, QTY, DESCRIPTION, LOC FROM ".$dbtable);
$result->execute();
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
$num=$row["NUM"];
$typ=$row["TYP"];
$lvl=$row["LVL"];
$jobNo=$row["JOBNO"];
$resp=$row["RESP"];
$rep=$row["REP"];
$date_initiated=$row["DATE_INITIATED"];
$age=$row["AGE"];
$partNo=$row["PARTNO"];
$qty=$row["QTY"];
$description=$row["DESCRIPTION"];
$loc = $row["LOC"];
$comp=$row["COMP"];
?>
<tr>
<td><?php echo $num; ?></td>
<td><?php echo $typ; ?></td>
<td><?php echo $lvl; ?></td>
<td><?php echo $jobNo; ?></td>
<td><?php echo $resp; ?></td>
<td><?php echo $rep; ?></td>
<td><?php echo $date_initiated; ?></td>
<td><?php echo $age; ?></td>
<td><?php echo $partNo; ?></td>
<td><?php echo $qty; ?></td>
<td><?php echo $description; ?></td>
<td><?php echo $loc; ?></td>
<td><input type='button' id=<?php echo 'btn'.$num; ?> value='Complete'/></td>
</tr>
<?php}?>
</table>
</div>
</div>
</body>
</html>
Missing spaces:
<?php}?>
should be
<?php } ?>
^-^--