943,767 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 876
  • PHP RSS
Aug 8th, 2008
0

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

Expand Post »
Hi all,
I am storing check box values with comma separated into db like this , the code given below
php Syntax (Toggle Plain Text)
  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
php Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 7
Solved Threads: 0
Junior Poster
ishlux is offline Offline
145 posts
since Jun 2008
Aug 8th, 2008
0

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

Hi,

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

Vivek
Reputation Points: 28
Solved Threads: 19
Junior Poster
vicky_rawat is offline Offline
137 posts
since Jun 2008
Aug 8th, 2008
0

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

ok where to write unserialize and how to write unserialize method......
Reputation Points: 7
Solved Threads: 0
Junior Poster
ishlux is offline Offline
145 posts
since Jun 2008
Aug 8th, 2008
0

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

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

php Syntax (Toggle Plain Text)
  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
Reputation Points: 7
Solved Threads: 0
Junior Poster
ishlux is offline Offline
145 posts
since Jun 2008
Aug 9th, 2008
0

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

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 ...
PHP Syntax (Toggle Plain Text)
  1. $arr = mysql_fetch_row( $result );
  2. $str = implode( " ", $arr );
  3. print $str;
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 posts
since Aug 2008
Aug 11th, 2008
0

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

I used the implode function, but still its not working........................
Reputation Points: 7
Solved Threads: 0
Junior Poster
ishlux is offline Offline
145 posts
since Jun 2008
Aug 11th, 2008
0

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

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 Syntax (Toggle Plain Text)
  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.

...
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Passing Javascript integer (id) to mysql_query
Next Thread in PHP Forum Timeline: Jeet Raj ( How We CAn Genrate Barcode In Php)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC