I've looked through some of the other answers on this, but they don't seem to solve my particular issue (or I am coding them wrong, which is also possible).
I know my SQL code works right, as I get all 19 rows of output, but when I output it to a PHP page, the page shorts me by 5 rows.
If I don't try to show the results in three columns by whatever (and just use one column) everything shows. When I try to do three by 'X', is when it starts cutting off results.
Here is my old, not working PHP code:
$fleet_query_results = #mysql_query($fleet_query, $connection) or die(mysql_error());
while($row = mysql_fetch_array($fleet_query_results)) {
$display_fleet .= "<tr>";
for($i = 1; $i < 4 && $row = mysql_fetch_array($fleet_query_results); $i++) {
$ship_info = $row['ship_info'];
$mem_info = $row['mem_info'];
$ship_link = $row['ship_link'];
$display_fleet .= "
<td valign=\"top\"><div id=\"fleet\"><div id=\"fheader\">$ship_info</div><br/><img align=\"center\" height=\"210\" width=\"350\" alt=\"$ship_name\" src=\"$ship_link\" /><br /><div id=\"fmem\">$mem_info</div></div></td>
";
}
$display_fleet .= "</tr>";
}
Any ideas? It's cutting off the first, fourth, ninth, thirteenth and seventeenth results.
Example page results:
<table border="1">
<tr><td>Header<br />Image<br />People</td><td>Header<br />Image<br />People</td><td>Header<br />Image<br />People</td></tr>
<tr><td>Header<br />Image<br />People</td><td>Header<br />Image<br />People</td><td>Header<br />Image<br />People</td></tr>
<tr><td>Header<br />Image<br />People</td><td>Header<br />Image<br />People</td><td>Header<br />Image<br />People</td></tr>
</table>
New code that works, but is UGLY:
$fleet_query_results = #mysql_query($fleet_query, $connection) or die(mysql_error());
while($row = mysql_fetch_array($fleet_query_results)) {
$display_fleet .= "<tr>";
$ship_info = $row['ship_info'];
$mem_info = $row['mem_info'];
$ship_link = $row['ship_link'];
$display_fleet .= "
<td valign=\"top\"><div id=\"fleet\"><div id=\"fheader\">$ship_info</div><br/><img align=\"center\" height=\"210\" width=\"350\" alt=\"$ship_name\" src=\"$ship_link\" /><br /><div id=\"fmem\">$mem_info</div></div></td>
";
for($i = 1; $i < 3 && $row = mysql_fetch_array($fleet_query_results); $i++) {
$ship_info = $row['ship_info'];
$mem_info = $row['mem_info'];
$ship_link = $row['ship_link'];
$display_fleet .= "
<td valign=\"top\"><div id=\"fleet\"><div id=\"fheader\">$ship_info</div><br/><img align=\"center\" height=\"210\" width=\"350\" alt=\"$ship_name\" src=\"$ship_link\" /><br /><div id=\"fmem\">$mem_info</div></div></td>
";
}
$display_fleet .= "</tr>";
}
Your while was eating some of the data rows.
$fleet_query_results = #mysql_query($fleet_query, $connection) or die(mysql_error());
$rows=1;
while($rows) {
$display_fleet .= "<tr>";
for($i = 1; $i < 4 && $row = mysql_fetch_array($fleet_query_results); $i++) {
$rows=$row;
if (!$row) break;
$ship_info = $row['ship_info'];
$mem_info = $row['mem_info'];
$ship_link = $row['ship_link'];
$display_fleet .= "
<td valign=\"top\"><div id=\"fleet\"><div id=\"fheader\">$ship_info</div><br/><img align=\"center\" height=\"210\" width=\"350\" alt=\"$ship_name\" src=\"$ship_link\" /><br /><div id=\"fmem\">$mem_info</div></div></td>
";
}
$display_fleet .= "</tr>";
}
or, as discussed below:
$i=0
while($row = mysql_fetch_array($fleet_query_results)) {
if( $i % 4 = 0 )
$display_fleet .= "<tr>";
$ship_info = $row['ship_info'];
$mem_info = $row['mem_info'];
$ship_link = $row['ship_link'];
$display_fleet .= "
<td valign=\"top\"><div id=\"fleet\"><div id=\"fheader\">$ship_info</div><br/><img align=\"center\" height=\"210\" width=\"350\" alt=\"$ship_name\" src=\"$ship_link\" /><br /><div id=\"fmem\">$mem_info</div></div></td>
";
if( ++$i % 4 = 0 )
$display_fleet .= "</tr>\n";
}
// clean add the missing cells to last row.
if( $i % 4 != 0 )
{
while($i++ %4)
$display_fleet .= "<td></td>";
$display_fleet .= "</tr>\n";
}
Related
i have a code that store data in database as an object with serialize(),
and show this on table in loop from database each category have 'payment' column that has the array with the payments data (example:[num,string,date]) And there could be several payment to each category,
but the issue is that now it show all payments category in the table one under the other
i try to do it nicer so that In the column that displays the the payments will be a
modal button that displays the payments of each category in the modal but it display the first value on the array to all categories
i try someting to give an id But that's impossible because it prints the information in a loop
that's my code:
function showTable($table, $data, &$totalSum = 0)
{
$totalEestimatedCost = 0;
$totalMyBudget = 0;
if (is_array($data)) {
$tableToShow = '';
$outputData = '<table class="table table-striped table-hover table-responsive-xs table-responsive-sm table-responsive-md table-responsive-lg" >';
$outputData .= "
<thead>
<tr>
<th scope='col'>קטגוריה</th>
<th scope='col'>התקציב שלי</th>
<th scope='col'>עלות בפועל</th>
<th scope='col'>תשלומים</th>
<th scope='col'>יתרה לתשלום</th>
<th scope='col'>הקובץ</th>
</tr>
</thead>
<tbody>
";
$totalHefresh = 0;
for ($i = 1; $i < count($data) / 2; $i++) {
$arrData = unserialize($data[$i]);
$heb_name = $arrData['data']['field_name_heb'];
$files = $arrData['data']['files'];
$myBudget = isset($arrData['data']['my_budget'])?$arrData['data']['my_budget']:0;
$myBudgetNumber = number_format($myBudget);
$estimatedCost = isset($arrData['data']['estimated_cost'])?$arrData['data']['estimated_cost']:0;
$estimatedCostNumber = number_format($estimatedCost);
$filesData = returnFiles($files, $arrData['data']['field_name'], $arrData['data']['stage']);
$total_field_cost = isset($arrData['data']['total_cost'])?$arrData['data']['total_cost']:0;
$payments = returnPayments($arrData['payments'], $arrData['data']['field_name'], $arrData['data']['stage']);
$hefresh = $estimatedCost - $total_field_cost;
$hefreshNumber = number_format($hefresh);
$totalEestimatedCost += $arrData['data']['estimated_cost'];
$totalEestimatedCostNumber = number_format($totalEestimatedCost);
$totalMyBudget += $arrData['data']['my_budget'];
$totalMyBudgetNumber = number_format($totalMyBudget);
$totalHefresh += $hefresh;
$totalHefreshNumber = number_format($totalHefresh);
$outputData .=
"<tr>
<td>$heb_name</td>
<td class='text-center'> <span> ₪ </span> <span>$myBudgetNumber</span> </td>
<td class='text-center'> <span> ₪ </span> <span>$estimatedCostNumber</span> </td>
<td >$payments</td>
<td class='text-center'><span> ₪ </span> <span>$hefreshNumber</span></td>
<td style='height: 118px'>$filesData</td>
</tr>
</tbody> ";
//echo "<pre>";
//print_r($arrData);
}
printDinamicDataTable($table , $outputData , $totalEestimatedCost , $totalHefresh);
$outputData .= "</table>";
$outputData .= "<div class='total-hfresh'>
<div>סה\"כ התקציב שלי: $totalMyBudgetNumber</div>
<div>סה\"כ עלות בפועל: $totalEestimatedCostNumber</div>
<div>יתרה לתשלום: $totalHefreshNumber</div>
</div>";
//echo "<br> $outputData";
$totalSum += $totalHefresh;
return $outputData;
}
};
function returnPayments($payments, $field, $stage)
{
$dataToReturn = '';
foreach ($payments as $key => $value) {
$payment = $value['payment'];
$date = $value['date'];
$note = $value['note'];
$dataToReturn .= "<table style='width: 100%;margin-bottom: 5px'><tr><td
class='pay-td1'>₪ $payment </td>";
$dataToReturn .= " <td class='pay-td2'>$note </td>";
$dataToReturn .= "<td class='pay-td3'> $date </td>";
$dataToReturn .= "<td><button data-stage='$stage' data-id='$key' data-
name='$field' class='deletePayment btn btn-danger'><b>X</b>
</button></td></tr></table>";
}
return $dataToReturn;
}
I'm very new to PHP and MySQLI, however, I have been dabbling with them for a couple of years.
I am working on adding a search function for some photos I have on my website based off of 3 criteria.
I've been successful in implementing the script on a different page, which does not include the syntax for the page limits. However, now, when I add in my $where_stmt code, I end up with some errors, and I believe it has to do with the placement of a needed }.
The script in question is:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
if (!defined('DB_SERVER')) define('DB_SERVER', 'xxx');
if (!defined('DB_USER')) define('DB_USER', 'xxx');
if (!defined('DB_PASSWORD')) define('DB_PASSWORD', 'xxx');
if (!defined('DB_TABLE')) define('DB_TABLE', 'xxx');
// The procedural way
$mysqli = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_TABLE);
$mysqli->set_charset("utf8");
$mysqli->query("SET NAMES 'utf8'");
if (mysqli_connect_errno($mysqli)) {
trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
}
// This first query is just to get the total count of rows
$sql = "SELECT COUNT(*) FROM tbl_photos";
$query = mysqli_query($mysqli, $sql);
$row = mysqli_fetch_row($query);
// Here we have the total row count
$rows = $row[0];
// This is the number of results we want displayed per page
$page_rows = 16;
// This tells us the page number of our last page
$last = ceil($rows/$page_rows);
// This makes sure $last cannot be less than 1
if($last < 1){
$last = 1;
}
// Establish the $pagenum variable
$pagenum = 1;
// Get pagenum from URL vars if it is present, else it is = 1
if(isset($_GET['pn'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
// This makes sure the page number isn't below 1, or more than our $last page
if ($pagenum < 1) {
$pagenum = 1;
} else if ($pagenum > $last) {
$pagenum = $last;
}
// This sets the range of rows to query for the chosen $pagenum
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
if(isset($_POST['submit']))
if(isset($_GET['go']))
if(isset($_REQUEST['submited'])) {
$tid = $_POST['tID'];
$lvmid = $_POST['lvmID'];
$lid = $_POST['lID'];
$where_stmt="";
// query only for LuchtvaartmaatschappijID (LVMID)
if((isset($lvmid) && !empty($lvmid)) && (!isset($tid) || empty($tid)) && (!isset($lid) || empty($lid)))
{
$where_stmt="WHERE lvm.luchtvaartmaatschappijID='".$lvmid."'";
}
// query only for ToestelID
elseif((isset($tid) && !empty($tid)) && (!isset($lvmid) || empty($lvmid)) && (!isset($lid) || empty($lid)))
{
$where_stmt="WHERE t.toestelID = '".$tid."'";
}
// query only for luchthaven
elseif((isset($lid) && !empty($lid)) && (!isset($lvmid) || empty($lvmid)) && (!isset($tid) || empty($tid)))
{
$where_stmt="WHERE img_location = '".$lid."'";
}
// query only for Luchtvaartmaatschappij and Toestel
elseif((isset($lvmid) && !empty($lvmid)) && (isset($tid) || !empty($tid)) && (!isset($lid) || empty($lid)))
{
$where_stmt="WHERE lvm.luchtvaartmaatschappijID='".$lvmid."' and t.toestelID='".$tid."'";
}
// query only for Luchtvaartmaatschappij and luchthaven
elseif((isset($lvmid) && !empty($lvmid)) && (isset($lid) || !empty($lid)) && (!isset($tid) || empty($tid)))
{
$where_stmt="WHERE lvm.luchtvaartmaatschappijID='".$lvmid."' and img_location = '".$lid."'";
}
// query for luchtvaartmaatschappij, toestel and luchthaven
elseif((isset($lvmid) && !empty($lvmid)) && (isset($tid) && !empty($tid)) && (isset($lid) && !empty($lid)))
{
$where_stmt="WHERE lvm.luchtvaartmaatschappijID='".$lvmid."' and t.toestelID='".$tid."' and img_location = '".$lid."'";
}
else
{
//where statement should be excluded as no filters are available
}
// This is your query again, it is for grabbing just one page worth of rows by applying $limit
$sql = "
SELECT randimgID, img_location, img_lvm, img_file, img_nmr, img_t, t.toestel, l.luchthavennaam, lvm.luchtvaartmaatschappij, lvm.luchtvaartmaatschappijID, t.toestelID
FROM tbl_photos p
LEFT JOIN tbl_luchthaven l
ON p.img_location = l.luchthavenID
LEFT JOIN tbl_luchtvaartmaatschappij lvm
ON p.img_lvm = lvm.IATAcode
LEFT JOIN tbl_toestel t
ON p.img_t = t.toestelID
$where_stmt
ORDER BY lvm.luchtvaartmaatschappij, t.toestel ASC, p.img_nmr ASC $limit";
$query = mysqli_query($mysqli, $sql);
/* determine number of rows result set */
$row_cnt = mysqli_num_rows($query);
// This shows the user what page they are on, and the total number of pages
$textline1 = "beelden (<b>$rows</b>)";
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>";
// Establish the $paginationCtrls variable
$paginationCtrls = '';
// If there is more than 1 page worth of results
if($last != 1){
/* First we check if we are on page one. If we are then we don't need a link to
the previous page or the first page so we do nothing. If we aren't then we
generate links to the first page, and to the previous page. */
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= '<li class="page-item"><a class="page-link" href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'">vorige</a> </li>';
// Render clickable number links that should appear on the left of the target page number
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
$paginationCtrls .= '<li class="page-item"><a class="page-link" href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> </li>';
}
}
}
// Render the target page number, but without it being a link
$paginationCtrls .= '<li class="page-item active">
<a class="page-link" href="#">'.$pagenum.' <span class="sr-only">(current)</span></a>
</li>';
// Render clickable number links that should appear on the right of the target page number
for($i = $pagenum+1; $i <= $last; $i++){
$paginationCtrls .= '<li class="page-item"><a class="page-link" href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> </li> ';
if($i >= $pagenum+4){
break;
}
}
// This does the same as above, only checking if we are on the last page, and then generating the "Next"
if ($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= '<li class="page-item"><a class="page-link" href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">volgende</a> </li>';
}
}
$list = '';
$items_in_row = 2 ;
$index = 0 ;
echo "<table width='100%' cellspacing='1' border='0'>
<tr>";
while($row = mysqli_fetch_assoc($query)) {
$img_location = $row['luchthavennaam'];
$img_lvm = $row['img_lvm'];
$l = htmlspecialchars($row['luchtvaartmaatschappij']);
$lvmID = $row['luchtvaartmaatschappijID'];
$img_nmr = $row['img_nmr'];
$t = $row['toestel'];
$tid = $row['toestelID'];
$f = $row['img_file'];
$rID = $row['randimgID'];
$img_file = $row['img_file'];
$image = "http://globe-trekking.com/vg/img/gallery/$img_lvm/$img_file";
$link = "http://globe-trekking.com/vg/gallery/details.php?pid=$rID&lvmID=$lvmID&in=$img_nmr";
$index++ ;
echo "<td width='370' align='left' valign='top' bgcolor='#292960'> ";
echo "<table width='540' border='0' cellpadding='0' cellspacing='0'>";
echo "<tbody>";
echo " <tr>";
echo " <td height='15' colspan='3' bgcolor='#292960'></td>";
echo " </tr>";
echo " <tr>";
echo " <td height='15' colspan='3' bgcolor='#000033'></td>";
echo " </tr>";
echo "<tr>";
echo " <td width='15' bgcolor='#000033'> </td>";
echo " <td bgcolor='#000033'><a href='" . $link ."'><img src='".$image."' width='510'></a></td>";
echo " <td width='15' bgcolor='#000033'></td>";
echo "</tr>";
echo "<tr>";
echo " <td bgcolor='#000033'> </td>";
echo " <td bgcolor='#000033'><table width='510' border='0' align='center' cellpadding='0' cellspacing='0'>";
echo " <tr>";
echo " <td height='15' colspan='2' valign='top' style='text-align: left'> </td>";
echo " </tr>";
echo " <tr>";
echo " <td width='72%' valign='top' style='text-align: left'><span style='font-size: 18px; color: #DEDEDE'><a class='airline' href='gallery_lvm.php?lvmid=$lvmID'>" . $l . "</a></span></td>";
echo " <td width='28%' style='text-align: left'><span style='font-size: 14.5px; color: #DEDEDE'>Reg: <a class='airline' href='gallery_reg.php?reg=$img_nmr'>" . $img_nmr . "</a></span></td>";
echo " </tr>";
echo " <tr>";
echo " <td height='10' colspan='2' valign='top' style='text-align: left'></td>";
echo " </tr>";
echo " <tr>";
echo " <td valign='top' style='text-align: left'><span style='font-size: 14.5px; color: #DEDEDE'><a class='airline' href='gallery_t.php?tid=$tid'>" . $t . "</a></span></td>";
echo " <td style='text-align: left'> </td>";
echo " </tr>";
echo " <tr>";
echo " <td height='10' colspan='2' valign='top' style='text-align: left'></td>";
echo " </tr>";
echo " <tr>";
echo " <td colspan='2' valign='top' style='text-align: left'><span style='font-size: 14.5px; color: #DEDEDE'>" . $img_location . "</span><br>
<br>
</td>";
echo " </tr>";
echo " <tr>";
echo " <td style='text-align: left'> </td>";
echo " <td style='text-align: left'> </td>";
echo " </tr>";
echo " </table></td>";
echo " <td bgcolor='#000033'> </td>";
echo "</tr>";
echo "<tr>";
echo " <td> </td>";
echo " <td> </td>";
echo " <td> </td>";
echo "</tr>";
echo " </tbody>";
echo " </table>";
echo " </td>";
if ($index%$items_in_row == 0){
echo " </tr>";
echo " <tr>";
}
}
echo " </tr>";
echo " </table>";
// Close your database connection
mysqli_close($mysqli);
?>
<br />
<nav aria-label="Page Navigation">
<ul class="pagination justify-content-center">
<div class="pagination"><?php echo $paginationCtrls; ?></div>
</ul>
</nav>
<br />
</div>
<br />
<br />
</div>
<?php include '../includes/menu/footer.php'; ?>
</body>
</html>
When I add it after the last else statement, I end up with an error that indicate
Notice: Undefined variable: where_stmt in /xxx/xxx/public_html/vg/gallery/search_post.php on line 174
// query for luchtvaartmaatschappij, toestel and luchthaven
elseif((isset($lvmid) && !empty($lvmid)) && (isset($tid) && !empty($tid)) && (isset($lid) && !empty($lid)))
{
$where_stmt="WHERE lvm.luchtvaartmaatschappijID='".$lvmid."' and t.toestelID='".$tid."' and img_location = '".$lid."'";
}
else
{
//where statement should be excluded as no filters are available
}
}
If I add it just before the mysqli_close() then it throws an error of:
PHP Notice: Undefined variable: paginationCtrls in
/xxx/xxx/public_html/vg/gallery/search_post.php on line 325
If I leave it out all together I get the following red x error in the web editor my hosting company provides me with:
Unexpected syntax, error $E0F
At this point, I'm not sure where this should be placed.
I should note that I can get the code to work when I get rid of the $where_stmt and the code above the $sql query.
I can recommend you to have a look at ORM libraries like http://propelorm.org/documentation/reference/model-criteria.html#finding-objects to avoid handwritten SQL and concatenated where clauses.
Also make sure that $paginationCtrls is declared before using it.
I am not very familiar with PHP or MySQL, but after researching here I have been able to learn and get very close to what I need and build my first sum query. I am trying to read the database and sum values based on several variables.
I need the reservation_pax from the reservations table where reservation_time is 8:00 where reservation_hidden = 0 and reservation_date is something. I can manually enter the date and it works. I am now trying to use a session code already in the script or find a way to to dynamically add based on selected date.
Here is the code I have working without the dynamic aspect or session.
$result = mysql_query("SELECT SUM(reservation_pax)
FROM reservations
WHERE reservation_time = '8:00:00'
AND reservation_date = '2014-10-27'
AND reservation_hidden ='0'") ;
if ($result === false) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result)) {
echo $row['SUM(reservation_pax)'];
}
Here is the full code of the page where I entered the above addition. Can anyone help me figure out how to call the selected date rather than having to manually enter.
<!-- Begin reservation table data -->
<br/>
<table class="global resv-table-small" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<?php
echo "<td class='noprint'> </td>";
echo "<td>Time</td>";
echo "<td>Guests/Type</td>";
echo "<td>Name</td>";
echo "<td>Special Instructions/Notes</td>";
echo "<td class='noprint'>Table</td>";
echo "<td class='noprint'>Status</td>";
echo "<td class='noprint'>Created</td>";
echo "<td class='noprint'>Details/Delete</td>";
echo "</tr>";
// Clear reservation variable
$reservations ='';
if ($_SESSION['page'] == 1) {
$reservations = querySQL('all_reservations');
}else{
$reservations = querySQL('reservations');
}
// reset total counters
$tablesum = 0;
$guestsum = 0;
if ($reservations) {
//start printing out reservation grid
foreach($reservations as $row) {
// reservation ID
$id = $row->reservation_id;
$_SESSION['reservation_guest_name'] = $row->reservation_guest_name;
// check if reservation is tautologous
$tautologous = querySQL('tautologous');
echo "<tr id='res-".$id."'>";
echo "<td";
// daylight coloring
if ($row->reservation_time > $daylight_evening){
echo " class='evening noprint'";
}else if ($row->reservation_time > $daylight_noon){
echo " class='afternoon noprint'";
}else if ($row->reservation_time < $daylight_noon){
echo " class='morning noprint'";
}
echo " style='width:10px !important; padding:0px;'> </td>";
echo "<td id='tb_time'";
// reservation after maitre message
if ($row->reservation_timestamp > $maitre['maitre_timestamp'] && $maitre['maitre_comment_day']!='') {
echo " class='tautologous' title='"._sentence_13."' ";
}
echo ">";
echo "<strong>".formatTime($row->reservation_time,$general['timeformat'])."</strong></td>";
echo "<td id='tb_pax'><strong class='big'>".$row->reservation_pax."</strong> <span class='noprint'>";
printType($row->reservation_hotelguest_yn);
//echo "<img src='images/icons/user-silhouette.png' class='middle'/>";
echo "</span></td><td style='width:10%' id='tb_name'><span class='noprint'>".printTitle($row->reservation_title)."</span><strong> <a id='detlbuttontrigger' href='ajax/guest_detail.php?id=".$id."'";
// color guest name if tautologous
if($tautologous>1){echo" class='tautologous tipsy' title='"._tautologous_booking."'";}
echo ">".$row->reservation_guest_name."</a></strong>";
// old reservations symbol
if( (strtotime($row->reservation_timestamp) + $general['old_days']*86400) <= time() ){
echo "<img src='images/icons/clock-bolt.png' class='help tipsyold middle smicon' title='"._sentence_11."' />";
}
// recurring symbol
if ($row->repeat_id !=0) {
echo " <img src='images/icons/loop-alt.png' alt='"._recurring.
"' title='"._recurring."' class='tipsy' border='0' >";
}
echo"</td><td style='width:10%' id='tb_note'>";
if ($_SESSION['page'] == 1) {
echo $row->outlet_name;
}else{
echo $row->reservation_notes;
}
echo "</td>";
if($_SESSION['wait'] == 0){
echo "<td class='big tb_nr' style='width:85px;' id='tb_table'><img src='images/icons/table_II.png' class='tipsy leftside noprint' title='"._table."' /><div id='reservation_table-".$id."' class='inlineedit'>".$row->reservation_table."</div></td>";
}
echo "<td class='noprint'><div>";
getStatusList($id, $row->reservation_status);
echo "</div></td>";
echo "<td class='noprint'>";
echo "<small>".$row->reservation_booker_name." | ".humanize($row->reservation_timestamp)."</small>";
echo "</td>";
echo "<td class='noprint'>";
// MOVE BUTTON
// echo "<a href=''><img src='images/icons/arrow.png' alt='move' class='help' title='"._move_reservation_to."'/></a>";
// WAITLIST ALLOW BUTTON
if($_SESSION['wait'] == 1){
$leftspace = leftSpace(substr($row->reservation_time,0,5), $availability);
if($leftspace >= $row->reservation_pax && $_SESSION['outlet_max_tables']-$tbl_availability[substr($row->reservation_time,0,5)] >= 1){
echo" <a href='#' name='".$id."' class='alwbtn'><img src='images/icons/check-alt.png' name='".$id."' alt='"._allow."' class='help' title='"._allow."'/></a> ";
}
}
// EDIT/DETAIL BUTTON
echo "<a href='?p=102&resID=".$id."'><img src='images/icons/pen-fill.png' alt='"._detail."' class='help' title='"._detail."'/></a> ";
// DELETE BUTTON
if ( current_user_can( 'Reservation-Delete' ) && $q!=3 ){
echo"<a href='#modalsecurity' name='".$row->repeat_id."' id='".$id."' class='delbtn'>
<img src='images/icons/delete.png' alt='"._cancelled."' class='help' title='"._delete."'/></a>";
}
echo"</td></tr>";
$tablesum ++;
$guestsum += $row->reservation_pax;
}
}
?>
</tbody>
<tfoot>
<tr style="border:1px #000;">
<td class=" noprint"></td><td></td>
<td colspan="2" class="bold"><?php echo $guestsum;?> <?php echo _guest_summary;?></td>
<td></td>
<td colspan="2" class="bold"><?php echo $tablesum;?> <?php echo _tables_summary;?></td>
<td colspan="2" class="bold"><?php
$result = mysql_query("SELECT SUM(`reservation_pax`) FROM `reservations` WHERE `reservation_time` = '8:00:00' AND `reservation_date` = '{$_SESSION['selectedDate']}' AND `reservation_hidden` ='0'") ;
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result))
{
echo $row['SUM(reservation_pax)'];
}
?>
<?php echo '/ 40 ', _guest_summary, ' -8:00 AM';?></td>
<td></td>
<?php
if($_SESSION['wait'] == 0){
//echo "<td></td>";
}
?>
</tr>
</tfoot>
</table>
<!-- End reservation table data -->
you can use alias field, as:
$result = mysql_query("SELECT SUM(reservation_pax) AS reserve_sum
FROM reservations WHERE reservation_time = '8:00:00'
AND reservation_date = '2014-10-27'
AND reservation_hidden ='0'"
) ;
....
and get access it as:
while($row = mysql_fetch_array($result))
{
echo $row['reserve_sum'];
}
$result = mysql_query("SELECT SUM(reservation_pax) FROM reservations WHERE reservation_time = '8:00:00' AND reservation_date = '{$_SESSION['selectedDate']}' AND reservation_hidden ='0'") ;
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result))
{
echo $row['SUM(reservation_pax)'];
}
?>
I know this has been asked before and I have got it working using the following code:
<?php
$maxcols = 8; $i = 0;
echo "<table id='table1'><tr>";
foreach ($id as $k => $v) {
echo "<td id='0'><div id='{$k}' class='drag t1'>{$v}</div></td>"; $i++;
if ($i == $maxcols) { $i = 0; echo "</tr><tr>"; }
} $i++;
while ($i <= $maxcols) {
$i++; echo "<td></td>";
}
echo "</tr></table>";
?>
This results in a table that looks like this :
I'd like to add headers to this so the end result looks like this:
I'd like to do it dynamically so if I create a table that is only 5 columns wide I'd get on the first header row ID01 - ID05 and on the second header row ID06 - ID10
I want to limit the header ID values to be no more than $maxid any extra header fields should be blank, like this : If $maxid = 12; then :
I need the header rows are made as follows and not using <TH>
<td class="mark">
I'm using some javascript to allow the movement of cell data.
The class is used to set the formatting on the header and stop items from being dragged into the fields.
Can anyone point me in the right direction on how to do this.
This should help you.
$maxcols = 8;
$maxid = 12;
$startid = 1;
echo "<table id='table1'>\n";
for ($i = 1;$i<=ceil($maxid/$maxcols);$i++) {
echo "<tr>\n";
for ($j=1;$j<=$maxcols;$j++)
if ($startid <= $maxid)
echo " <td class='mark'>ID".$startid++."</td>\n";
else
echo " <td> </td>\n";
echo "</tr>\n<tr>\n";
for ($j=1;$j<=$maxcols;$j++)
echo "<td>Content</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
Generates
<table id='table1'>
<tr>
<td class='mark'>ID1</td>
<td class='mark'>ID2</td>
<td class='mark'>ID3</td>
<td class='mark'>ID4</td>
<td class='mark'>ID5</td>
<td class='mark'>ID6</td>
<td class='mark'>ID7</td>
<td class='mark'>ID8</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td class='mark'>ID9</td>
<td class='mark'>ID10</td>
<td class='mark'>ID11</td>
<td class='mark'>ID12</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
</table>
try this. It will work in the same way as you desired
<?php
$id= array("1","2","3","4","5","6","7","8","9","10","11","12");
$maxcols = 8; $i = 0;$j=0;$t=0;$s=0;
$maxid = count($id);
echo "<table id='table1'><tr>";
foreach ($id as $k => $v)
{
if($t == 0)
{
while ($t <= $maxcols-1) {
if($s < $maxid)
{
$s++;$t++; echo "<td class='mark'>id$s</td>";
}
else
{
echo "<td class='mark'></td>";$t++;$s++;
}
}
echo "</tr><tr>";
}
else
{
}
echo "<td id='0'><div id='{$k}' class='drag t1'>{$v}</div></td>"; $i++;
if ($i == $maxcols)
{
echo "</tr><tr>";
if($j == 0)
{
while ($j <= $maxcols-1) {
if($s < $maxid)
{
$s++;$j++; echo "<td class='mark'>id$s</td>";
}
else
{
echo "<td class='mark'></td>";$j++;$s++;
}
}
echo "</tr><tr>";
}
$i=0;
}
}
echo "</tr></table>";
?>
Output
Hi You can Use My Library:
class generate{
private $row = "<tr>{columns}</tr>";
private $td = "<td {attr}>{data}</td>";
private $attributeTR="";
private $attributeTD="";
private $tdBuilder="";
public function addCol($ColumValsArr=array("class='motota'"=>"Example")){
foreach($ColumValsArr as $key=>$val){
$newCol = str_replace("{data}",$val,$this->td);
$newCol = str_replace("{attr}",$key,$newCol);
$this->tdBuilder .= str_replace("{data}",$key,$newCol);
}
}
public function getRow(){
return str_replace("{columns}",$this->tdBuilder,$this->row);
}
}
<?php
function TableFunc($Data)
{
$Table = "<table>" . PHP_EOL;
foreach ($Data as $tags => $array) {
$Table .= "<$tags>" . PHP_EOL;
foreach ($array as $thead) {
$tag=$tags==="tbody"?"td":"th";
$Table .= "<tr>" . PHP_EOL;
if (is_array($thead)) {
foreach ($thead as $theadItem) {
if (is_array($theadItem))
$Table .= "<$tag colspan='$theadItem[1]'>$theadItem[0]</$tag>" . PHP_EOL;
else
$Table .= "<$tag>$theadItem</$tag>" . PHP_EOL;
}
}
$Table .= "</tr>" . PHP_EOL;
}
$Table .= "</$tags>" . PHP_EOL;
}
$Table .= "</table>" . PHP_EOL;
return $Table;
}
$Data = array(
"thead" => [
[["GENEL BİLGİ", 2], ["KALORİMETRE (ISINMA)", 2], ["HESAPLAMA", 2]],
["NO", "AD SOYAD", "FARK", "TUTAR", "OKUMA", "ÖDENECEK"]
],
"tbody"=>array(
array("1","MURAT DURAN","100","100.00","10.00","110.00"),
array("1","MURAT DURAN","100","100.00","10.00","110.00"),
array("1","MURAT DURAN","100","100.00","10.00","110.00"),
array("1","MURAT DURAN","100","100.00","10.00","110.00"),
),
"tfoot" => [["NO", "AD SOYAD", "M2", "MAHSUP", "SAYAÇ", "15°", "FARK", "TUTAR", "ORTAK ALAN", "EKSTRA", "MUAFİYET", "OKUMA", "ÖDENECEK"]]
);
echo TableFunc($Data);
How would I create a table that multiples height by weight?
I have no idea how to figure it out!
I am trying to create a BMI calculator.
// collect values from a form sent with method=get
$min_weight = mysql_real_escape_string($_GET["min_weight"]);
$max_weight = mysql_real_escape_string($_GET["max_weight"]);
$min_height = mysql_real_escape_string($_GET["min_height"]);
$max_height = mysql_real_escape_string($_GET["max_height"]);
?>
<table>
<tr>
<td>Key:</td>
<td class="good show">Healthy (20-25)</td>
<td cla ss="warning show">Overweight (25-30)</td>
<td class="bad show">Unhealthy ( -20 or 30+)</td>
</tr>
</table>
<table border="1">
<?php
echo "<tr><td>Height →<br>Weight ↓</td>";
for ( $i = $min_height; $i <= $max_height; $i+=5 )
{
echo "<td>{$i}</td>";
}
echo "</tr>";
for ( $j = $min_weight; $j <= $max_weight; $j+=5 )
{
echo "<tr>";
echo "<td>{$j}</td>";
echo "</tr>";
}
This should do the job, i've also put some isset()'s:
<?php
// collect values from a form sent with method=get
$min_weight = isset($_GET["min_weight"]) ? mysql_real_escape_string($_GET["min_weight"]):0;
$max_weight = isset($_GET["max_weight"]) ? mysql_real_escape_string($_GET["max_weight"]):0;
$min_height = isset($_GET["min_height"]) ? mysql_real_escape_string($_GET["min_height"]):0;
$max_height = isset($_GET["max_height"]) ? mysql_real_escape_string($_GET["max_height"]):0;
?>
<table>
<tr>
<td>Key:</td>
<td class="good show">Healthy (20-25)</td>
<td class="warning show">Overweight (25-30)</td>
<td class="bad show">Unhealthy ( -20 or 30+)</td>
</tr>
</table>
<?php
$table = '<table border="1">';
$table .= '<tr><td>Height →<br>Weight ↓</td>';
for ($i = $min_height;$i <= $max_height;$i += 5){
$table .= "<td>$i</td>";
}
$table .= "</tr>";
for($j = $min_weight; $j <= $max_weight;$j += 5){
$table .= "<tr><td>$j</td>";
for ($i = $min_height;$i <= $max_height;$i += 5){
$table .= '<td>'. $i * $j .'</td>';
}
$table .= '</tr>';
}
$table .= '</table>';
echo $table;
?>
Even though this works is it wrong to have the table border outside of the php tags?
<table>
<tr>
<td>Key:</td>
<td class="good show">Healthy (20-25)</td>
<td class="warning show">Overweight (25-30)</td>
<td class="bad show">Unhealthy ( -20 or 30+)</td>
</tr>
</table>
<table border="1">
<?php
echo "<tr><td>Height →<br>Weight ↓</td>";
for ( $j = $min_height; $j <= $max_height; $j+=5 )
{
echo "<td>{$j}</td>";
}
for ( $i = $min_weight; $i <= $max_weight; $i+=5 )
{
echo "<tr><td>{$i}</td>";
for ( $j = $min_height; $j <= $max_height; $j+=5 )
{
$var = number_format(($i)/(($j/100)*($j/100)),'2','.','');
{
echo "<td class='warning'>";
}
echo $var;
echo "</td>";
}
echo "</tr>";
}
?>
</table>