JSFiddle - React, Tailwind, and code Playground

by Krzysztof Niecikowski

HTML

<?php
	
$adjacents = 4;
	
$result = $mysqli->query("SELECT * FROM webelements WHERE web='ALR' AND cat='Article'");
$total_results = $result->num_rows;
$result->close();

	/* Setup vars for query. */
	$targetpage = "moving-articles";
	$limit = 15; 								
	$page = $_GET['page'];
	if($page) 
		$start = ($page - 1) * $limit; 	
	else
		$start = 0;			
	
	/* Get data. */
	$sql = $mysqli->query("SELECT * FROM webelements WHERE web='ALR' AND cat='Article' ORDER BY id DESC LIMIT $start, $limit");


	/* Setup page vars for display. */
	if ($page == 0) $page = 1;					//if no page var is given, default to 1.
	$prev = $page - 1;							//previous page is page - 1
	$next = $page + 1;							//next page is page + 1
	$lastpage = ceil($total_results/$limit);	//lastpage is = total pages / items per page, rounded up.
	$lpm1 = $lastpage - 1;						//last page minus 1
	
	/* Draw the pagination object.	*/
	
	$pagination = "";
	if($lastpage > 1)
	{	
		$pagination .= "
		<div class='pagination'>";
		if ($page > 1) 
			$pagination.= "<a href='$targetpage/page/$prev/'>« previous</a>";
		else
			$pagination.= "<span class='disabled'>« previous</span>";	
		
		if ($lastpage < 7 + ($adjacents * 2))			{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class='current'>$counter</span>";
				else
					$pagination.= "<a href='$targetpage/page/$counter/'>$counter</a>";					
			}
		}
		
		elseif($lastpage > 5 + ($adjacents * 2))
		{
	
			if($page < 1 + ($adjacents * 2))		
			{
				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class='current'>$counter</span>";
					else
						$pagination.= "<a href='$targetpage/page/$counter/'>$counter</a>";					
				}
				$pagination.= "...";
				$pagination.= "<a href='$targetpage/page/$lpm1/'>$lpm1</a>";
				$pagination.= "<a href='$targetpage/page/$lastpage/'>$lastpage</a>";		
			}

			elseif($lastpage - ($adjacents * 2)...