PHP echo tables - php

Overview
I have some data stored in MySql database related to Products. I am trying to retrieve this data and display it on a page using HTML table.
The PHP and MySql has gone well and all the data is retrieved but it is displayed in a very messy manner.
Here is what I have as a layout:
What I am aiming to achieve is to further divide the results table add more columns rows to make the data more readable
Something like this;
The code: PHP, MySQL & HTML:
<?php
session_start();
include('connect_mysql.php');
$product_name = 'product_name';
$product_qua = 'product_qua';
$product_price = 'product_price';
$product_image = 'product_image';
$product_des = 'product_des';
$sql = mysql_query("SELECT * FROM products");
echo "<table id='display'>";
while($rows = mysql_fetch_array($sql))
{
echo"<br>";
echo"<tr><td>";
echo"$rows[$product_name]<br></td>";
echo"<td><img src=$rows[$product_image] height='200px' width='200px'><br></td>";
echo"<td>Avalible: $rows[$product_qua]<br></td>";
echo"<td>Price: $rows[$product_price]<br></td>";
echo"<td>Description: $rows[$product_des]<br></td>";
echo"</tr>";
}
echo "</table>";
?>
CSS responsible for this part:
#display{
float:left;
border: 5px solid black;
margin-left:100px;
}

just add some padding or a border to the table cells:
table#display td{
border: 1px solid black;
padding:0 8px;
}
Edit: What you could do as well:
<table id='display'>
<?php while($rows = mysql_fetch_array($sql)): ?>
<!-- <br> <- why a break? it's not in the correct spot anyway -->
<tr><td>
<?php echo $rows[$product_name]; ?><br>
</td>
<td> - </td>
<td><img src="<?php echo $rows[$product_image]; ?>" height='200px' width='200px'><br></td>
<td> - </td>
<td>Avalible: <?php echo $rows[$product_qua]; ?><br></td>
<td> - </td>
<td>Price: <?php echo $rows[$product_price]; ?><br></td>
<td> - </td>
<td>Description: <?php echo $rows[$product_des]; ?><br></td>
</tr>
<?php endwhile; ?>
</table>
Tip: I prefer to use the while/endwhile; approach rather than using brackets when displaying data to the user.

First of all don't echo so much HTML using PHP, instead do it like this
<?php
session_start();
include('connect_mysql.php');
$product_name = 'product_name';
$product_qua = 'product_qua';
$product_price = 'product_price';
$product_image = 'product_image';
$product_des = 'product_des';
$sql = mysql_query("SELECT * FROM products"); ?>
<table id='display'>
<?php
while($rows = mysql_fetch_array($sql)) {
?>
<tr><td><?php echo $rows[$product_name]; ?></td>
<!-- And so on-->
<?php
}
?>
</table>
Secondly by seeing your inmage, it seems like you need a border for your table so use
table, td {
border: 1px solid #000000;
}

add the following css to apply border on your table cells:
#display td{ border: 2px solid red; }
and optionally add to your #display { :
border-collapse: collapse;

Related

How to create a dynamic table in PHP from SQL

