0

This is my array and I want to insert it in PostgreSQL table in PHP custom. I don't know how to do this.

Array

(
    [yearlyno] => Array
        (
            [0] => 999
            [1] => 22
        )

    [mothername] => Array
        (
            [0] => rabia
            [1] => alia
        )

    [husbandname] => Array
        (
            [0] => dan
            [1] => ali
        )

    [mothersage] => Array
        (
            [0] => 22
            [1] => 45
        )

)

I have searched but could not find any solution.

Please help! I am beginner in PHP.

3
  • what kind of issue are you facing while inserting the record in db? Commented Nov 22, 2017 at 5:40
  • not sure about pgsql, but how about having a seperate table for this. This may now seem small set of data but can grow bigger. create a table people_table with array keys as columns (mothername etc) Commented Nov 22, 2017 at 5:48
  • You can use pg_insert docs here. Or convert it in postgresql array (example) Commented Nov 22, 2017 at 6:28

3 Answers 3

0

use while loop and echo $cmdrr [] with DB name in a array

while($cmdrr=$dbf->returnDBarray("psql",$_cmdresult)){
  ?>
 <tr>
  <td><?php echo $cmdrr['yearlynumber']; ?></td>
     <td><?php echo $cmdrr['mothername']; ?></td>
     <td><?php echo $cmdrr['husbandname']; ?></td>
     <td><?php echo $cmdrr['mothersage']; ?></td>
Sign up to request clarification or add additional context in comments.

Comments

0

Use implode(). This will convert your array in string, or You can convert it in JSON also by json_encode().

Examples

Implode - implode($your_array);
JSON    - json_encode($your_array)

Comments

0

You have 2 options here. Either use serialize() or json_encode() And while retrieving data, you should use unserialize() or json_decode() respectively.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.