Hi here the the values which are from the table will be stored in an session....before that which is displayed with an checkbox.......but what i want to do here is i want those values which are clicked should be stored in a session and i want to display them in the next page........... help me

<?php

	include('database.php');


 $stype=$_POST['category'];
if($stype=="service_category")
   { 
	 
	 $result = mysql_query("SELECT * FROM  service_category ");
	while($row = mysql_fetch_array($result))
		{
		?><input type="Checkbox" id="a[]"  value="servicec"><?echo $row['servicec'];
		echo "<br />";
		$a[i]=$row['servicec'];
		$i++;
		$_SESSION['a1']=$a[i];
			//	echo  $_SESSION['a1'];

		}
   }

Recommended Answers

All 3 Replies

Hi,

Two things I want to tell you.
1. the code that you have written will store the last value in session variable a1.

so your code should be something like this.

while($row = mysql_fetch_array($result))		{		?><input type="Checkbox" id="a[]"  value="servicec"><?echo $row['servicec'];		echo "<br />";		$a[i]=$row['servicec'];	$i++;	
       }
      $_SESSION['a1']=$a;

2. As per your requirement, the clicking event is client side event, so you can not directly modify the array stored in session.
for that you will either need to use AJAX or you will need to post this page and then in next page you can catch the checkboxes values which were clicked on previous page.

I tried with ur code..........it will display only the last value................

<?php

	include('database.php');


 $stype=$_POST['category'];
if($stype=="service_category")
   { 
	 
	 $result = mysql_query("SELECT * FROM  service_category ");
	while($row = mysql_fetch_array($result))
		{
		?><input type="Checkbox" name="a[]" id="a[]"  value="servicec"><?//echo $row['servicec'];
		echo "<br />";
		$a[i]=$row['servicec'];
		$i++;
		//$_SESSION['a1']=$a[i];
			//	echo  $_SESSION['a1'];

		}
		$_SESSION['a1']=$a;
		$a = $_SESSION['a1']; //assign $_SESSION['array'] to $array
			foreach($a as $i) 
				{
				echo $i;
				}
   }
commented: You are still not using the [code] tags. Bad bad.. -1

Hi,
Please replace following line

$a[i]=$row['servicec'];

with

$a[$i]=$row['servicec'];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.