I try to make a dynamic table. The data comes from a database.
It works so far, but I want to make a table with seperate fields, not like my way.
My code so far:
<?php
$result = mysql_query("SELECT buyTime, untilTime FROM users WHERE userName='".$_SESSION["user"]."';");
$num_rows = mysql_num_rows($result);
echo("Buy Date"."|Expire Date");
echo "<br />";
echo "<br />";
while ($row = mysql_fetch_array($result)) {
echo '<th>'.$row['buyTime'].'</th>'."|".'<th>'.$row['untilTime'].'</th>';
echo "<br />";
}
?>
The result:
Click here
So how can I make a correct table, not a pseudo one?
Thank you :)
Regards
Use a table element on html and put your php loop code inside the tbody element. How to properly create a table;
<table>
<thead>
<tr>
<th>Buy Date</th>
<th>Expire Date</th>
</tr>
</thead>
<tbody>
<?php
$result = mysql_query("SELECT buyTime, untilTime FROM users WHERE userName='".$_SESSION["user"]."';");
$num_rows = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td>'.$row['buyTime'].'</td><td>'.$row['untilTime'].'</td>';
echo '</tr>'
}
?>
</tbody>
</table>
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<h2>Colored Table Header</h2>
<table>
<tr>
<th>Buy Date</th>
<th>Expire Date</th>
</tr>
<?php
$result = mysql_query("SELECT buyTime, untilTime FROM users WHERE userName='".$_SESSION["user"]."';");
$num_rows = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) { ?>
<tr>
<td><?php echo $row['buyTime']; ?></td>
<td><?php echo $row['untilTime']; ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
NOTE: An HTML table is defined with the <table>tag.
Each table row is defined with the <tr> tag. A table header is defined with the <th> tag. By default, table headings are bold and centered. A table data/cell is defined with the <td> tag. Moreover Mysql is outmoded please try learn new approach. You can learn it on w3schools php
Good Luck!!!

PHP Variable not Echoing

Evening All, just trying to figure out why some of my variables are not echoing from my MYSQL database. At first they were going to be Session variables of which i found did not work, so then i changed to a mysql query on my invoice page
$OrderID = $_SESSION[OrderID];
$LName = mysql_result(mysql_query("SELECT LName FROM customers WHERE Username = '$Username'"), 0);
$Fname = mysql_result(mysql_query("SELECT FName FROM customers WHERE Username = '$Username'"), 0);
$Date = mysql_result(mysql_query("SELECT Date FROM orders WHERE OrderID = '$OrderID'"), 0);
My Queries above. Order ID and Date are working, yet Lname and Fname are not where everything is named correctly as they are in the database.
Full Code below of where i am trying to echo them.
<div id='containter' style='position:absolute;width:750px;height:800px; left:50% ; margin-left: -375px; border-style: solid;border-width: 1px;'>
<div id='heading' style='position:absolute;width:650px;height:100px; left:50% ; margin-left: -325px;top:20px; border-style: solid;border-width: 1px;'>
<div style='position:absolute;left:500px;text-align:center;font-size:36px;'> <p>INVOICE </p></div>
<div style='position:absolute;text-align:center;font-size:38px;width:250px;left:-20px;'> OzScopes</div>
<div style='position:absolute;text-align:center;font-size:16px;width:250px;left:-37px;top:45px;'> ozscopes.com.au</div>
<div id='headingbottom' style='position:absolute;width:100%;height:20px;top:80px;'>
<table>
<tr>
<td style='position:absolute;left:5%;'>Invoice Number </td>
<td style='position:absolute;left:25%;'> <?php echo $OrderID;?> </td>
<td style='position:absolute;left:77%;'><?php echo $Date ;?></td>
</tr>
</table>
</div>
</div>
<div id='invoicecontent' style='position:absolute;width:650px;height:600px; left:50% ; margin-left: -325px;top:140px; border-style: solid;border-width: 1px;'>
<div id='information'>
<div id='customerinfo' style='position:absolute;width:255px;height:75px;top:-210px;padding:10px; border-bottom: 2px solid;border-right:1px solid; display:inline'>
<table>
<tr>
<th>Customer Information</th>
</tr>
<tr>
<td> <?php echo $LName;?> lnametest</td>
</tr>
</table>
</div>
<div id='mailinginfo' style='position:absolute;width:355px;height:75px;left:275px;top:-210px;padding:10px;border-bottom: 2px solid; display:inline'>
Mailing Information
</div>
</div>
<div id='products' style='position:absolute;top:97px;width:650px;height:503px;'>
<?php
echo "<table border=\"0\" cellspacing=\"0\" padding=\"0\" width=\"650px\">";
echo "<tr style='font-weight: bold; font-size:16px;'>";
echo "<td colspan=\"2\" align=\"center\" style='border-bottom: 2px solid;font-family:'Ek Mukta';color:#464d48;'>Description</td>";
echo "<td align=\"left\" style='border-bottom: 2px solid;font-family:'Ek Mukta';color:#464d48;'>Quantity</td>";
echo "<td colspan=\"3\" align=\"center\" style='border-bottom: 2px solid ;font-family:'Ek Mukta';color:#464d48;'>Price (Per Unit)</td>";
echo "<td align=\"center\" style='border-bottom: 2px solid;font-family:'Ek Mukta';color:#464d48;'>Total</td>";
echo "</tr>";
echo "</table>";
?>
</div>
<div id='payment'>
</div>
</div>
</div>
Where are you getting $Username? should you get it from the session first?
Like so:
$Username = $_SESSION[Username];
otherwise this string is empty and the select statement will come back as empty, because the where clause was based on username = $Username (which in this case is empty).
Get username of the session variable first, then use it in where clause. Apart from that, as others have said, please avoid using mysql queries, use mysqli instead.
Hope it helps.

How to show selected table row id in the address bar with ajax

I have this below script that load the selected table row details in a div in the same page with ajax.
$('.positiontitle-link').click(
function(){
var durl = $(this).attr('ref');
$('#details').load(durl)
}
)
This is my Table where it have two column. First column used to list the jobs from MySQL database and the second used to view the selected row full details.
<table class="table1" width="100%" cellpadding="0" cellspacing="0" style="height: 100%; z-index:1; top:0; position: absolute;">
<tr>
<td width="30%" style=" min-width:40px;padding:0; background-color:rgba(255, 255, 255, 0.9); height: 100%; bottom: 0; top:0;" valign="top">
<div style="margin: 0; padding: 0; overflow-x:hidden; height: 100%; position: inherit; bottom: 0; top:0;">
<?php
require "module/call.php";
?>
</div>
</td>
<td width="60%" style="min-width:40px;padding:0; background-color:rgba(255, 255, 255, 0.9); height: 100%; bottom: 0; top:0;" valign="top"><div id="details" style="overflow:auto; width:100%; border-left-width: thin; border-right-width: 0; border-top-width: thin; border-bottom-width: 0; height: 100%; bottom: 0; top:0;"></div></td>
<td width="20%" style="padding:0;"> </td>
</tr>
</table>
This is the imageof the table
This is the call.php codes
<?php
$result = mysqli_query($conn,"SELECT * FROM job where approved='1' ORDER BY `CreatedTime` DESC");
echo "<table id='maintable' class='table-fill' border='0' cellpadding='0' cellspacing='0'>
<tr>
<th position='fixed' overflow='hidden' width='10%'>Job Title</th>
<th position='fixed' width='5%'>Company Name</th>
<th width='5%'>Closing Date</th>
</tr>";
while($row = mysqli_fetch_array($result) )
{
if (strlen($row['positiontitle']) > 20) $row['positiontitle'] = substr($row['positiontitle'], 0, 60) . "...";
echo "<tr onclick='get_data(123)' ref='job.details.php?id=".$row['id']."' target='content' class='positiontitle-link'>";
echo "<td data-id='<?php echo $row['id']?>'><font style='text-shadow: none;'>" . $row['positiontitle'] . "</font></a></td>";
echo "<td data-id='<?php echo $row['id']?>'>" . $row['companyname'] . "</td>";
echo "<td data-id='<?php echo $row['id']?>'>" . $row['closingdate'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
and this is the details.php codes
<?php
$result = mysqli_query($conn,"SELECT * FROM job WHERE id = '".$_GET['id']."' ORDER BY `CreatedTime` DESC");
$jobdetails = mysqli_fetch_assoc($result);
echo ''.$jobdetails['positiontitle'].'';?>
</title>
</br>
<div style="width:100%; margin-top:-20px;">
<!-------------------------------------------Start of Right Sidebar---------------------------------------------------------------->
<div style="float:left; font-size: 14px; width:20%;"class="ara-form">
<header style="padding-top: 25px; font-size: 14px; color:#666666; padding-left:7px; padding-right:7px;">
<?php
$result = mysqli_query($conn,"SELECT * FROM job WHERE id = '".$_GET['id']."' ORDER BY `CreatedTime` DESC");
$jobdetails = mysqli_fetch_assoc($result);
echo '<strong>Job Title</strong><hr class="style-six"> '.$jobdetails['positiontitle'].'</p></br>';
echo '<strong>Company Name</strong><hr class="style-six"> '.$jobdetails['companyname'].'</p></br>';
echo '<strong>Location</strong><hr class="style-six"> '.$jobdetails['location'].'</p></br>';
echo '<strong>Closing Date</strong><hr class="style-six"> '.$jobdetails['closingdate'].'</p></br>';
echo '<strong>Number of Vacancy</strong><hr class="style-six"> '.$jobdetails['numberofvacancy'].'</p></br>';
echo '<strong>Job Category</strong><hr class="style-six"> '.$jobdetails['jobcategory'].'</p></br>';
echo '<strong>Duration</strong><hr class="style-six">'.$jobdetails['duration'].'</p></br>';
echo '<strong>Employment Type</strong><hr class="style-six"> '.$jobdetails['employmenttype'].'</p></br>';
echo '<strong>Salary</strong><hr class="style-six"> '.$jobdetails['salary'].'</p></br>';
echo '<strong>Timing</strong><hr class="style-six"> '.$jobdetails['timing'].'</p></br>';
echo '<strong>Nationality</strong><hr class="style-six"> '.$jobdetails['nationality'].'</p></br>';
echo '<strong>Gender</strong><hr class="style-six">'.$jobdetails['gender'].'</p></br>';
echo '<strong>Experience</strong><hr class="style-six">'.$jobdetails['experience'].'</p></br>';
echo '<strong>Education</strong><hr class="style-six"> '.$jobdetails['education'].'</p></br>';
echo '<strong>Gender</strong><hr class="style-six"> '.$jobdetails['gender'].'</p></br>';
echo '<strong>Gender</strong><hr class="style-six"> '.$jobdetails['gender'].'</p></br>';
?>
</header>
</div>
<!---------------------------------------------End of Right Sidebar------------------------------------------->
<div style="float:left; font-size: 14px; width:80%;" class="ara-form">
<fieldset style="font-size: 14px; color:#666666;">
<!-------------------------------------------------Start Time viewed Button------------------------------------------------>
<div style="width:100px; float:right; padding-left:2px; padding-top: 10px;">
<?php
include "module/button/job.views.php";
?>
</div>
<!---------------------------------------------------End Time viewed Button------------------------------------------------->
<!-----------------------------------------------Start Main Content----------------------------------------------->
<?php
echo '<p><strong>Company Background</strong><hr class="style-six"> '.$jobdetails['background'].'</p></br>';
echo '<p><strong>Job Summary</strong><hr class="style-six"> '.$jobdetails['summary'].'</p></br>';
echo '<p><strong>Job Duties and Responsibilities</strong><hr class="style-six"> '.$jobdetails['duty'].'</p></br>';
echo '<p><strong>Qualification</strong><hr class="style-six"> '.$jobdetails['qualification'].'</p></br>';
echo '<p><strong>Skills</strong><hr class="style-six"></br> '.$jobdetails['skill'].'</p></br>';
echo '<p><strong>Submission Guideline</strong><hr class="style-six"> '.$jobdetails['submission'].'</p></br>';
echo '<p><strong>Words to search this job</strong><hr class="style-six"> '.$jobdetails['search'].'</p></br>';
?>
<!-------------------------------------------------End Main Content----------------------------------------------->
</fieldset></div>
My Question is
1- I want to show the selected row id in the address bar
2- I want to show unclicked.php in the details div when no row selected
If you want to change the content of the address bar without refreshing the page, you'll either need to use the HTML5 History API or a hashbang URL.
HTML5 History API: This will allow you to change the content of the address bar to whatever you like, but the browser support is limited. An example is as follows:
history.pushState(null, "", "/test");
This will change the page URL to yoursite.com/test.
You can use this to add a row-related extension to the URL, eg. yoursite.com/table/row/20.
See here for a more in-depth explanation of how the API works.
Hashbang URL: This is a less clean solution, but is somewhat simpler and will work on all browsers. Your URL will look like yoursite.com/table#row20. (If you already have a # in the page URL, this will not work). Just call window.location = "#row20" to add #row20 to the current page URL.
If you are going to change the URL when a new row is selected, then you should also check the URL on page load and preselect a row if required. Eg. requesting yoursite.com/table#row20 would return the page with row 20 already selected.
$('#details').load('path/to/unclicked.php') will load the file's contents into the div. If you want this to occur on page load, just wrap it in a call to $(document).ready(). Simply make the AJAX request again if the user is able to deselect all rows.

how to select and echo an image from mysql

I am trying to get information from mysql including a blob image which i shall echo with php and will have an onclick event within the php, redirecting it to another page. The onlick event will contain a mysql result which it will carry with it as seen in the code below.
My main issue is with the syntax of the code or if there is another way to do it all together. please keep in mind the output when the script is run is similiar to that of google images, bing images etc. Thank you.
<?php
$con=mysqli_connect("localhost","root","*******","media");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM movies ORDER BY `movies`.`title` ASC");
echo "<table border='3' style='margin: auto; text-align: left;background: white; padding: 3em;'>
<tr>
<th><b>Movie Title</b></th>
<th><b>Language</b></th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td style='padding-right: 2em;'><img src="data:image/jpeg;base64,' . base64_encode( $row['image'] ) . '" width="160px" height="200px";" onclick="window.location='lookup.php?pattern=" . $row['title'] . "';>";
</td>
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Untested but here is one way you could clean up your code move style and javascript (and use some jquery) into the head:
<?php
$con=mysqli_connect("localhost","root","*******","media") or die("Failed to connect to MySQL: " . mysqli_connect_error());
$result = mysqli_query($con,"SELECT * FROM movies ORDER BY `movies`.`title` ASC");
?>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('img').each(function() {
var img = $(this);
img.click(function() {
window.location="lookup.php?pattern=" + img.attr('title');
});
});
});
</script>
<style>
table {
margin: auto;
text-align: left;
background: white;
padding: 3em;
border: 2px solid #000000;
}
table tr td {
padding-right: 2em;
}
table tr td img {
width: 160px;
height: 200px;
}
</style>
</head>
<body>
<table>
<tr>
<th>Movie Title</th>
<th>Language</th>
</tr>
<?php
while($row = mysqli_fetch_array($result)) {
echo "
<tr>
<td>
<img src=\"data:image/jpeg;base64," . base64_encode( $row['image'] ) . "\" title=\"" . $row['title'] . "\">
</td>
</tr>
";
}
?>
</table>
</body>
</html>
<?php mysqli_close($con); ?>
Or if you don't want to use javascript, you could always wrap the image around the anchor tag instead:
<td>
<a href='lookup.php?pattern={$row['title']}'>
<img src=\"data:image/jpeg;base64," . base64_encode( $row['image'] ) . "\">
</a>
</td>
You could further separate PHP and HTML code:
<?php
$con=mysqli_connect("localhost","root","*******","media");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
$result = mysqli_query($con,"SELECT * FROM movies ORDER BY `movies`.`title` ASC");
?>
<table border='3' style='margin: auto; text-align: left;background: white; padding: 3em;'>
<tr>
<th><b>Movie Title</b></th>
<th><b>Language</b></th>
</tr>
<?php
while($row = mysqli_fetch_array($result)) {
$img = 'data:image/jpeg;base64,'
. base64_encode( $row['image'] );
?>
<tr>
<td style='padding-right: 2em;'>
<img src="<?php echo $img; ?>"
style="width: 160px; height: 200px;"
onclick="window.location='lookup.php?pattern=<?php echo $row['title']?>;'"
/>
</td>
</tr>
<?php } ?>
</table>
<?php
mysqli_close($con);
?>
You could also use some sort of templating engine to do this, but the results would be pretty much the same - I don't see much point in writing, say,
<strong>{{ title }}</strong>
instead of
<strong><?php echo $title; ?></strong>

keeping track of pages and mysql_num_rows

Working off my previous question I'm trying to figure out how to achieve what I'm after.
I have an order that gets made. When the time comes to print that order, if the order has more than 25 lines/rows i need to put up from line 26 and create a new page. My question is how would I write that? I was thinking with mysql_num_rows but how can I track that?
How would I break it down, say put rows 0-24 into array1 then put rows 25-49 into array2 and so on? Then put the different arrays into while loops?
Maybe put everything into an array, then split it up?
Here's what I have right now
<?php
if (isset($_POST['CheckBox'])){
$CB = $_POST['CheckBox'];
} else {echo 'Nothing Marked'; die;}
/////////////////////////////////////////
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style>
#media print{ #page{margin: 5%;} }
body{
background-color: #CCC;
margin:0;
padding:0;
}
#MainWrapper{
margin:0 auto;
width:675px;
height:900px;
background-color:#3CF;
position:relative;
}
#OrderInfo{
width:200px;
height:50px;
background-color:#6C6;
float:left;
font-family:Verdana, Geneva, sans-serif;
font-size:9px;
}
#OrderInfoNotes{
width:475px;
height:50px;
background-color:#6C6;
float:right;
font-family:Verdana, Geneva, sans-serif;
font-size:9px;
}
#LineHeader{
width:675px;
background-color:#C90;
float:left;
}
.OrderLines{
font-family:Verdana, Geneva, sans-serif;
font-size:9px;
padding:0px;
}
.PBA{page-break-after: auto;}
.bigbold{ font-weight:bold; font-size:14px;}
.bigger{font-size:14px;}
</style>
</head>
<body>
<?php
///////////////////////////////////////////
foreach ( $CB as $thekey => $Order_ID )
{
$queryOrderHead = "SELECT * FROM Orders WHERE Order_ID = ".mysql_real_escape_string($Order_ID)."";
$queryOrderLines = "SELECT * FROM Order_LineDetails WHERE Order_LineDetails.Order_ID = ".mysql_real_escape_string($Order_ID)."";
//////////////////////////////////////////
if ($queryRunHead = mysql_query($queryOrderHead)){
//////////////////////////////////////////
// THIS IS THE HEADER OF THE ORDER ///////
//////////////////////////////////////////
while ($info_HEAD = mysql_fetch_array($queryRunHead))
{
$OrderDate_HEAD = $info_HEAD['OrderDate'];
$shippingservice_HEAD = $info_HEAD['shippingservice'];
$OrderNotes_HEAD = $info_HEAD['OrderNotes'];
?>
<div id="MainWrapper">
<!--START ORDERINFO INTO -->
<div id="OrderInfo">
Order ID:<span class="bigbold"><?php echo ' '.$Order_ID; ?></span><br>
<?php echo 'SHIPPER: <span class="bigbold">'.$shippingservice_HEAD.'</span>'; ?><br>
<?php echo 'ORDER DATE: '.$OrderDate_HEAD; ?>
</div>
<div id="OrderInfoNotes">
<?php echo 'NOTES: '.$OrderNotes_HEAD; ?></div>
<!--END ORDERINFO INTO -->
<hr><br>
<div id="LineHeader">
<table class="OrderLines">
<tr class="bigbold">
<td width="300"><u>Product Name:</u></td>
<td width="90"><u>UPC Code:</u></td>
<td width="50" align="right"><u>PID:</u></td>
<td width="75" align="right"><u>QTY:</u></td>
<td width="160" align="right"><u>Packer:</u></td>
</tr>
<?php
}
/////////////////////////////////////////
// THIS IS THE ORDER LINES //////////////
/////////////////////////////////////////
$queryRunLines = mysql_query($queryOrderLines);
while ($info = mysql_fetch_array($queryRunLines))
{
$ProductName_LINE = $info['ProductName'];
$qty_LINE = $info['qty'];
$Product_ID_LINE = $info['Product_ID'];
$UPC_LINE = $info['UPC'];
?>
<tr class="bigger">
<td><?php echo $ProductName_LINE; ?></td>
<td><?php echo $UPC_LINE; ?></td>
<td align="right"><?php echo $Product_ID_LINE; ?></td>
<td align="right"><?php echo $qty_LINE; ?></td>
<td></td>
</tr><tr>
<td colspan="5"><hr></td></tr>
<?php
}
///////////////////////////////////////////////////////////
// END OF ORDER LINES /////////////////////////////////////
///////////////////////////////////////////////////////////
$numRows = 0;
$numRows = mysql_num_rows($queryRunLines);
echo 'Total Rows ('.$numRows.')'
///////////////////////////////////////////////////////////
?><tr>
<td colspan="5" class="center">--- :END: ---</td>
</tr>
</table>
</div>
</div>
<p class="PBA"/>
<?php
} else {
echo mysql_error();
}
}
mysql_close($conn);
?>
</body>
</html>
From looking at your previous question, it appears you want to print the HTML page, not use pagination. Just use a counter variable:
$i = 0;
while ($info = mysql_fetch_array($queryRunLines))
{
$ProductName_LINE = $info['ProductName'];
$qty_LINE = $info['qty'];
$Product_ID_LINE = $info['Product_ID'];
$UPC_LINE = $info['UPC'];
if (!($i % 25)) {
// echo page break every 25 lines
}
// output
$i++;
}
Also take a look at CSS attributes page-break-before/page-break-after. I would also suggest using an HTML to PDF converter. They are easy to use and will make your printed documents consistent across different systems.
What you need is called pagination.
One of the way to do it is, use LIMIT clause in your query.
I would have put up here but there are hundreds of tutorials for pagination in google with good explanation. It would be better if you search by "php pagination" and learn step by step.
you can limit the number of rows returned by your query,
add LIMIT 0, 24 at the end of your query, you will get the first 25 rows.
you can have more details here
Use a variable to store how many rows you want to display and another one to store the current rows being retrieved.
Look up pagination which will give you a better idea. It may not be exactly what you what but will teach you how to limit sql results they way you want.

Categories