Open a link in a child window - php

when either Project or No is clicked, they open in a new window with other details under that clicked row, but i want them to open in a child window instead. is there a way to do it?
this is my code
<table id="keywords" class="container">
<thead>
<tr>
<td><span>Project</span></td>
<td><span>No</span></td>
<td><span>Sub ID</span></td>
<td><span>Name</span></td>
<td><span>Requested Amount</span></td>
<td><span>Paid Amount</span></td>
<td><span>Amount To be Paid</span></td>
<td><span>Description</span></td>
<td><span>State</span></td>
</tr>
</thead>
<?php
/* showing table */
$sql = "SELECT * FROM memo ORDER BY No DESC, SubID ASC"
or die("Failed to query database" .mysqli_error());
$result = $link->query($sql);
while ($row = $result->fetch_assoc()) {
print "<tr>";
print "<td >" . $row['Project'] . "</td>";
print "<td >" . $row['No'] . "</td>";
print "<td >" . $row['SubID'] . "</td>";
print "<td >" . $row['Name'] . "</td>";
print "<th >" . $row['RequestAmount'] . "</th>";
print "<th >" . $row['PaidAmount'] . "</th>";
print "<th >" . $row['AmountToPay'] . "</th>";
print "<td >" . $row['Description'] . "</td>";
print "<td >" . $row['State'] . "</td>";
print "</tr>";
}
// print "</table>";
?>
</table>

Related

Get the sum of selected columns

