Salve, come posso fare una cosa del genere? .. Vorrei che quando digito users.php senza il parametro mi visualizza tutti i record che ci sono nell'archivio dati e invece quando c'è users.php?ruolo=1 ..
mi deve visualizzare tutti quelli che hanno il ruolo 1.
vi posto il codice:
cosa devo fare?
grazie mille, e volevo avvisare che non lo scritta io.. ma lo presa su internet "stackoverflow".codice:<?phpsession_start(); include("inc.php"); include("admin.php"); include("layout/template.php"); layout_header(); ?> <?php try { $ruolo = (isset($_GET['ruolo'])) ? trim($_GET['ruolo']) : ''; $total = $db->query(' SELECT COUNT(*) FROM users')->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); // Prepare the paged query $stmt = $db->prepare(' SELECT * FROM users ORDER BY _update LIMIT :limit OFFSET :offset '); // 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"]."";?>">Cancella Tutto</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(); ?>
aspetto risposte.

Rispondi quotando