I do have some problems with my code.
I would like to change the color on my lables if it goes from one status to another depending on the world from mysql db.
First of all, I have the code:
<table class="table responsive">
<div id="employee_table">
<table class="table">
<tr>
<th width="10%">ARK ID</th>
<th width="20%">User</th>
<th width="45%">Header</th>
<th width="10%">Status</th>
<th width="20%">Priority</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["ark_id"]; ?></td>
<td><?php echo $row["name"]; ?></td>
<td><a href="read.php?id=<?php echo $row['id']; ?>"><?php echo $row["overskrift"]; ?></td>
<td><?php echo $row["prioritet"]; ?></td>
<td><?php echo $row["status"]; ?></td>
</tr>
<?php
}
?>
</table>
Second of all, I'll have Status and priority to change label color like this
If priority is LOW then Green Label
If priority is MEDIUM then Blue
if priority is HIGH then RED
... The same function to the Status Pending .... And so on..
I hope someone could help me :)
Thanks!
You could check the priority on the beginning of the while loop:
<table class="table responsive">
<div id="employee_table">
<table class="table">
<tr>
<th width="10%">ARK ID</th>
<th width="20%">User</th>
<th width="45%">Header</th>
<th width="10%">Status</th>
<th width="20%">Priority</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
if($row["prioritet"] == "LOW") {
$color = '#000000'; // choose color
}
else if($row["prioritet"] == "MEDIUM") {
$color = '#888888'; // choose color
}
else {
$color = '#ffffff'; // choose color
}
?>
<tr>
<td><?php echo $row["ark_id"]; ?></td>
<td><?php echo $row["name"]; ?></td>
<td><a href="read.php?id=<?php echo $row['id']; ?>"><?php echo $row["overskrift"]; ?></td>
<td style="color:<?php echo $color?>"><?php echo $row["prioritet"]; ?></td>
<td style="color:<?php echo $color?>"><?php echo $row["status"]; ?></td>
</tr>
<?php
}
?>
</table>
hope below code help you
<table class="table responsive">
<div id="employee_table">
<table class="table">
<tr>
<th width="10%">ARK ID</th>
<th width="20%">User</th>
<th width="45%">Header</th>
<th width="10%">Status</th>
<th width="20%">Priority</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
if($row["prioritet"] == "LOW") {
$priority_color = '#009933'; // low priority color
}
else if($row["prioritet"] == "MEDIUM") {
$priority_color = '#0099ff'; // Medium priority color
}
else if($row["prioritet"] == "HIGH"){
$priority_color = '#ff0000'; // High priority color
}else{
$priority_color = '#ffffff'; // default color
}
?>
<tr>
<td><?php echo $row["ark_id"]; ?></td>
<td><?php echo $row["name"]; ?></td>
<td><a href="read.php?id=<?php echo $row['id']; ?>"><?php echo $row["overskrift"]; ?></td>
<td><?php echo $row["prioritet"]; ?></td>
<td bgcolor="<?php echo $priority_color; ?>"><?php echo $row["status"]; ?></td>
</tr>
<?php
}
?>
</table>
Related
I want to output statement you are approve if the row status = 1, the data can be output now i just want the statement saying approve.
here's my code
<div class="row">
<div class="col-md-12">
<table class="table table-striped">
<tr>
<th>Nominee Name</th>
<th>Year</th>
<th>Department</th>
<th>StudentID</th>
<th>Position</th>
<th>View File</th>
<th>Nominee Photo</th>
<th>Nominated by</th>
<th>status</th>
</tr>
<?php
foreach ($nominees as $noms) {
?>
<tr>
<td><?php echo $noms['name']; ?></td>
<td><?php echo $noms['year']; ?></td>
<td><?php echo $noms['department']; ?></td>
<td><?php echo $noms['studentid']; ?></td>
<td><?php echo $noms['position']; ?></td>
<td></td>
<td><img src="<?php echo base_url(); ?>uploads/<?php echo $noms['photo']; ?>" style='width:50px;height:50px;'></td>
<td><?php echo $noms['nomname']; ?></td>
<?php if ($noms['approve'] == 1) { ?>
<td>Approve</td>
<?php } else { ?>
<td>pending</td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div>
</div>
If the $nominees array returns the stays, then you can do like this
<?php if ( $nom['status'] == 1) { ?>
<td>Approve</td>
<?php }else{ ?>
<td>pending</td>
<?php }?>
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>
I have this code to get all the data from my products table. It's working great like this:
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row['id'];
echo $row['country'];
echo $row['price'];
echo $row['games'];
echo $row['plus'];
echo $row['buylink'];
echo "<br/>";
}
But I want these results to be shown in a table inside the body. I tried something but it's not working.
This is how the table looks :
<table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Country</th>
<th>Price</th>
<th>Games</th>
<th>Plus</th>
<th>Buy Link</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['country']; ?></td>
<td><?php echo $row['price']; ?></td>
<td><?php echo $row['games']; ?></td>
<td><?php echo $row['plus']; ?></td>
<td><?php echo $row['buylink']; ?></td>
</tr>
</tbody>
<?php
if ($result->num_rows > 0) {
?>
<table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Country</th>
<th>Price</th>
<th>Games</th>
<th>Plus</th>
<th>Buy Link</th>
</tr>
</thead>
<tbody>
<?php while($row = $result->fetch_assoc()){ ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['country']; ?></td>
<td><?php echo $row['price']; ?></td>
<td><?php echo $row['games']; ?></td>
<td><?php echo $row['plus']; ?></td>
<td><?php echo $row['buylink']; ?></td>
</tr>
<?php }?>
</tbody>
</table>
<?php
}else {
// if there is no result... Code something here.
}
?>
Youre getting close. You need to have the loop spit out the rows into the html.
<table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Country</th>
<th>Price</th>
<th>Games</th>
<th>Plus</th>
<th>Buy Link</th>
</tr>
</thead>
<tbody>
<?php
while($row = $result->fetch_row()) {
echo "<tr>";
foreach ($row as $item) {
echo "<td>$item</td>";
}
echo"</tr>";
}
?>
</tbody>
also instead of using a associative array and indexing into it (ie. $row['country']), You can use a normal array and a foreach loop to cut down on the code.
LE:
Each html table row is created based on each database's table row. So, you just need to loop through the result set (that while), and for each iteration of the loop, you need to create a new html table row:
<table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Country</th>
<th>Price</th>
<th>Games</th>
<th>Plus</th>
<th>Buy Link</th>
</tr>
</thead>
<tbody>
<?php while($row = $result->fetch_assoc()){ ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['country']; ?></td>
<td><?php echo $row['price']; ?></td>
<td><?php echo $row['games']; ?></td>
<td><?php echo $row['plus']; ?></td>
<td><?php echo $row['buylink']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
Here is my code. I am newer in programming. If I made any mistake please help me to solve it.
Thanks.
<table class="table table-striped" style="width:1300px; font-size:30px;" border="1px solid black">
<tr>
<th>Reference No</th>
<th>Category</th>
<th>Total Price</th>
</tr>
<?php
include("../db/db.php");
$sql_cost_details="select b.* from lc_details a, cost_details b where b.reference_no=a.reference_no AND a.lc_details_no='$lc_no' order by reference_no ASC";
$run_sql=mysqli_query($con, $sql_cost_details);
$i=0;
$total=0;
while($row_cost_details=mysqli_fetch_array($run_sql)){
$reference_no=$row_cost_details['reference_no'];
$category=$row_cost_details['category'];
$total_price=$row_cost_details['value'];
$i++;
?>
<tr align="center">
<td><?php echo $reference_no; ?></td>
<td><?php echo $category; ?></td>
<td><?php echo $total_price; ?></td>
</tr>
<?php } ?>
</table>
It shows this type of result
Expected result is this:
Use the below which solve your problem:
<table class="table table-striped" style="width:1300px; font-size:30px;" border="1px solid black">
<tr>
<th>Reference No</th>
<th>Category</th>
<th>Total Price</th>
</tr>
<?php
include("../db/db.php");
$sql_cost_details="select b.* from lc_details a, cost_details b where b.reference_no=a.reference_no AND a.lc_details_no='$lc_no' order by reference_no ASC";
$run_sql=mysqli_query($con, $sql_cost_details);
$i=0;
$total=0;
$prev = '';
while($row_cost_details=mysqli_fetch_array($run_sql)){
$reference_no=$row_cost_details['reference_no'];
$category=$row_cost_details['category'];
$total_price=$row_cost_details['value'];
$i++;
?>
<tr align="center">
<td><?php if ($prev != $reference_no){ echo $reference_no; } ?></td>
<td><?php echo $category; ?></td>
<td><?php echo $total_price; ?></td>
</tr>
<?php
$prev = $row_cost_details['reference_no'];
} ?>
</table>
I have the code to do the search. But the search results are not in the same table. All search results appear in a different table. How do I make them appear in one table?
Screenshot :
And here's my code :
> search.php
<?php
$query = $_GET['query'];
$min_length = 1;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM barang WHERE (`tanggal` LIKE '%".$query."%')") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_assoc($raw_results)){
?>
<table width="107%" class="view">
<thead>
<tr>
<th width="180">Tanggal</th>
<th width="150">Barang Masuk</th>
<th width="90">Bijih Keluar</th>
<th width="120">Kantong Hitam Keluar</th>
<th width="120">Kantong Putih Keluar</th>
<th width="90">Stok Bijih</th>
<th width="90">Stok Kantong Hitam</th>
<th width="90">Stok Kantong Putih</th>
<th width="130">Catatan</th>
</tr>
</thead>
<td><?php echo $results['tanggal']; ?></td>
<td><?php echo $results['barang_in']; ?></td>
<td><?php echo $results['bijih_out']; ?></td>
<td><?php echo $results['htm_out']; ?></td>
<td><?php echo $results['pth_out']; ?></td>
<td><?php echo $results['bijih']; ?></td>
<td><?php echo $results['kantong_htm']; ?></td>
<td><?php echo $results['kantong_pth']; ?></td>
<td><?php echo $results['note']; ?></td>
<?php
}
}
else{ // if there is no matching rows do following
echo "Hasil tidak bisa ditemukan atau tidak ada di dalam database.";
}
}
else{
echo "Minimum length is ".$min_length;
}
?>
So how to make the search results appear just in one table? Am I wrong to put the table code? Or something else? And one more question, How to add numbers for each result? Thank you in advance for your time and the help.
Move <table> tag outside your while loop and also add a <TR> tag inside the while loop and dont forget to close tag.
For Serial Number you have to introduce another variable as a counter. In the code given below i added $i. Change it if you had already used $i in your code.
I think after changing your code will look like
?>
<table width="107%" class="view">
<thead>
<tr>
<th>SN</th>//new Line
<th width="180">Tanggal</th>
<th width="150">Barang Masuk</th>
<th width="90">Bijih Keluar</th>
<th width="120">Kantong Hitam Keluar</th>
<th width="120">Kantong Putih Keluar</th>
<th width="90">Stok Bijih</th>
<th width="90">Stok Kantong Hitam</th>
<th width="90">Stok Kantong Putih</th>
<th width="130">Catatan</th>
</tr>
</thead>
<?php
$i=1;//new line
while($results = mysql_fetch_assoc($raw_results)){
?>
<tr>
<td><?php echo $i; ?> </td>//new line
<td><?php echo $results['tanggal']; ?></td>
<td><?php echo $results['barang_in']; ?></td>
<td><?php echo $results['bijih_out']; ?></td>
<td><?php echo $results['htm_out']; ?></td>
<td><?php echo $results['pth_out']; ?></td>
<td><?php echo $results['bijih']; ?></td>
<td><?php echo $results['kantong_htm']; ?></td>
<td><?php echo $results['kantong_pth']; ?></td>
<td><?php echo $results['note']; ?></td>
</tr>
<?php
$i++;//new line
}
?>
</table>
<?php
}
else{ // if there is no matching rows do following
echo "Hasil tidak bisa ditemukan atau tidak ada di dalam database.";
}
Move the <table> tag outside of your while loop.
Should be like this..
echo "<table width="107%" class=/"view/">";
while($results = mysql_fetch_assoc($raw_results)){
?>
<!-- Comment this
<table width="107%" class="view">
-->
<thead>
use this
<?php
$query = $_GET['query'];
$min_length = 1;
if(strlen($query) >= $min_length)
{
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM barang WHERE (`tanggal` LIKE '%".$query."%')") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0)
{
?>
<table width="107%" class="view">
<thead>
<tr>
<th width="180">Tanggal</th>
<th width="150">Barang Masuk</th>
<th width="90">Bijih Keluar</th>
<th width="120">Kantong Hitam Keluar</th>
<th width="120">Kantong Putih Keluar</th>
<th width="90">Stok Bijih</th>
<th width="90">Stok Kantong Hitam</th>
<th width="90">Stok Kantong Putih</th>
<th width="130">Catatan</th>
</tr>
</thead>
<?php
while($results = mysql_fetch_assoc($raw_results))
{
<tr>
<td><?php echo $results['tanggal']; ?></td>
<td><?php echo $results['barang_in']; ?></td>
<td><?php echo $results['bijih_out']; ?></td>
<td><?php echo $results['htm_out']; ?></td>
<td><?php echo $results['pth_out']; ?></td>
<td><?php echo $results['bijih']; ?></td>
<td><?php echo $results['kantong_htm']; ?></td>
<td><?php echo $results['kantong_pth']; ?></td>
<td><?php echo $results['note']; ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
else
{ // if there is no matching rows do following
echo "Hasil tidak bisa ditemukan atau tidak ada di dalam database.";
}
}
else
{
echo "Minimum length is ".$min_length;
}
?>