954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Storing checkbox values.............

Hi all,
I am storing check box values with comma separated into db like this , the code given below

<?php 	
	include 'database.php';

$servicec = addslashes(serialize($a1)); 
$servicet = addslashes(serialize($b1)); 
$services = addslashes(serialize($c1)); 
		 


$query1 = "insert into autoalto_contractor( 	service_category,service_type,services) values ('".$servicec."',
'".$servicet."','".$services."')";


but while retrieving from the db i am not able to display it properly the code is given below

<?php
session_start();
include('database.php');
$result = mysql_query("SELECT * FROM  autoalto_contractor" );
	
while($row = mysql_fetch_array($result))
 {
	?>
	<tr>
		<td width="5%"></td>
				
		<td><?echo $row['service_category'];?></td>
		<td><?echo $row['service_type'];?></td>
		<td><?echo $row['services'];?></td>

	</tr>
	<tr>
		<td width="5%"></td>			
		<td colspan="4" style="background-repeat: repeat-x;" background="images/dot.jpg" height="0" width="300"></td>
	</tr>
	<?		
}
mysql_close();
?>

its giving the o/p like this

a:3:{i:0;s:18:"vehicle Inspection";i:1;s:14:"batteryservice";i:2;s:10:"oil canhge}
i want only vehicle inspection , battery service like this...........can anybody help me pls...........i am trying this from long time.

ishlux
Junior Poster
145 posts since Jun 2008
Reputation Points: 7
Solved Threads: 0
 

Hi,

I think you will need to unserialize the values after retrieving them from db.

Vivek

vicky_rawat
Junior Poster
137 posts since Jun 2008
Reputation Points: 28
Solved Threads: 19
 

ok where to write unserialize and how to write unserialize method......

ishlux
Junior Poster
145 posts since Jun 2008
Reputation Points: 7
Solved Threads: 0
 

Hi all,
i used unserialize method but its displaying like this

<td><?echo unserialize($row['service_category']);?></td>

o/p is
emailId zipcode service_category service_type services

[email]ishu@gmail.com[/email] 3333 Array N; N;

Instead displaying value its displaying Array so what to do now..........pls help me

ishlux
Junior Poster
145 posts since Jun 2008
Reputation Points: 7
Solved Threads: 0
 

If you are using mysql_fetch_row it returns your data as an array ... thus the array in your output.

You should manage your database output before writing it to the html page.
Something like this ...

$arr = mysql_fetch_row( $result );
$str = implode( " ", $arr );
print $str;
langsor
Posting Whiz
390 posts since Aug 2008
Reputation Points: 30
Solved Threads: 36
 

I used the implode function, but still its not working........................

ishlux
Junior Poster
145 posts since Jun 2008
Reputation Points: 7
Solved Threads: 0
 

You don't really say what is not working, or how?
I'm assuming your database query is giving you results,
That the results have been serialized as demonstrated above,
And you're just still having trouble unserializing the results and getting them into your fields ...

<?php
session_start();
include('database.php');
$result = mysql_query( "SELECT * FROM  autoalto_contractor"  );

while( $row = mysql_fetch_array( $result ) ) {
  $service_category = unserialize( $row['service_category'] );
  $service_type = unserialize( $row['service_type'] );
  $services = unserialize( $row['services'] );

print <<<endline
  <tr>
    <td width="5%"></td><!--??? WHY THIS width="5%" ???-->
    <td>$service_category</td>
    <td>$service_type</td>
    <td>$services</td>
  </tr>
  <tr>
    <td width="5%"></td><!--??? colspan="3" below ???-->
    <td colspan="4" style="background-repeat: repeat-x;" background="images/dot.jpg" height="0" width="300"></td>
  </tr>
endline;
}
mysql_close();
?>


If the above doesn't work you will need to be more specific about what the results you are getting are.

...

langsor
Posting Whiz
390 posts since Aug 2008
Reputation Points: 30
Solved Threads: 36
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You