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

Reply

Join Date: Jun 2008
Posts: 144
Reputation: ishlux is an unknown quantity at this point 
Solved Threads: 0
ishlux ishlux is offline Offline
Junior Poster

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

 
0
  #1
Aug 8th, 2008
Hi all,
I am storing check box values with comma separated into db like this , the code given below
  1. <?php
  2. include 'database.php';
  3.  
  4. $servicec = addslashes(serialize($a1));
  5. $servicet = addslashes(serialize($b1));
  6. $services = addslashes(serialize($c1));
  7.  
  8.  
  9.  
  10. $query1 = "insert into autoalto_contractor( service_category,service_type,services) values ('".$servicec."',
  11. '".$servicet."','".$services."')";

but while retrieving from the db i am not able to display it properly the code is given below
  1. <?php
  2. session_start();
  3. include('database.php');
  4. $result = mysql_query("SELECT * FROM autoalto_contractor" );
  5.  
  6. while($row = mysql_fetch_array($result))
  7. {
  8. ?>
  9. <tr>
  10. <td width="5%"></td>
  11.  
  12. <td><?echo $row['service_category'];?></td>
  13. <td><?echo $row['service_type'];?></td>
  14. <td><?echo $row['services'];?></td>
  15.  
  16. </tr>
  17. <tr>
  18. <td width="5%"></td>
  19. <td colspan="4" style="background-repeat: repeat-x;" background="images/dot.jpg" height="0" width="300"></td>
  20. </tr>
  21. <?
  22. }
  23. mysql_close();
  24. ?>


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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 133
Reputation: vicky_rawat is an unknown quantity at this point 
Solved Threads: 17
vicky_rawat's Avatar
vicky_rawat vicky_rawat is offline Offline
Junior Poster

Re: Storing checkbox values.............

 
0
  #2
Aug 8th, 2008
Hi,

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

Vivek
Vivek Rawat
Keep solving complexities.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 144
Reputation: ishlux is an unknown quantity at this point 
Solved Threads: 0
ishlux ishlux is offline Offline
Junior Poster

Re: Storing checkbox values.............

 
0
  #3
Aug 8th, 2008
ok where to write unserialize and how to write unserialize method......
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 144
Reputation: ishlux is an unknown quantity at this point 
Solved Threads: 0
ishlux ishlux is offline Offline
Junior Poster

Re: Storing checkbox values.............urgent plz help me

 
0
  #4
Aug 8th, 2008
Hi all,
i used unserialize method but its displaying like this

  1. <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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: Storing checkbox values.............

 
0
  #5
Aug 9th, 2008
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 ...
  1. $arr = mysql_fetch_row( $result );
  2. $str = implode( " ", $arr );
  3. print $str;
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 144
Reputation: ishlux is an unknown quantity at this point 
Solved Threads: 0
ishlux ishlux is offline Offline
Junior Poster

Re: Storing checkbox values.............

 
0
  #6
Aug 11th, 2008
I used the implode function, but still its not working........................
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: Storing checkbox values.............

 
0
  #7
Aug 11th, 2008
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 ...

  1. <?php
  2. session_start();
  3. include('database.php');
  4. $result = mysql_query( "SELECT * FROM autoalto_contractor" );
  5.  
  6. while( $row = mysql_fetch_array( $result ) ) {
  7. $service_category = unserialize( $row['service_category'] );
  8. $service_type = unserialize( $row['service_type'] );
  9. $services = unserialize( $row['services'] );
  10.  
  11. print <<<endline
  12. <tr>
  13. <td width="5%"></td><!--??? WHY THIS width="5%" ???-->
  14. <td>$service_category</td>
  15. <td>$service_type</td>
  16. <td>$services</td>
  17. </tr>
  18. <tr>
  19. <td width="5%"></td><!--??? colspan="3" below ???-->
  20. <td colspan="4" style="background-repeat: repeat-x;" background="images/dot.jpg" height="0" width="300"></td>
  21. </tr>
  22. endline;
  23. }
  24. mysql_close();
  25. ?>

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

...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC