Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6706415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:31:04+00:00 2026-05-26T07:31:04+00:00

I got an array inside a php programm that looks like this: $db=Array (

  • 0

I got an array inside a php programm that looks like this:

$db=Array ( [1] => 1 [2] => 2 [3] => 2 [4] => 2 [5] => 3 [6] => 4 [7] => 4 [8] => 5 );

It is an associative array, and I want to store it in my mysql database with this structure:

id  date    fd1     fd2     fd3     fd4     fd5     fd6     fd7     fd8

mysql_query("INSERT INTO table2 (date) VALUES(NOW(),'$db')");

id is set to AUTO_INCREASE and NOW() stores the date for every entry

But my main problem is how to assign array field [1] to fd1 column and post “value” in it

Any Help appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:31:04+00:00Added an answer on May 26, 2026 at 7:31 am
    $sql_fields = 'date';
    $sql_values = 'NOW()';
    for ($i=1; $i<=8; $i++) {
        $sql_fields .= ',fd'.$i;
        $sql_values .= ','.$db[$i];
    }
    $sql = 'INSERT INTO `table2` ('.$sql_fields.') VALUES ('.$sql_values.')';
    mysql_query($sql);
    

    EDIT:

    there’s no impact for speed here. you can also use implode instead

    // create fdX list
    $fields = array_map(function($v){return '`fd'.($v++).'`';}, range(1,8));
    // the sql query
    $sql = 'INSERT INTO `table2` 
        (`date`,'.implode(',',$fields).') VALUES (NOW(),'.implode(',',$db).')';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an associative array in php that I want to stick into a
I am creating a json array in PHP like this (it's inside a class):
I've got a form which looks like that: <form method=post enctype=multipart/form-data onsubmit=return new_post_form_submit();> <input
I've got a PHP database class which connects to MySQL and wraps up all
Say I've got this array: MyArray(0)=aaa MyArray(1)=bbb MyArray(2)=aaa Is there a .net function which
If I've got an array of values that are basically zero-padded string representations of
I've got an array with data from a MySQL table in nested set model
i have have got an array of the complexe sort to store my navigation
I've got an array of 10 frogs, and only one jumps. I want them
I've got an array with items, and I want to pass these in to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.