简体   繁体   中英

Insert array into database in custom PHP

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.

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)

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM