0

After lots of searching and failing after trying.. i am posting this question here..

After half part of my actual query [here][1] i am not able to save the resulting array of arrays to the database..

Initially i had an array of inputs which i turned into array of arrays of inputs now my save function looks something like this

function store()
{
        foreach($post['cats'] as $cat)  {

        $query = 'insert into #__joomd_item_cat values('.$cat.', '.$row->id.')';
        $this->_db->setQuery( $query );

        if(!$this->_db->query())    {
            $obj->error = $this->_db->getErrorMsg();
            return $obj;
        }

    }
}

now, how do i modify it to get my array of arrays into database..

This function is triggered by a serialized method.. so please recheck your answers and comments

function save(task) {
var data = $jd("form[name='<?php echo $array['editform']; ?>']").serializeArray();
    $jd.ajax({
          url: "<?php echo $url; ?>",
          type: "POST",
          dataType:"json",
          data: data,
          beforeSend: function()    {
            $jd(".poploadingbox").show();
          },
          complete: function()  {
            $jd(".poploadingbox").hide();
          },
          success: function(res)    {

            savesuccess(res);

          },
          error: function(jqXHR, textStatus, errorThrown)   {
            alert(textStatus);                 
          }
    }); 

}

  [1]: http://stackoverflow.com/questions/11583375/add-input-fields-dynamically-but-fields-are-generated-by-external-php-functions/11583597#11583597
harry
  • 220
  • 4
  • 15
  • 2
    The easy way is to serialize (see `serialize()`, http://php.net/serialize) your array and save that, but it limits your ability to manipulate the data in the database. – El Yobo Jul 20 '12 at 19:52
  • all i can figure out is use the function serialize() which cab be used like type:serialize($_POST); in ajax in the sending function, but retrieval is still not clear.. To save them i still need an array, which all confuses me.. Can you help – harry Jul 21 '12 at 04:59

1 Answers1

3

You can serialize() it and then unserialize() it upon retrieval.

John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Being a learner of the basics, all i can figure out is use the function serialize() which cab be used like `type:serialize($_POST);` in ajax in the sending function, but retrieval is still not clear.. To save them i still need an array, which all confuses me – harry Jul 20 '12 at 20:21
  • Am sorry, the things were already serialized, now how would you want me to proceed.. – harry Jul 22 '12 at 12:41