Jump to content

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

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?
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-83792
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...
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.

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/18572-pagination-question/#findComment-94241
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.