I have extracted hundreds of data from MYSQL database then populated them to a table. Each table has a column name "Preview" which will generate preview button. When we click on that preview button it has to pass Application ID of that row to genpdf.php but I could pass the Application ID of that specific row.
<form id="genpdf" action="genpdf.php" method="POST">
<h3 style="padding:10px;">List of Application Submitted</h3>
<table width="100%" style="padding: 10px;">
<tr>
<td><strong>S. No.</strong></td>
<td><strong>Application ID</strong></td>
<td><strong>Name</strong></td>
<td><strong>Date of Birth</strong></td>
<td><strong>Telephone</strong></td>
<td><strong>Email</strong></td>
<td><strong>Preview</strong></td>
</tr>
<?php
$i = 1;
while($row = mysql_fetch_array($record))
{
echo '<tr><td>' . $i . '</td>';
echo '<td>' . $row['applicationid'] . '</td>';
echo '<td>' . $row['title'] . ' ' . $row['firstname'] . ' ' . $row['middlename'] . ' ' . $row['familyname'] . '</td>';
echo '<td>' . $row['dobmonth'] . '/' . $row['dobday'] . '/' . $row['dobyear'] . '</td>';
echo '<td>' . $row['telephonet4'] . '</td>';
echo '<td>' . $row['emailt4'] . '</td>';
echo '<td><input type="submit" value "Preview" /></td>';
$i += 1;
}
?>
</table>
</form>
You have to replace the form submit button with a regular link that calls the genpdf.php page and adds the applicationId as a HTTP GET parameter.
Preview
Related
Hi I am having a problem displaying the 24 H volume name in coinmarketcap api it roduces an error when i call it but other values are working perfectly it may bebecause the 24h volume starts with a number. I want to know how will i get it. Thank you. Here is my current code
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<table>
<tbody>
<tr>
<th>Name</th>
<th>Symbol</th>
<th>Rank</th>
</tr>
<?php
ini_set('max_execution_time', 300);
// $tick = file_get_contents('https://api.coinmarketcap.com/v1/ticker/bitcoin/');
$url ='https://api.coinmarketcap.com/v1/ticker/?start=0&limit=1000';// path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$characters = json_decode($data); // decode the JSON feed
// echo $characters[0]->name;
foreach ($characters as $character) {
echo '<tr>';
echo '<td>' . $character->name . '</td>';
echo '<td>' . $character->symbol . '</td>';
echo '<td>' . $character->rank . '</td>';
echo '<td>' . $character->price_usd . '</td>';
echo '<td>' . $character->price_btc . '</td>';
echo '<td>' . $character->total_24h_volume_usd . '</td>';
echo '<td>' . $character->market_cap_usd . '</td>';
echo '<td>' . $character->available_supply . '</td>';
echo '<td>' . $character->total_supply . '</td>';
echo '<td>' . $character->max_supply . '</td>';
echo '<td>' . $character->percent_change_1h . '</td>';
echo '<td>' . $character->percent_change_24h . '</td>';
echo '<td>' . $character->percent_change_7d . '</td>';
echo '<td>' . $character->last_updated . '</td>';
echo '</tr>';
}
?>
</tbody>sdsdf
</table>
</body>
</html>
In order to access fields named in that fashoin you need to wrap them with {''}. So you need to write $character->{'24h_volume_usd'}.
I have table called reservations. It displays reservations made by users. I want highlight records in current date using end date.
Php code
$result2 = mysql_query("SELECT * FROM reservations WHERE hotel_id = '1' ORDER BY end");
while ($row = mysql_fetch_array($result2)) {
echo '<tr>';
echo '<td class="contacts">' . $row['fname'] . ' ' . $row['lname'] . '</td>';
echo '<td class="contacts">' . $row['start'] . '</td>';
echo '<td class="contacts">' . $row['end'] . '</td>';
echo '<td class="contacts">' . $row['qty'] . '</td>';
echo '</td>';
echo '<td class="contacts">' . $row['room_type'] . '</td>';
echo '<td class="contacts">' . '<a href=out.php?id=' . $row["res_id"] . '>' . 'Check Out' . '</a>' . '</td>';
echo '</tr>';
}
I'd do that at frontend side, but if you want to compute than in PHP, you will need to compare the date from $row and current date and add a class or a style tag to the .
Like so:
$rowHasCurrentDate = $row['date'] == date('Y-m-d');
echo '<tr' + ($rowHasCurrentDate ? ' class="highlight-row"' : "") + '>';
instead of
echo '<tr>';
You can replace the 'class="highlight-row"' with 'style="background-color:red"' if you want to do it without touching frontend side at all.
The example is kinda spaghetti-code, but you can move this logic somewhere else after you get it working.
I am assuming that your start date is current date. This is css thing, i have given you solution to you.
<html>
<head>
<style>
.currdate
{
background-color:red; //change this color to whatever you wish to change to
}
</style>
</head>
<body>
<?php
$result2 = mysql_query("SELECT * FROM reservations WHERE hotel_id = '1' ORDER BY end");
while ($row = mysql_fetch_array($result2)) {
echo '<tr>';
echo '<td class="contacts">' . $row['fname'] . ' ' . $row['lname'] . '</td>';
echo '<td class="contacts currdate">' . $row['start'] . '</td>';
echo '<td class="contacts">' . $row['end'] . '</td>';
echo '<td class="contacts">' . $row['qty'] . '</td>';
echo '</td>';
echo '<td class="contacts">' . $row['room_type'] . '</td>';
echo '<td class="contacts">' . '<a href=out.php?id=' . $row["res_id"] . '>' . 'Check Out' . '</a>' . '</td>';
echo '</tr>';
}
?>
<body>
</html>
So i've been trying to get one record and edit it by pressing the button that is created in that table, but honestly, i have no idea how to do that. Dx Can anyone help me with this? (Yes, i want the button created for each record. You know, so at the end of every row in the table, every record will have it's own button.)
while($rArt = mysqli_fetch_array($sql)){
echo '<tr><td>' . $rArt['ArtID'] . '</td>';
echo '<td>' . $rArt['FiliaalID'] . '</td>';
echo '<td>' . $rArt['Productnaam'] . '</td>';
echo '<td>' . $rArt['Inkoopprijs'] . '</td>';
echo '<td>' . $rArt['Voorraad'] . '</td>';
echo '<td>' . $rArt['Min_voorraad'] . '</td>';
$voo = $rArt['Voorraad'];
$minvoo = $rArt['Min_voorraad'];
$nodig = $minvoo * 2 - $voo;
$chosen = $rArt['ArtID'];
echo '<td>' . $nodig . '</td>';
echo '<td><input type="submit" name="bestel" value="Bestel"></td></tr>';
if(isset($_GET['bestel'])){
$query = mysqli_query($mysql, "
UPDATE artikel a, voorraad v
SET v.voorraad = v.voorraad + '$nodig'
WHERE a.artid = v.artid
AND v.voorraad = '$chosen'");
}
}
I wouldn't use submit in this case, but just a suggestion:
Why don't you try it this way:
<table>
<tr>
<td>Artikel ID</td>
<td> **<a href="bestelpagina/edit/id/1">** </td>
</tr>
</table>
So you can create an action called Edit in which you can do the changes.
Read the comment in the solution as they are important.
while($rArt = mysqli_fetch_array($sql)){
// echo '<tr><td>' . $rArt['ArtID'] . '</td>';
//The above line i removed and added the line below
echo '<tr><td>' .'<a href=\'admin.php?ArtID='.$rArt['ArtID'].'\'>'.$rArt['ArtID'] .'</td>';
echo '<td>' . $rArt['FiliaalID'] . '</td>';
echo '<td>' . $rArt['Productnaam'] . '</td>';
echo '<td>' . $rArt['Inkoopprijs'] . '</td>';
echo '<td>' . $rArt['Voorraad'] . '</td>';
echo '<td>' . $rArt['Min_voorraad'] . '</td>';
$voo = $rArt['Voorraad'];
$minvoo = $rArt['Min_voorraad'];
$nodig = $minvoo * 2 - $voo;
$chosen = $rArt['ArtID'];
echo '<td>' . $nodig . '</td>';
//echo '<td><input type="submit" name="bestel" value="Bestel"></td></tr>';
//removed this as you dont need input button here.
}///Your while loop should close here not in the ent
if(isset($_GET['bestel'])){
$query = mysqli_query($mysql, "
UPDATE artikel a, voorraad v
SET v.voorraad = v.voorraad + '$nodig'
WHERE a.artid = v.artid
AND v.voorraad = '$chosen'");
}
//} I remove this tag as your while loop should close before isset function
I have a PHP Script which lists all Applications from a Databse in a HTML Table. In an own row I want two buttons. Accept and decline
Accept should set the status to "accepted" for the id i klicked on accept.
The Same for decline.
This should update the status in the mysql database.
My Script at the moment:
echo '<table border="1">';
echo '<tr>
<th>ID</th>
<th>Name</th>
<th>Alter</th>
<th>E-Mail</th>
<th>KD</th>
<th>Steam</th>
<th>Spiele</th>
<th>Status</th>
<th>Accept</th>
<th>Decline</th>
</tr>';
while($row = mysql_fetch_object($ergebnis))
{
echo '<tr>';
echo '<td>' . $row->id . '</td>';
echo '<td>' . $row->name . '</td>';
echo '<td>' . $row->age . '</td>';
echo '<td>' . $row->mail . '</td>';
echo '<td>' . $row->kd . '</td>';
echo '<td>' . $row->steam . '</td>';
echo '<td>' . $row->spiele . '</td>';
echo '<td>' . $row->status . '</td>';
echo '</tr>';
}
echo '</table>';
I want my script to be dynamic, so I don't have to refresh the page after every change. Is it possible to do this with jQuery or Ajax? If yes, how do I do it?
change <tr> to <tr class="clickable" data-id="' . $row->id . '">
attach an event handler to tr.clickable
$('tr.clickable').on('click', function(element) {
$.get('changeStatus.php?' + $(element).data('id'));
});
improve the code above
I am looking for simple, the best practical way of placing summed value above HTML table.
Normally loops can generate sums after the loop is finished that is below the table of all results. It may be very difficult when the table is very long and we need to scroll down every time to see the sum of sales. Do I need to run two loops or is there any trick to do that? Task seems very simple. In below code I am summing Quantities from all orders and Total Sales values:
$lp=1; $total=0; $total_qt=0;
while ($record = mysql_fetch_array($result)){
$total += $record['Total'];
$total_qt += $record['Qt'];
echo '<tr style="background-color:'. ((next($colour) == true) ? current($colour) : reset($colour)).'">
<td> ' . $lp++ . '</td>
<td class="bolder"> ' . $record['Name'] . '</td>
<td> ' . $record['Product'] . '</td>';
if ($invoice=="on") echo '<td style="font-size:11px">' . $record['Invoice'] . '</td>';
echo '<td> ' . $record['despatched'] . '</td>
<td> ' . $record['Qt'] . '</td>
<td> ' . $record['Price'] . '</td>
<td class="align_right"> ' . $record['Total'] . '</td>';
echo '</tr>';
}
echo '</table><div class="stat_total">Qt: '.$total_qt.' Total: £'.$total.'</div> </div>';
You could use a variable to store your output while you are in the loop, rather than echo it, and when you finished the loop then echo the stored results with both totals before and after them. Like this:
$lp=1; $total=0; $total_qt=0;
$output = ''; //here you temporarily save your output
while ($record = mysql_fetch_array($result)){
$total += $record['Total'];
$total_qt += $record['Qt'];
$output .= '<tr style="background-color:'. ((next($colour) == true) ? current($colour) : reset($colour)).'">
<td> ' . $lp++ . '</td>
<td class="bolder"> ' . $record['Name'] . '</td>
<td> ' . $record['Product'] . '</td>';
if ($invoice=="on") $output .= '<td style="font-size:11px">' . $record['Invoice'] . '</td>';
$output .= '<td> ' . $record['despatched'] . '</td>
<td> ' . $record['Qt'] . '</td>
<td> ' . $record['Price'] . '</td>
<td class="align_right"> ' . $record['Total'] . '</td>';
$output .= '</tr>';
}
//Now you can put a div with the Total both at the start and end of the table
echo '<div class="stat_total">Qt: '.$total_qt.' Total: £'.$total.'</div>';
echo $output . '</table>';
echo '<div class="stat_total">Qt: '.$total_qt.' Total: £'.$total.'</div> </div>';
By using the SUM() SQL function you'll be able to access the sums without needing to run PHP:
SQL
SELECT SUM(Total) FROM Orders