Jump to content

pagination question


digitalgod

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/
Share on other sites

try[code]
<?php
mysql_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 = '&nbsp;';
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]
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-80237
Share on other sites

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 = '&nbsp;';
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]
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-82472
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-83189
Share on other sites

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 '
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-83536
Share on other sites

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 = '&nbsp;';
$z = '&nbsp;';
}
echo "<td>$y $z</td>";
echo "<td>&nbsp;</td>";
echo "<td>&nbsp;</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 do
name/nom + #  | Girl  | Guy|

again when it starts the second column... any ideas no how to do that?
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84187
Share on other sites

change to [code]if ($x < $num_records) {
  $y = mysql_result($list_result, $x, 'name');
  $z= "+" . mysql_result($list_result, $x, 'number');
  $col2 = '&nbsp;';
  $col3 = '&nbsp;';
} else {
  $y = '&nbsp;';
  $z = '&nbsp;';
  $col2 = 'Girl';
  $col3 = 'Guy';
}
echo "<td>$y $z</td>";
echo "<td>$col2</td>";
echo "<td>$col3</td>";[/code]
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84211
Share on other sites

thanks but that's not what I meant. I need the top part of the tables to display what each column is

so I have

-------------------------------------------------------------------
| name/nom + #    |  Guy  |  Girl  | name/nom + #    |  Guy  |  Girl  |
--------------------------------------------------------------------
| INFO 1              |  &nbsp;|&nbsp;|    INFO 49          |&nbsp;| &nbsp;|
----------------------------------------------------------------------

etc

sorry for the way the table looks lol, but I hope you understand what I mean.

I really appreciate your help
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84252
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84261
Share on other sites

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 = '&nbsp;';
$z = '&nbsp;';
//$promo = '&nbsp;';
}
echo "<td>$y $z </td>";
echo "<td>&nbsp;</td>";
echo "<td>&nbsp;</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]
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84267
Share on other sites

[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 = '&nbsp;';
$z = '&nbsp;';
//$promo = '&nbsp;';
}
echo "<td>$y $z </td>";
echo "<td>&nbsp;</td>";
echo "<td>&nbsp;</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 2
look previous post
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-84274
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.