digitalgod Posted August 24, 2006 Share Posted August 24, 2006 hey guys,I was wondering if it's possible to print info in an html table and if there are more than 48 cells it starts a new column?something like this-------------------------------------| || INFO 1 | INFO 49| |-------------------------------------| || INFO 2 | etc| |-------------------------------------| ||up to info 48 || |-------------------------------------and if there's more than 96 it will create a new page. Any ideas how to do that? Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/ Share on other sites More sharing options...
sasa Posted August 25, 2006 Share Posted August 25, 2006 try[code]<?phpmysql_connect("", "", "");mysql_select_db("");$result = mysql_query('Select count(*) from your_table');$num_records = mysql_result($result,0,0);$max_num_rows = 48;$max_num_columns = 2;$per_page = $max_num_columns * $max_num_rows;$total_pages = ceil($num_records / $per_page);if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; $start = ($page - 1) * $per_page;$result = mysql_query("select info from your_table limit $start, $per_page");$num_columns = ceil(mysql_num_rows($result)/$max_num_rows);$num_rows = min($max_num_rows,mysql_num_rows($result));echo "<table border=\"2\">\n";for ($r = 0; $r < $num_rows; $r++){ echo "<tr>\n"; for ($c = 0; $c < $num_columns; $c++){ $x = $c * $num_rows + $r; if ($x < $num_records) $y = mysql_result($result, $x, 'info'); else $y = ' '; echo "<td>$y</td>"; } echo "</tr>\n";}echo "</table>\n";for ($i=1;$i <= $total_pages;$i++) { if ($i == $page) echo " $i "; else echo " <a href=\"?page=$i\">$i</a> ";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-80237 Share on other sites More sharing options...
digitalgod Posted August 29, 2006 Author Share Posted August 29, 2006 ok right now this is way beyond me!!...can you please explain your code... I replaced the queries with my own and it's not working... all I get is a blank page and I really don't even know where to start...the queries need to be dynamic so I'm using $_GET and this is what I have with your code[code=php:0]if (isset($_GET['club']) && isset($_GET['date'])) {$result = mysql_query("SELECT COUNT(*) FROM listarchive WHERE date = ".$_GET['date']." AND club = ".$_GET['club']." ");$num_records = mysql_result($result,0,0);$max_num_rows = 48;$max_num_columns = 2;$per_page = $max_num_columns * $max_num_rows;$total_pages = ceil($num_records / $per_page);if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; $start = ($page - 1) * $per_page;$result = mysql_query("SELECT * FROM listarchive LIMIT $start, $per_page WHERE date = ".$_GET['date']." AND club = ".$_GET['club']."");$num_columns = ceil(mysql_num_rows($result)/$max_num_rows);$num_rows = min($max_num_rows,mysql_num_rows($result));echo "<table border=\"2\">\n";for ($r = 0; $r < $num_rows; $r++){ echo "<tr>\n"; for ($c = 0; $c < $num_columns; $c++){ $x = $c * $num_rows + $r; if ($x < $num_records) $y = mysql_result($result, $x, 'info'); else $y = ' '; echo "<td>$y</td>"; } echo "</tr>\n";}echo "</table>\n";for ($i=1;$i <= $total_pages;$i++) { if ($i == $page) echo " $i "; else echo " <a href=\"?page=$i\">$i</a> ";}[/code]date looks like 0000-00-00*edit*found out why it wasn't displaying anything... Now I get an error saying Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource for lines 279 and 280 which are:[code]<?php$num_columns = ceil(mysql_num_rows($result)/$max_num_rows);$num_rows = min($max_num_rows,mysql_num_rows($result));?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-82472 Share on other sites More sharing options...
digitalgod Posted August 30, 2006 Author Share Posted August 30, 2006 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-83186 Share on other sites More sharing options...
AdRock Posted August 30, 2006 Share Posted August 30, 2006 Here is a good tutorial for pagaination and there is also a forum for asking questions about the codehttp://www.allsyntax.com/tutorials/PHP/23/Pagination-with-PHP/1.php Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-83187 Share on other sites More sharing options...
digitalgod Posted August 30, 2006 Author Share Posted August 30, 2006 that's really not what I'm looking for, I know how to do pagination, what I don't know how to do is display information like I stated in my original post[quote author=digitalgod link=topic=105519.msg421543#msg421543 date=1156446671]hey guys,I was wondering if it's possible to print info in an html table and if there are more than 48 cells it starts a new column?something like this-------------------------------------| || INFO 1 | INFO 49| |-------------------------------------| || INFO 2 | etc| |-------------------------------------| ||up to info 48 || |-------------------------------------and if there's more than 96 it will create a new page. Any ideas how to do that?[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-83189 Share on other sites More sharing options...
sasa Posted August 31, 2006 Share Posted August 31, 2006 change line[code]$result = mysql_query("SELECT COUNT(*) FROM listarchive WHERE date = ".$_GET['date']." AND club = ".$_GET['club']." ");[/code]to[code]$result = mysql_query("SELECT COUNT(*) FROM listarchive WHERE date = '".$_GET['date']."' AND club = '".$_GET['club']."' ");[/code]add some ' Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-83536 Share on other sites More sharing options...
digitalgod Posted September 1, 2006 Author Share Posted September 1, 2006 yeah I did do that before and it worked well after that. I have another problem now, I need it to create empty cells if there isn't enough info. So if there's only 15 names it will still create 96 cells but only 15 of them will have info.. is that doable? Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-83792 Share on other sites More sharing options...
digitalgod Posted September 1, 2006 Author Share Posted September 1, 2006 ok here's what I got so far[code=php:0]$total_result = mysql_query("SELECT COUNT(*) FROM listarchive WHERE date = '".$_GET['date']."' AND club = '".$_GET['club']."' ");$num_records = mysql_result($total_result,0,0);$max_num_rows = 48;$max_num_columns = 2;$per_page = $max_num_columns * $max_num_rows;$total_pages = ceil($num_records / $per_page);if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; $start = ($page - 1) * $per_page;$list_result = mysql_query("SELECT * FROM listarchive WHERE date = '".$_GET['date']."' AND club = '".$_GET['club']."' ORDER BY name LIMIT $start, $per_page");$num_columns = ceil(mysql_num_rows($list_result)/$max_num_rows);$num_rows = min($max_num_rows,mysql_num_rows($list_result));echo "<table border=\"1\">\n";echo "<tr><td width=197><div align='center'><strong>name/nom + #</strong></div></td><td height=17 width=21><strong>Girl</strong></td><td height=17 width=21><strong>Guy</strong></td></tr>\n";for ($r = 0; $r < $max_num_rows; $r++){ echo "<tr>\n"; for ($c = 0; $c < $max_num_columns; $c++){ $x = $c * $num_rows + $r; if ($x < $num_records) { $y = mysql_result($list_result, $x, 'name'); $z= "+" . mysql_result($list_result, $x, 'number'); } else { $y = ' '; $z = ' '; } echo "<td>$y $z</td>"; echo "<td> </td>"; echo "<td> </td>"; } echo "</tr>\n"; }echo "</table>\n";for ($i=1;$i <= $total_pages;$i++) { if ($i == $page) echo "Page $i "; else echo " <a href=\"?page=$i\">$i</a> ";}[/code]so that fills up everything that doesn't have info with empty spaces but I just need it to doname/nom + # | Girl | Guy|again when it starts the second column... any ideas no how to do that? Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84187 Share on other sites More sharing options...
sasa Posted September 1, 2006 Share Posted September 1, 2006 change to [code]if ($x < $num_records) { $y = mysql_result($list_result, $x, 'name'); $z= "+" . mysql_result($list_result, $x, 'number'); $col2 = ' '; $col3 = ' ';} else { $y = ' '; $z = ' '; $col2 = 'Girl'; $col3 = 'Guy';}echo "<td>$y $z</td>";echo "<td>$col2</td>";echo "<td>$col3</td>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84211 Share on other sites More sharing options...
digitalgod Posted September 1, 2006 Author Share Posted September 1, 2006 thanks but that's not what I meant. I need the top part of the tables to display what each column isso I have -------------------------------------------------------------------| name/nom + # | Guy | Girl | name/nom + # | Guy | Girl | --------------------------------------------------------------------| INFO 1 | | | INFO 49 | | |----------------------------------------------------------------------etcsorry for the way the table looks lol, but I hope you understand what I mean.I really appreciate your help Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84252 Share on other sites More sharing options...
sasa Posted September 1, 2006 Share Posted September 1, 2006 try[code]...$num_rows = min($max_num_rows,mysql_num_rows($list_result));echo "<table border=\"1\">\n<tr>";for ($i = 0 ; $i < $max_num_columns; $i++)echo "<td width=197><div align='center'><strong>name/nom + #</strong></div></td><td height=17 width=21><strong>Girl</strong></td><td height=17 width=21><strong>Guy</strong></td>"; echo "</tr>\n";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84261 Share on other sites More sharing options...
digitalgod Posted September 1, 2006 Author Share Posted September 1, 2006 gives me the same result as what I did before... unless I'm doing something wrong[code=php:0]$num_rows = min($max_num_rows,mysql_num_rows($list_result));echo "<table class='guestlist'>\n";for ($i = 0 ; $i < $max_num_columns; $i++)echo "<tr><td width=197><div align='center'><strong>name/nom + #</strong></div></td><td height=17 width=21><img width=17 height=17 src='images/boy.jpg'></td><td height=17 width=21><img width=15 height=17 src='images/girl.jpg'></td></tr>\n";echo "</tr>\n";for ($r = 0; $r < $max_num_rows; $r++){ echo "<tr>\n"; for ($c = 0; $c < $max_num_columns; $c++){ $x = $c * $num_rows + $r; if ($x < $num_records) { $y = mysql_result($list_result, $x, 'name'); $z= "+" . mysql_result($list_result, $x, 'number'); /*$promo = mysql_result($list_result, $x, 'promo_code'); if ($promo != "") { $promo = "(".$promo.")"; }*/ } else { $y = ' '; $z = ' '; //$promo = ' '; } echo "<td>$y $z </td>"; echo "<td> </td>"; echo "<td> </td>"; } echo "</tr>\n"; }echo "</table>\n";for ($i=1;$i <= $total_pages;$i++) { if ($i == $page) echo "Page $i "; else echo " <a href=\"?page=$i\">$i</a> ";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84267 Share on other sites More sharing options...
sasa Posted September 1, 2006 Share Posted September 1, 2006 [quote author=digitalgod link=topic=105519.msg426200#msg426200 date=1157144406]gives me the same result as what I did before... unless I'm doing something wrong[code=php:0]$num_rows = min($max_num_rows,mysql_num_rows($list_result));echo "<table class='guestlist'>\n";for ($i = 0 ; $i < $max_num_columns; $i++)echo "<tr><td width=197><div align='center'><strong>name/nom + #</strong></div></td><td height=17 width=21><img width=17 height=17 src='images/boy.jpg'></td><td height=17 width=21><img width=15 height=17 src='images/girl.jpg'></td></tr>\n";echo "</tr>\n";for ($r = 0; $r < $max_num_rows; $r++){ echo "<tr>\n"; for ($c = 0; $c < $max_num_columns; $c++){ $x = $c * $num_rows + $r; if ($x < $num_records) { $y = mysql_result($list_result, $x, 'name'); $z= "+" . mysql_result($list_result, $x, 'number'); /*$promo = mysql_result($list_result, $x, 'promo_code'); if ($promo != "") { $promo = "(".$promo.")"; }*/ } else { $y = ' '; $z = ' '; //$promo = ' '; } echo "<td>$y $z </td>"; echo "<td> </td>"; echo "<td> </td>"; } echo "</tr>\n"; }echo "</table>\n";for ($i=1;$i <= $total_pages;$i++) { if ($i == $page) echo "Page $i "; else echo " <a href=\"?page=$i\">$i</a> ";}[/code][/quote]move <tr> tag from line 4 to line 2look previous post Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84274 Share on other sites More sharing options...
digitalgod Posted September 5, 2006 Author Share Posted September 5, 2006 thanks it worked perfectly!! Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-86531 Share on other sites More sharing options...
digitalgod Posted September 14, 2006 Author Share Posted September 14, 2006 got another question, would there be any way to change the code so that instead of having to click on Page 2, Page 3 etc they're all displayed at the same time and there's just a page break between them? Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-91995 Share on other sites More sharing options...
digitalgod Posted September 18, 2006 Author Share Posted September 18, 2006 anyone?? Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-94082 Share on other sites More sharing options...
HuggieBear Posted September 18, 2006 Share Posted September 18, 2006 I'm guessing this is for printing purposes, otherwise, why would you need a page break. If so, then the answer is no, you'd have to work out how many rows you have that fit on a page and pad out with <br/> tags accordingly.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-94241 Share on other sites More sharing options...
digitalgod Posted September 18, 2006 Author Share Posted September 18, 2006 well right now everything appears on different pages, if I can have them all appear on the same page that would be great but I"m not sure how to do it Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-94314 Share on other sites More sharing options...
HuggieBear Posted September 19, 2006 Share Posted September 19, 2006 You need to remove the pagination that you just put in...It shouldn't be too difficult to achieve.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-94483 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.