Jump to content

display the values of the checkbox


kat32

Recommended Posts

When I click the submit button, I want to display the values of the checkbox that I checked in all pages. How do I modify this to work to remember what was checked on all pages.. Thanks

<?php
session_start();
include 'dbconnect.php';
$_SESSION['checked_uid'] = array();
if($_POST['submit']){
     $checkedboxes = '';
     foreach($_POST['cbox'] as $checkedid){
          $checkedboxes .= $checkedid.',';
     }
     //$_SESSION['checked_uid'] = implode(rtrim($checkedboxes,','));
 $_SESSION['checked_uid'] = substr($checkedboxes, 0, strlen( $checkedboxes ) - 1 );
}
if(isset($_GET['p'])){
	if($_GET['p'])
		$page = $_GET['p'];			
	}
else
	$page = 1;
$q = mysql_query("SELECT * FROM tblusers");
$rows = mysql_num_rows($q);
$posts_per_page=20;
$pages = ceil($rows / $posts_per_page);

$offset = $page * $posts_per_page - $posts_per_page;?>
<form method="post" name="frm1" action="<? echo $_SERVER['PHP_SELF'];?>"><?php
$query = mysql_query("SELECT * FROM tblusers LIMIT $posts_per_page OFFSET $offset") or die(mysql_error());
while($d = mysql_fetch_object($query)){
	$uid=$d->uid;
	$username=$d->username;

        $checked = (in_array($uid,$_SESSION['checked_uid'])) ? 1 : 0;
	echo $username.' ';
?>
	<input type="checkbox" name="cbox[]"  value="<?php echo $uid; ?>" <?php echo $checked ? 'checked' : '' ?> >
    	<br /><?php
}

if($page > 1 ){
    	echo 'Pages:';
}
    if($page > 1)
        echo '<a href="?p=' . ($page - 1) . '"></a> ';
    else
        echo '';

    for($a = 1; $a <= $pages; $a++)
        if($a == $page)
            echo "$a ";
        else
            echo '<a href="?p=' . $a . '">' . $a . '</a> ';

    if($page < $pages)
        echo '<a href="?p=' . ($page + 1) . '"></a>';
    else
        echo '';

    echo '</p>';
?>
<input type="submit" name="submit"></form>

Link to comment
https://forums.phpfreaks.com/topic/171868-display-the-values-of-the-checkbox/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.