In this sheet, I want to search for a time period and the location ad get the search result in another page.
this is the page i get after I search. (search.php)
<table class="table" id="keywords" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th><span>ID</span></th>
<th><span>Name</span></th>
<th><span>Location</span></th>
<th><span>Date</span></th>
<th><span>Catagory</span></th>
<th><span>Labour-Supplier</span></th>
<th><span>In-time</span></th>
<th><span>Out-time</span></th>
<th><span>Day</span></th>
<th><span>Day Rate</span></th>
<th><span>Salary</span></th>
<th><span>OT-hours</span></th>
<th><span>OT-rate</span></th>
<th><span>OT-amount</span></th>
<th><span>Allowance II</span></th>
<th><span>TotalSalary</span></th>
<th><span>Advance</span></th>
<th><span>Salary-to-hand</span></th>
</tr>
</thead>
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
$Location=$_POST['Location'];
$query = mysql_query("SELECT ID,Name,Location,Date,Category,LabourSupplier,Day,DayRate,Salary,OTHours,OTrate,OTAmount,Allowance2,TotalSalary,Advance,SalaryToHand FROM attendance WHERE Date BETWEEN '".$_POST["FDate"]."' AND '".$_POST["TDate"]."' AND Location LIKE '%" . $Location . "%' ORDER BY location DESC, Date DESC",$connection)
or die("Failed to query database" . mysql_error());
while ($row = mysql_fetch_array($query)) {
print "<tr>";
print "<td >" . $row['ID'] . "</td>";
print "<td >" . $row['Name'] . "</td>";
print "<td >" . $row['Location'] . "</td>";
print "<th >" . $row['Date'] . "</th>";
print "<td >" . $row['Category'] . "</td>";
print "<td >" . $row['LabourSupplier'] . "</td>";
print "<th >" . $row['InTime'] . "</th>";
print "<th >" . $row['OutTime'] . "</th>";
print "<th >" . $row['Day'] . "</th>";
print "<th >" . $row['DayRate'] . "</th>";
print "<th >" . $row['Salary'] . "</th>";
print "<th >" . $row['OTHours'] . "</th>";
print "<th >" . $row['OTrate'] . "</th>";
print "<th >" . $row['OTAmount'] . "</th>";
print "<th >" . $row['Allowance2'] . "</th>";
print "<th >" . $row['TotalSalary'] . "</th>";
print "<th >" . $row['Advance'] . "</th>";
print "<th>" . $row['SalaryToHand'] . "</th>";
print "</tr>";
}
}
}
print "</table>";
?>
I want to get the sum of the columns Day, Salary,OT hours, OT amount, Total Salary and Salary To Hand at the bottom of the table. Is there a possible way to do that or should i get the sums in another table.
PS i tried to get the sum in a new table but this didn't work.
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
$Location=$_POST['Location'];
$query = mysql_query("SELECT ID,Name,Location,sum(Day),sum(Salary),sum(OTHours),sum(OTAmount),sum(TotalSalary),sum(Advance),sum(SalaryToHand) FROM attendance WHERE Date BETWEEN '".$_POST["FDate"]."' AND '".$_POST["TDate"]."' AND Location LIKE '%" . $Location . "%' ORDER BY location DESC, Date DESC",$connection)
or die("Failed to query database" . mysql_error());
while ($row = mysql_fetch_array($query)) {
print "<tr>";
print "<td >" . $row['ID'] . "</td>";
print "<td >" . $row['Name'] . "</td>";
print "<td >" . $row['Location'] . "</td>";
print "<th >" . $row['Day'] . "</th>";
print "<th >" . $row['Salary'] . "</th>";
print "<th >" . $row['OTHours'] . "</th>";
print "<th >" . $row['OTAmount'] . "</th>";
print "<th >" . $row['TotalSalary'] . "</th>";
print "<th >" . $row['Advance'] . "</th>";
print "<th>" . $row['SalaryToHand'] . "</th>";
print "</tr>";
}
}
}
print "</table>";
?>
Try this SQL query :
// Get parameter
$fDate = $_POST["FDate"];
$tDate = $_POST["TDate"];
// Build SQL query
$sql = <<<SQL
SELECT '' AS ID,
'' AS Name,
'' AS Location,
SUM(Day) AS Day,
SUM(Salary) AS Salary,
SUM(OTHours) AS OTHours,
SUM(OTAmount) AS OTAmount,
SUM(TotalSalary) AS TotalSalary,
SUM(Advance) as Advance,
SUM(SalaryToHand) as SalaryToHand
FROM attendance
WHERE Date BETWEEN '{$fDate}' AND '{$tDate}'
AND Location LIKE '%{$Location}%'
ORDER BY location DESC, Date DESC
SQL;
// Excecute it
$query = mysql_query($sql ,$connection) or die("Failed to query database" . mysql_error());
// Handle result
while ($row = mysql_fetch_array($query)) {
...
}
Keep in mind that is not safe query (don't put $_POST param directly into SQL, use prepare statement).
# Strawberry is right, mysqli is a safer driver than mysql. Think of a migration when you have time.

foreach loop highlight cells from database

I'm wondering if my code could be easier with a foreach loop. my code thusfar:
the purpose is to read the values in the MYSQL table, and if the anwser is "NEE" display the background color in RED. my code works but it is very long..
$connection = mysql_connect('localhost', 'root', ''); //The Blank string is
the password
mysql_select_db('heijsDB');
$query = "SELECT * FROM hygieneaanvoer"; //You don't need a ; like you do in
SQL
$result = mysql_query($query);
//List the Columns for the Report
if(! $result ) {
die('Could display data: ' . mysql_error());
}
echo "<table border='1' class='w3-panel'>
<fieldset>hygiëne/GMP aduit Aanvoer</fieldset>
<tr>
<th>Datum</th>
<th>Controleur</th>
<th>controleur</th>
<th>Revisie</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
<th>8</th>
<th>9</th>
<th>10</th>
<th>11</th>
<th>12</th>
<th>13</th>
<th>14</th>
<th>15</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['datum'] . "</td>";
echo "<td>" . $row['controleur'] . "</td>";
echo "<td>" . $row['codering'] . "</td>";
echo "<td>" . $row['revisie'] . "</td>";
if($row['q1']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q1']."</td>";
else echo "<td>".$row['q1']."</td>";
if($row['q2']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q2']."</td>";
else echo "<td>".$row['q2']."</td>";
if($row['q3']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q3']."</td>";
else echo "<td>".$row['q3']."</td>";
if($row['q4']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q4']."</td>";
else echo "<td>".$row['q4']."</td>";
if($row['q5']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q5']."</td>";
else echo "<td>".$row['q5']."</td>";
if($row['q6']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q6']."</td>";
else echo "<td>".$row['q6']."</td>";
if($row['q7']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q7']."</td>";
else echo "<td>".$row['q7']."</td>";
if($row['q8']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q8']."</td>";
else echo "<td>".$row['q8']."</td>";
if($row['q9']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q9']."</td>";
else echo "<td>".$row['q9']."</td>";
if($row['q10']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q10']."</td>";
else echo "<td>".$row['q10']."</td>";
if($row['q11']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q11']."</td>";
else echo "<td>".$row['q11']."</td>";
if($row['q12']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q12']."</td>";
else echo "<td>".$row['q12']."</td>";
if($row['q13']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q13']."</td>";
else echo "<td>".$row['q13']."</td>";
if($row['q14']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q14']."</td>";
else echo "<td>".$row['q14']."</td>";
if($row['q15']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q15']."</td>";
else echo "<td>".$row['q15']."</td>";
echo "</tr>";
}
echo "</table>";
?>
Here is solution
$result = mysql_query("SELECT * FROM hygieneaanvoer")or die('Could display data: ' . mysql_error());;
echo "<table border='1' class='w3-panel'>
<fieldset>hygiëne/GMP aduit Aanvoer</fieldset>
<tr>
<th>Datum</th>
<th>Controleur</th>
<th>controleur</th>
<th>Revisie</th>";
for ($i=1;$i<=15;$i++){
echo '<th>'.$i.'</th>';
}
echo "</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['datum'] . "</td>";
echo "<td>" . $row['controleur'] . "</td>";
echo "<td>" . $row['codering'] . "</td>";
echo "<td>" . $row['revisie'] . "</td>";
for ($j=1;$j<=15;$j++){
echo "<td ".(($row['q'.$j] == 'NEE') ? "style='background-color: #e21010;'" : "" ).">".$row['q'.$j]."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
What you could do, is just create a single variable that you'd use for setting the style of all rows:
while($row = mysql_fetch_array($result))
{
$style_string = "";
if($row['q1']=='NEE') {
$style_string = "style='background-color: #e21010;'";
}
echo "<tr>";
echo "<td>" . $row['datum'] . "</td>";
echo "<td>" . $row['controleur'] . "</td>";
echo "<td>" . $row['codering'] . "</td>";
echo "<td>" . $row['revisie'] . "</td>";
echo "<td " . $style_string . ">" . $row['q1'] . "</td>";
echo "<td " . $style_string . ">" . $row['q2'] . "</td>";
echo "<td " . $style_string . ">" . $row['q3'] . "</td>";
echo "<td " . $style_string . ">" . $row['q4'] . "</td>";
echo "<td " . $style_string . ">" . $row['q5'] . "</td>";
echo "<td " . $style_string . ">" . $row['q6'] . "</td>";
echo "<td " . $style_string . ">" . $row['q7'] . "</td>";
echo "<td " . $style_string . ">" . $row['q8'] . "</td>";
echo "<td " . $style_string . ">" . $row['q9'] . "</td>";
echo "<td " . $style_string . ">" . $row['q10'] . "</td>";
echo "<td " . $style_string . ">" . $row['q11'] . "</td>";
echo "<td " . $style_string . ">" . $row['q12'] . "</td>";
echo "<td " . $style_string . ">" . $row['q13'] . "</td>";
echo "<td " . $style_string . ">" . $row['q14'] . "</td>";
echo "<td " . $style_string . ">" . $row['q15']. "</td>";
echo "</tr>";
}
(Or just set the background color of the <tr>)
Best of luck!
You can simply add the class to the td like this
echo "<td class='". $row['q15'] . "'>".$row['q15']."</td>";
Add css like this
.NEE {background-color: #e21010;}

How to get total of given colum of mysql virtual table

<?php
{
echo "</br>";
echo "</br>";
echo "<table border='1'> <tr>";
while ($row1=mysql_fetch_array($result1)){
echo "<td><strong>" . $_POST['card_no']. "</strong></td>";
echo "<td><strong>" . $row1['lname']. "</strong></td>";
}
"</tr>";
echo "<tr><td><strong> Total Incentive: </strong></td><td><strong> Rs." $TotalIncentive " </strong> </td></tr>";
//i want to show Total Incentive Value above table "$TotalIncentive". pls see attached image for more clarification.
echo "<table border='1' width='auto'>
<tr>
<th>Tid</th>
<th>Depart</th>
<th>Sub Depart</th>
<th>EARN</th>
<th>Eff</th>
<th> Group Eff </th>
<th>Date</th>
<th>Incentive</th>
</tr>";
//$sql=Query not show here becz its very large Query
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td bgcolor='#FFFFF'>" . $row['t_id'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['dep_code'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['subdep_code']." ".$row['type_code'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['TER']. "</td>";
echo "<td bgcolor='#00FF33'>" . round(($row['TER']/570)*$pre). "%</td>";
echo "<td bgcolor='#FFFF00'>" . round($row['geff1']) . "%</td>";
echo "<td bgcolor='#FFFFF'>" . $row['tdate'] . "</td>";
if($row['geff1']>=105){
$inc=(300*($row['TER']/570)*$pre)/105;
}elseif($row['geff1']>=100){
$inc=(275*($row['TER']/570)*$pre)/100;
}elseif($row['geff1']>=95){
$inc=(240*($row['TER']/570)*$pre)/95;
}elseif($row['geff1']>=90){
$inc=(200*($row['TER']/570)*$pre)/90;
}elseif($row['geff1']>=85){
$inc=(160*($row['TER']/570)*$pre)/85;
}elseif($row['geff1']>=80){
$inc=(120*($row['TER']/570)*$pre)/80;
}elseif($row['geff1']>=75){
$inc=(90*($row['TER']/570)*$pre)/75;
}elseif($row['geff1']>=70){
$inc=(60*($row['TER']/570)*$pre)/70;
}elseif($row['geff1']>=65){
$inc=(30*($row['TER']/570)*$pre)/65;
}elseif($row['geff1']<65){
$inc=0;
}
echo "<td ><strong>Rs.".round($inc,2);"</strong></td>";
echo "</tr>";
//Total Incentive Should be SUM(round($inc,2))
}
echo "</table>";
mysql_close($con);
}
//I want to Show "Total Incentive" Value in the place that i mention in my Image
?>
update your while loop as below & echo $totalInc at the end of this while() loop
<?php
$totalInc = 0; //added this variable
while ($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td bgcolor='#FFFFF'>" . $row['t_id'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['dep_code'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['subdep_code']." ".$row['type_code'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['TER']. "</td>";
echo "<td bgcolor='#00FF33'>" . round(($row['TER']/570)*$pre). "%</td>";
echo "<td bgcolor='#FFFF00'>" . round($row['geff1']) . "%</td>";
echo "<td bgcolor='#FFFFF'>" . $row['tdate'] . "</td>";
if($row['geff1']>=105){
$inc=(300*($row['TER']/570)*$pre)/105;
}elseif($row['geff1']>=100){
$inc=(275*($row['TER']/570)*$pre)/100;
}elseif($row['geff1']>=95){
$inc=(240*($row['TER']/570)*$pre)/95;
}elseif($row['geff1']>=90){
$inc=(200*($row['TER']/570)*$pre)/90;
}elseif($row['geff1']>=85){
$inc=(160*($row['TER']/570)*$pre)/85;
}elseif($row['geff1']>=80){
$inc=(120*($row['TER']/570)*$pre)/80;
}elseif($row['geff1']>=75){
$inc=(90*($row['TER']/570)*$pre)/75;
}elseif($row['geff1']>=70){
$inc=(60*($row['TER']/570)*$pre)/70;
}elseif($row['geff1']>=65){
$inc=(30*($row['TER']/570)*$pre)/65;
}elseif($row['geff1']<65){
$inc=0;
}
$totalInc = $totalInc + $inc; //set value to this variable
echo "<td ><strong>Rs.".round($inc,2);"</strong></td>";
echo "</tr>";

Get table value html

I'm trying to update a mySQL table after a button click..The button click is not the problem but I wonder how I can get the klant_pk which is unique to update a certain record in mySQL. As you see I print out the mySql table at first. So is there anyone who know how I can get the according klant_pk after I click on a button in the table..
Thanks
$result = mysqli_query($con, "SELECT * FROM bestelling");
echo "Bestellingen";
echo "<table border='1' align='center'>
<tr>
<th>Bestelling_pk</th>
<th>Klant_pk</th>
<th>Product</th>
<th>Commentaar</th>
<th>Tijd</th>
<th> Voortgang </th>
<th> Status </th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['bestelling_pk'] . "</td>";
echo "<td>" . $row['klant_pk'] . "</td>";
echo "<td>" . $row['product'] . "</td>";
echo "<td>" . $row['opmerking'] . "</td>";
echo "<td>" . $row['tijd'] . "</td>";
echo "<td> <input type='button' value='In Wacht' onclick='return change(this);' />";
echo "<td>" . $row['status'] . "</td>";
echo "</tr>";
}
echo "</table>";
while ($row = mysqli_fetch_array($result)) {
...
echo "<td id='klank_pk_".$row['klant_pk']."'>" . $row['klant_pk'] . "</td>";
...
echo "<td> <input type='button' value='In Wacht' onclick='change(getElementById('klank_pk_".$row['klant_pk']."').value);' />";
...
}

mysql_fetch_array with dates separated

I am trying to loop through MySQL results and return same dates & agents in a separate . The table containing this data has the number of tickets each agent works on a specific day. Each group of dates should be separated by a blank row in the table. Below is the code I am working with. I believe I have to do a foreach, but not sure how to get it working.
Here is a screenshot to a final table layout I am looking to achieve.
if($res && mysql_num_rows($res))
{
while($row = mysql_fetch_array($res))
{
if ($row['total_updated'] > 0) {
print "<tr>";
print "<td align=center>" . $row['date_added'] . "</td>";
print "<td nowrap>" . $row['agent'] . "</td>";
print "<td nowrap>" . $row['agent_location'] . "</td>";
print "<td align=center>" . number_format($row['total_updated']) . "</td>";
print "<td align=center>" . number_format($row['total_notes']) . "</td>";
print "<td align=center>" . number_format($row['total_closed']) . "</td>";
print "<td align=center>" . number_format($row['ticket_app1_updated']) . "</td>";
print "<td align=center>" . number_format($row['ticket_app1_notes']) . "</td>";
print "<td align=center>" . number_format($row['ticket_app1_closed']) . "</td>";
print "<td align=center>" . number_format($row['ticket_app2_updated']) . "</td>";
print "<td align=center>" . number_format($row['ticket_app2_notes']) . "</td>";
print "<td align=center>" . number_format($row['ticket_app2_closed']) . "</td>";
print "<td align=center>" . number_format($row['ticket_app3_updated']) . "</td>";
print "<td align=center>" . number_format($row['ticket_app3_notes']) . "</td>";
print "<td align=center>" . number_format($row['ticket_app3_closed']) . "</td>";
print "</tr>";
}
}
}
print "</table>";
If you sort your results by date_added you don't need any foreach, just compare previous date with current one:
while($row = mysql_fetch_array($res))
{
if (!isset($lastdate))
$lastdate = $row['date_added'];
if ($lastdate != $row['date_added']) {
?><tr><td colspan="15">---blank line---</td></tr> <?php
}
//paste all of your prints here
$lastdate = $row['date_added'];
}

Categories