If row status is 1 show the approved status in the table - php

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 }?>

Related

using variable from array outside of foreach loop

Im trying to display variables from an array. I am using a foreach loop, however I need to display $order['campaign_name'] before the loop so that it only shows up once. How can I do this? If I change it to $orders['campaign_name'] I get an undefined index error.
<div class="table-responsive">
<table class="table" id="component-table">
<?php if ($orders) { ?>
<?php foreach ($orders as $order) { ?>
<thead>
<tr>
<td colspan=100%><h3><?php echo $order['campaign_name']; ?></h3></td>
</tr>
</thead>
<tbody>
<tr class="campaign-list" id="campaign-list">
<td><?php echo $order['component_name']; ?></td>
<td><?php echo $order['component_owner']; ?></td>
<td><?php echo $order['component_date']; ?></td>
<td><?php echo $order['campaign_code']; ?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="text-center" colspan="8"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
You are trying to get those value which is not exist before loop. You are directly calling VALUE.
Easily just put index value behind tha array
echo $orders[0]['campaign_name']
It will print your value.
You would need need to know which index of the array you want to show, but if you want to show the first index of the array you can use $orders[0]['component_name'].
<div class="table-responsive">
<table class="table" id="component-table">
<?php if ($orders) { ?>
<thead>
<tr>
<td colspan=100%><h3><?php echo $orders[0]['campaign_name']; ?></h3></td>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order) { ?>
<tr class="campaign-list" id="campaign-list">
<td><?php echo $order['component_name']; ?></td>
<td><?php echo $order['component_owner']; ?></td>
<td><?php echo $order['component_date']; ?></td>
<td><?php echo $order['campaign_code']; ?></td>
</tr>
<?php } ?>
</tbody>
<?php } else { ?>
<tbody>
<tr>
<td class="text-center" colspan="8"><?php echo $text_no_results; ?></td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
Your campaign name continues to echo out because you have it inside of your foreach loop; if you want it to display only once, make sure to place it above your foreach loop.
Here's a less cluttered example to learn from:
<table>
...
<?php
if ($orders):
echo $order['campaign_name'];
foreach($orders as $order):
echo '...'; // other components
endforeach;
else:
echo $text_no_results;
endif;
?>
...
</table>

adding inline CSS in datatable row on condition not working

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.

change bootstrap label depend on words from mysql row

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>

How to avoid displaying duplicated values or overwrite duplicated values in php foreach loop in table?

I'm currently working on codeigniter. I want to display a value that is not been duplicated or overwrite a duplicated value from mysql database into the datatable of php foreach loop.
Here is the table code:
<table class="table table-striped responsive-utilities jambo_table" id="myTable">
<thead>
<tr class="headings">
<th>Employee No.</th>
<th>Username</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
foreach($EMPLOYEES as $employee){?>
<tr>
<td><?php echo $employee->empnum; ?></td>
<td><?php echo $employee->username; ?></td>
<td><?php echo $employee->name; ?> <?php echo $employee->lastname; ?></td>
<td><?php
if ($employee->hasClockOut==1){
echo '<a class="label label-danger">Inactive</a>';
}else {
echo '<a class="label label-success">Active</a>';
}
?></td>
</tr>
<?php } ?>
</tbody>
</table>
Why not just use -
$EMPLOYEES = array_unique($EMPLOYEES);
Try this
<table class="table table-striped responsive-utilities jambo_table" id="myTable">
<thead>
<tr class="headings">
<th>Employee No.</th>
<th>Username</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php $emp='';
foreach($EMPLOYEES as $employee){
if($emp!=$employee->username){ # if username contain duplicate values
?>
<tr>
<td><?php echo $employee->empnum; ?></td>
<td><?php echo $employee->username; ?></td>
<td><?php echo $employee->name; ?> <?php echo $employee->lastname; ?></td>
<td><?php
if ($employee->hasClockOut==1){
echo '<a class="label label-danger">Inactive</a>';
}else {
echo '<a class="label label-success">Active</a>';
}
?></td>
</tr>
<?php }$emp=$employee->username;} ?>
</tbody>
</table>

Parse error: syntax error, unexpected end of file in [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I am getting the "Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\football\index.php on line 123" error on my webserver (using XAMPP). My code is the following:
<?php
include 'FootballData.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>phplib football-data.org</title>
<link href="./css/bootstrap.min.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Showcasing some library functions...</h1>
</div>
<?php
// Create instance of API class
$api = new FootballData();
// fetch and dump summary data for premier league' season 2015/16
$soccerseason = $api->getSoccerseasonById(398);
echo "<p><hr><p>"; ?>
<h3>Fixtures for the 1st matchday of <? echo $soccerseason->payload->caption; ?></h3>
<table class="table table-striped">
<tr>
<th>HomeTeam</th>
<th></th>
<th>AwayTeam</th>
<th colspan="3">Result</th>
</tr>
<?php foreach ($soccerseason->getFixturesByMatchday(1) as $fixture) { ?>
<tr>
<td><? echo $fixture->homeTeamName; ?></td>
<td>-</td>
<td><? echo $fixture->awayTeamName; ?></td>
<td><? echo $fixture->result->goalsHomeTeam; ?></td>
<td>:</td>
<td><? echo $fixture->result->goalsAwayTeam; ?></td>
</tr>
<? } ?>
</table>
<?
echo "<p><hr><p>";
// fetch all available upcoming fixtures for the next week and display
$now = new DateTime();
$end = new DateTime(); $end->add(new DateInterval('P7D'));
$response = $api->getFixturesForDateRange($now->format('Y-m-d'), $end->format('Y-m-d'));
?>
<h3>Upcoming fixtures next 7 days</h3>
<table class="table table-striped">
<tr>
<th>HomeTeam</th>
<th></th>
<th>AwayTeam</th>
<th colspan="3">Result</th>
</tr>
<?php foreach ($response->fixtures as $fixture) { ?>
<tr>
<td><? echo $fixture->homeTeamName; ?></td>
<td>-</td>
<td><? echo $fixture->awayTeamName; ?></td>
<td><? echo $fixture->result->goalsHomeTeam; ?></td>
<td>:</td>
<td><? echo $fixture->result->goalsAwayTeam; ?></td>
</tr>
<? } ?>
</table>
<?
echo "<p><hr><p>";
// search for desired team
$searchQuery = $api->searchTeam(urlencode("Real Madrid"));
// var_dump searchQuery and inspect for results
$response = $api->getTeamById($searchQuery->teams[0]->id);
$fixtures = $response->getFixtures('home')->fixtures;
?>
<h3>All home matches of Real Madrid:</h3>
<table class="table table-striped">
<tr>
<th>HomeTeam</th>
<th></th>
<th>AwayTeam</th>
<th colspan="3">Result</th>
</tr>
<?php foreach ($fixtures as $fixture) { ?>
<tr>
<td><? echo $fixture->homeTeamName; ?></td>
<td>-</td>
<td><? echo $fixture->awayTeamName; ?></td>
<td><? echo $fixture->result->goalsHomeTeam; ?></td>
<td>:</td>
<td><? echo $fixture->result->goalsAwayTeam; ?></td>
</tr>
<? } ?>
</table>
<?
echo "<p><hr><p>";
// fetch players for a specific team
$team = $api->getTeamById($searchQuery->teams[0]->id);
?>
<h3>Players of <? echo $team->_payload->name; ?></h3>
<table class="table table-striped">
<tr>
<th>Name</th>
<th>Position</th>
<th>Jersey Number</th>
<th>Date of birth</th>
</tr>
<? foreach ($team->getPlayers() as $player) { ?>
<tr>
<td><? echo $player->name; ?></td>
<td><? echo $player->position; ?></td>
<td><? echo $player->jerseyNumber; ?></td>
<td><? echo $player->dateOfBirth; ?></td>
</tr>
<? } ?>
</table>
</div>
</body>
</html>
How can I solve this?
See alternative PHP syntax. You cannot use it like this <?php foreach ($fixtures as $fixture) { ?> <?php } ?> rather <?php foreach ($fixtures as $fixture): ?> <?php endforeach; ?>
You should avoid this {?> and this: <?php}
You shouldn't put brackets directly close to the open/close php tag, but it separate with a space: { ?> <?php { also avoid <? and use <?php

Categories