...

View Full Version : breaking up data when displaying on web page [ was Is This Possible? ]



sammy
08-03-2006, 05:38 AM
I have a database with one table which includes all the data I need to display on my site. I want to display that data in multiple tables with spaces (a space where html can be added ) in between say every 10 data entries on my site. So I will have say a table displaying the first up to the 10th data entry in my database then a break for ads then continuing to the 11th to 20th data entry then a break for ads etc etc...I want to display say 5 tables of data per page (so 50 data entries, 10 per table, per page). I also need to add pagination because I will have around 300 data entries and need to break it up 50 per page (again 5 tables per page, 10 data entries per table, with spaces between tables where html can be placed) until the last table on the last page displays the last 10 data entries. All of this data will be updated often and changing however the number of data entries will not (say 300 all together). Any help will be much much appreciated, I am very desperate for a solution..Thank you!

raf
08-03-2006, 07:42 AM
welcome here!


I want to display that data in multiple tables with spaces (a space where html can be added ) in between say every 10 data entries on my site
that's easy in most server side languaes. if you will be using php, then you can use the modulus for that. like


$i = 1
while($row = mysql_fetch_assoc($result)){
if (($i % 10) == '0'){
echo '<br />';
}
// display row
}


for the pagination --> run a google or search on the php forum. a few million read made examplecodes and tutorials should pop up.

vinyl-junkie
08-03-2006, 01:27 PM
Just one small correction, raf. This line:


if (($i % 10) == '0'){
should lose the quotes around the zero.


if (($i % 10) == 0){

raf
08-03-2006, 03:06 PM
Just one small correction, raf. This line:


if (($i % 10) == '0'){
should lose the quotes around the zero.


if (($i % 10) == 0){
no, it doesn't need correcting. try it out:


$i = 10;
if ($i % 10) == '0'){
echo '<br />quotes around the 0 are OK';
}
if ($i % 10) == 0){
echo '<br />no quotes around the 0 is OK';
}

will print:
quotes around the 0 are OK
no quotes around the 0 is OK

i think you are confusing == with === because
== '0' evaluates the same as == 0 whereas
=== '0' does not evaluate the same as === 0
if ($i % 10) === '0'){ would be incorrect

and besides, that code is just typed in quickly without rereading. so there are enough things wrong with it


$i = 1

should be


$i = 1 ;

and inside the while loop, i should increment $i so you'll need to add


$i ++;


maybe i should include a disclaimer: all code is typed in haste without being reread, lett alone debugged :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum