$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $connection->setAttribute(PDO::ATTR_PERSISTENT, false); $connection->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8' COLLATE 'utf8'"); return $connection; } $db = Conn(); function pagine($table = 'users', $perpage = 5) { if (empty($_GET['page'])) { $page = 1; } else { $page = (int) $_GET['page']; } $pagenext = $page + 1; $pageprev = $page - 1; if ($pageprev < 0) { $pageprev = 1; } $offset = ($page - 1) * $perpage; $sql = "SELECT * FROM " . $table . " WHERE active = '1' AND admin = '0' LIMIT " . $offset . "," . $perpage; global $db; // get pdo connection Conn() $st = $db->query($sql); $row = $st->fetchAll(PDO::FETCH_ASSOC); echo '<a href="?page=' . $pageprev . '"> prev </a>'; echo '<a href="?page=' . $pagenext . '"> next </a>'; return $row; } // using and get data from mysql print_r(pagine());
$pageprev = $page - 1; if ($pageprev < 0) { $pageprev = 1; } $offset = ($page - 1) * $perpage; $sql = "SELECT * FROM " . $table . " WHERE active = '1' AND adminid = '0' ORDER BY id DESC LIMIT " . $offset . "," . $perpage; global $db; // get pdo connection Conn() $st = $db->query($sql); $row = $st->fetchAll(PDO::FETCH_ASSOC); echo '<p class="pagine"><a class="pagelink" href="?page=' . $pageprev . '"> Poprzednia</a>'; echo '<a class="pagelink"> ' . $page . ' </a>'; echo '<a class="pagelink" href="?page=' . $pagenext . '"> Nastepna</a></p>'; return $row; } $rows = pagine(); //$st = $db->query("SELECT * FROM campaning WHERE adminid = '0' AND active = '1'"); //$rows = $st->fetchALL(PDO::FETCH_ASSOC); echo '<div class="tg-wrap" style="background: #66c666"> <table id="tg-RsPwC" class="tg"> <tr style="background: #eee; color: #444"> <th class="tg1">ID</th> <th class="tg1">Link (w szablonie z https:// lub http://)</th> <th class="tg1">Miniaturka</th> <th class="tg1">Data dodania</th> <th class="tg1">Ustawienia</th> </tr>'; foreach ($rows as $v) { $host = $_SERVER['HTTP_HOST'] . "/"; $link = $v['name']; $size = getimagesize($link); $size = $size[0] . '/' . $size[1] . 'px'; $img = '<a href="' . $link . '" target="_blank"><img src="' . $link . '" width="50" height="50"></a> <br>' . $size; if (file_exists($link)) { echo '<tr> <td class="tg1">' . $v['id'] . '</td> <td class="tg1"> ' . $host . 'login/' . $link . '</td> <td class="tg1" style="text-align: center;">' . $img . '</td> <td class="tg1">' . $v['time'] . '</td> <td class="tg1"> <a class="abtn" href="?id=' . $v['id'] . '" title="Usuń"> <i class="fa fa-trash"></i></a> </td> </tr>';