ripropongo il mio codice.. ora il mio codice attuale e cosi:
codice:
<?php
session_start();
include("inc.php");
include("admin.php");
include("layout/template.php");
layout_header();
?>
<?php
try {
$ruolo = (isset($_GET['ruolo'])) ? trim($_GET['ruolo']) : '';
if(empty($ruolo))
{
$total = $db->query('
SELECT
COUNT(*)
FROM
users')->fetchColumn();
}else
{
$total = $db->query('
SELECT
COUNT(*)
FROM
users where level_access='.$ruolo.'')->fetchColumn();
}
// How many items to list per page
$limit = 1;
// How many pages will there be
$pages = ceil($total / $limit);
// What page are we currently on?
$page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
'options' => array(
'default' => 1,
'min_range' => 1,
),
)));
// Calculate the offset for the query
$offset = ($page - 1) * $limit;
// Some information to display to the user
$start = $offset + 1;
$end = min(($offset + $limit), $total);
if(empty($ruolo))
{
// Prepare the paged query
$stmt = $db->prepare('
SELECT
*
FROM
users
ORDER BY
_update
LIMIT
:limit
OFFSET
:offset
');
}
else
{
$stmt = $db->prepare('
SELECT
*
FROM
users
where level_access=:level_access
ORDER BY
_update
LIMIT
:limit
OFFSET
:offset
');
$stmt->bindParam(':level_access', $ruolo, PDO::PARAM_INT);
}
// Bind the query params
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
$stmt->execute();
// Do we have any results?
if ($stmt->rowCount() > 0) {
// Define how we want to fetch the results
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$iterator = new IteratorIterator($stmt);
// Display the results
?>
<table class="table">
<tbody>
<tr>
<th>Username</th>
<th>Nome</th>
<th>Cognome</th>
<th>Email</th>
<th>Modifica</th>
<th>Svuota</th>
<th>Cancella</th>
</tr>
<?php
foreach ($iterator as $row) {
?>
<td><?php echo "".$row["username"]."";?></td>
<td><?php echo "".$row["name"]."";?></td>
<td><?php echo "".$row["firstname"]."";?></td>
<td><?php echo "".$row["email"]."";?></td>
<td><a href="users_edit.php?id=<?php echo "".$row["id"]."";?>">Profilo</a></td>
<td><a href="users_del.php?id=<?php echo "".$row["id"]."";?>">Svuota</a></td>
<td><a href="users_del_all.php?id=<?php echo "".$row["id"]."";?>">Del</a></td>
<?php
}
?>
</table>
<?php
} else {
echo '<p>No results could be displayed.</p>';
}
echo '<div align="center">';
// The "back" link
$prevlink = ($page > 1) ? '<a href="?ruolo='.$ruolo.'&page=1" title="First page">«</a> <a href="?ruolo='.$ruolo.'&page=' . ($page - 1) . '" title="Previous page">‹</a>' : '<span class="disabled">«</span> <span class="disabled">‹</span>';
// The "forward" link
$nextlink = ($page < $pages) ? '<a href="?ruolo='.$ruolo.'&page=' . ($page + 1) . '" title="Next page">›</a> <a href="?ruolo='.$ruolo.'&page=' . $pages . '" title="Last page">»</a>' : '<span class="disabled">›</span> <span class="disabled">»</span>';
// Display the paging information
echo '<div id="paging"><p>', $prevlink, ' Page ', $page, ' of ', $pages, ' pages, displaying ', $start, '-', $end, ' of ', $total, ' results ', $nextlink, ' </p></div>';
echo '</div>';
} catch (Exception $e) {
echo '<p>', $e->getMessage(), '</p>';
}
?>
<?php
layout_footer();
?>
idea?
ora funziona se ci sono i dati , ma senza dati: da errore:
codice:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1' at line 12
grazie..per l'aiuto.