PHP displaying data in table 5 by 3 paginated with thumbs and other information

I am creating a website that will talk about events and nightclubs of nightclubs in a big city. Events can count hundreds. I would like the data to be displayed in a 5 by 3 table that contains thumbs and other paging information. For instance:

Thumb_event1  Thumb_event2  Thumb_event3  Thumb_event4  Thumb_event5
event_name1   event_name2   event_name3   event_name3   event_name5
Date          Date          Date          Date          Date 

Thumb_event6  Thumb_event7  Thumb_event8  Thumb_event9  Thumb_event10
event_name6   event_name7   event_name8   event_name9   event_name10
Date          Date          Date          Date          Date 

Thumb_event11 Thumb_event12 Thumb_event13 Thumb_event14 Thumb_event15
event_name11  event_name12  event_name13  event_name14  event_name1
Date          Date          Date          Date          Date5

Records 1 to 15 of 36                First    Previous   Next   Last

How can this be achieved? Any help would be appreciated. I used to do PHP code to display data in a similar way, but without pagination.

This was supposed to display some image previews just a while ago:

<?php
echo "\n<table>";
$i = 5;
while ($pictures = mysql_fetch_assoc($pictures_result))
{
if($i==5) echo "\n\t<tr>";
echo "<td width='100' height='100' align='center' valign='middle'><a href = 'picture_view.php?picture_id=$pictures[picture_id]'>
  <img src='User_Images/$pictures[picture_thumb_url]' border='0'/></a></td>\n";
$i--;
if($i==0) {
echo "\n\t</tr>\n\t<tr>";
$i = 5;
} 
}
if($i!=5) echo "\n\t\t<td colspan=\"$i\"></td>\n\t</tr>";
echo "\n</table>";
?> 

But I do not know how to make pages if I set a limit of 15 per page. Thanks in advance.

+3
source share
2 answers

, , , - :

define('ITEMS_PER_PAGE', 15);

// do a count query here
$num_items = mysql_result($result);
$num_pages = ceil($num_items / ITEMS_PER_PAGE);

$cur_page = (isset($_GET['p']) && (intval($_GET['p']) > 0)) ? intval($_GET['p']) : 1;

if ($cur_page > $num_pages)
    die('This page does not exist.');

$limit_clause = 'LIMIT '.(($cur_page - 1)*ITEMS_PER_PAGE).','.ITEMS_PER_PAGE;
// Add this to the end of your query
// YOUR QUERY GOES HERE

// YOUR THUMBNAIL CODE GOES HERE

// Now create the links
$links = array();
if ($cur_page > 1)
{
   $links[] = '<a href="page.php?p=1">First page</a>';
   $links[] = '<a href="page.php?p='.($cur_page-1).'">Previous page</a>';
}
if ($cur_page < $num_pages)
{
   $links[] = '<a href="page.php?p='.($cur_page+1).'">Next page</a>';
   $links[] = '<a href="page.php?p='.$num_pages.'">Last page</a>';
}

, , ( ) , , , ( ).

, . , .

EDIT. , LIMIT. , , , , .

+1

mysql - LIMIT. , LIMIT 10, 15 15 , 10-. LIMIT () ( GET)

+1

Source: https://habr.com/ru/post/1789993/


All Articles