unserialize query results not working - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: unserialize query results not working (/showthread.php?tid=5281) Pages:
1
2
|
unserialize query results not working - El Forum - 01-15-2008 [eluser]exodus7[/eluser] I seem to be having some trouble using unserialize in my view. When I use the following code, im getting a blank list generated with no data :ahhh: If I change unserialize to a simple echo statement, it displays the serialized data fine. Anyone have an idea? Controller: Code: $this->surveymodel->q15($_POST); Code: function q15() Code: <ol> Thank you unserialize query results not working - El Forum - 01-15-2008 [eluser]eggshape[/eluser] Hi - you don't need to use unserialize() because you haven't serialized the results. Just echo the field: Code: echo '<li>' . $row->q15 . '</li>'; I think your confusion is that you think view() serializes your $data array? It does not. unserialize query results not working - El Forum - 01-15-2008 [eluser]exodus7[/eluser] eggshape: Thanks for your response. What I did i was serialize an array (checkboxes) and stored the serialized data in my database using the "insert_entry" function in my model (SEE bottom). When viewing the results using the survey_results function in my controller is when im trying to unserialize the serialized data from the database. Here's a more detailed view: Controller: Code: <?php Model: Code: <? Code: <ol> unserialize query results not working - El Forum - 01-15-2008 [eluser]eggshape[/eluser] Hey exodus; Sorry, I didn't properly read your code. I think if you read the manual concerning passing objects to the view function, it says the object gets converted to an array. So perhaps this will work: Code: <? unserialize query results not working - El Forum - 01-15-2008 [eluser]exodus7[/eluser] I gave that a shot and I'm getting a fatal error: "Fatal error: Cannot use object of type stdClass as array" - line 331 line 331 is in the view file which shows: Code: unserialize($row['q15']); unserialize query results not working - El Forum - 01-15-2008 [eluser]eggshape[/eluser] EDIT: Hmm. That error seems to indicate that $row is still an object, which confuses me a bit in light of the manual. If $row is still an object and you want to keep your original q15() method: Code: <?php foreach ($q15 as $row) Oh man...am I totally confusing you or what?! =) unserialize query results not working - El Forum - 01-15-2008 [eluser]exodus7[/eluser] I gave that a shot as well and got a new error: Call to undefined function unshift() So I figured you might of wanted to use array_unshift instead but when I use array_unshift I'm getting this error: Wrong parameter count for array_unshift() unserialize query results not working - El Forum - 01-15-2008 [eluser]eggshape[/eluser] I tried using 'return $query->result()' and then '$row->id' in one of my apps and it works. I looked at the view() method code, and it does convert an object to an array. *BUT* (duh) $this->db->result() returns an ARRAY of objects...so the objects are still objects, and there is no conversion. EDIT: CI is complicated, eh? . you're right, sometimes i use unshift/pop by accident since i used to write in perl. unserialize query results not working - El Forum - 01-15-2008 [eluser]exodus7[/eluser] considering I have less than 6 months of php experience and about 2 months of CI experience, its not easy :-) In any case, I've been doing some searching online to see how others do it, and I found in some postings that others use implode to store data, which stores the values separated by a separator of your choice, and then use explode when you want to separate the values, is that right? Thanks for the help eggshape unserialize query results not working - El Forum - 01-15-2008 [eluser]eggshape[/eluser] yeah...that's pretty much what i do too, but i don't see a problem with your method. there's almost always more than one way to do it. perhaps in your original code when you wrote [code] echo '<li>'; unserialize($row->q15); echo '<li>'; [code] it didn't work because (1) you're dealing with an array after unserialization and (2) there's no 'echo' call, so you didn't even get the output 'array(#number of items)'. sure, no problem. i hope i didn't confuse you that much. try to see if you can get your method to work. |