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.

Recommended Answers

All 6 Replies

Hi,

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

Vivek

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

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

ishu@gmail.com 3333 Array N; N;

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

Member Avatar for langsor

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;

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

Member Avatar for langsor

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 <td> 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.

...

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.