...

View Full Version : Paginated Data using PHP & MySQL



sjanssen
08-10-2012, 03:33 PM
Hi All,

Hoping someone can help me out with this, I have a products database and the data pulled and displayed on a paginated page..However currently the data is just listed in 3 columns "Product_Image" "Model_No" & "Product PDF", But i want to change it so it is more like a catalogue and has 3 -4 products in row rather than listing them in all in one column. The code to display the data and link to example page is below:


echo "<tr><th>Product Image</th><th>Model No</th><th>Product PDF</th></tr>";

// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }

// echo out the contents of each row into a table
echo "<tr>";
echo '<td><img src="' . mysql_result($result, $i, 'product_image') . '"/></td>';
echo '<td>' . mysql_result($result, $i, 'model_no') . '</td>';
echo "<td><a href='" . mysql_result($result, $i,'product_pdf') . "'>Product PDF Download</a></td>";

echo "</tr>";
}
// close table>
echo "</table>";

// pagination

http://upun.co.uk/UKJST.php

hope this makes sense, and appreciate any input on the matter!

Thanks,

Steve

mlseim
08-10-2012, 05:03 PM
I would probably use <div> and stylesheet (CSS) to create a widget
for each item, but you're using <table>, which is OK because you're
displaying tabular things. I didn't specify any styling for the <td>
tags (width, spacing, etc). I just wanted to see if the layout works.





echo "<tr>";
$count=0;

// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }

// echo out the contents of each row into a table
if($count==3){
echo "</tr><tr>";
$count=0;
}
$model=mysql_result($result, $i, 'model_no');
echo "<td><img src=" . mysql_result($result, $i, 'product_image') . " alt='" . $model . "' title='" . $model . "' /><br />";
echo "<b>Model: </b>" . $model . "<br />";
echo "<a href='" . mysql_result($result, $i,'product_pdf') . "'>Product PDF Download</a></td>";

$count++;
}
echo "</tr>";
// close table>
echo "</table>";

// pagination

sjanssen
08-10-2012, 11:27 PM
Hi Mlseim,

thanks for the input, it is working with an issue, have put a test page up for you to see, As you can see where the image is meant to be there is the model no again,

Any ideas? i tried a few couple adjustments but just get the image url appearing,

http://upun.co.uk/UKJST1.php


Thanks,

sjanssen
08-11-2012, 12:05 AM
managed to fix the bug mate,


echo "<tr>";
$count=0;

// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }

// echo out the contents of each row into a table
if($count==3){
echo "</tr><tr>";
$count=0;
}

$model=mysql_result($result, $i, 'model_no');
echo '<td><img src="' . mysql_result($result, $i, 'product_image') . '"/><br />';
echo "<b>Model: </b>" . $model . "<br />";
echo "<a href='" . mysql_result($result, $i,'product_pdf') . "'>Product PDF Download</a></td>";

$count++;
}
echo "</tr>";
// close table>
echo "</table>";

// pagination

many thanks again

mlseim
08-11-2012, 01:07 AM
If you make your left and right page columns narrower, and make the
middle column wider, you'll get better "white space" between items and
the model numbers would be wrapped.

My "alt" and "title" properties were supposed to create the model number in
the mouse-over "tip box" when you hover over the image. I must
have made a typo ... but a "tip box" was the intent of it.

Glad you got it working.

sjanssen
08-11-2012, 01:46 AM
yeah works fine now, thanks again, WIll work on the margins after i update the rest of the pages, making changes as i go through it but the products were the main concern as they are the biggest job of it really



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum