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 7753799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:08:37+00:00 2026-06-01T12:08:37+00:00

I have two arrays: name – facebook,google,yahoo url – facebook.com,google.com,yahoo.com In my database, I

  • 0

I have two arrays:

name - facebook,google,yahoo
url - facebook.com,google.com,yahoo.com

In my database, I have a table (tbl_websites).
structure : id, site_name, site_url

I want to insert the data from those two arrays into a single row in that table.

example:
(row 1)

id : 1
site_name : facebook
site_url : facebook.com

(row 2)

id : 2
site_name : google
site_url : google.com

(row 3)

id : 3
site_name : yahoo
site_url : yahoo.com

How do I do that?

Any help will be 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-06-01T12:08:39+00:00Added an answer on June 1, 2026 at 12:08 pm

    Assuming there is a direct 1:1 match between the arrays, you can simply loop over one of them as in:

    foreach ($name as $key => $value) {
      $name_value = mysql_real_escape_string($value);
      $url_value = mysql_real_escape_string($url[$key]);
    
      // Addendum: If there was a third array, just use `$key` as the array key
      // same as done with $url[$key]
      $thrid_value = mysql_real_escape_string($third_arr[$key]);
    
      $result = mysql_query("INSERT INTO tbl_websites (site_name, site_url, third_value) VALUES ('$name_value', '$url_value', '$third_value')");
    }
    

    This assumes the id is an auto-increment value. I have, for simplicity brevity, used the mysql_query() function here. But it is recommended to use a prepared statement via an api like PDO instead. The process of retrieving them from the arrays is the same.

    PDO version (assumes connection already made in $db):

    foreach ($name as $key => $value) {   
      $stmt = $db->prepare("INSERT INTO tbl_websites (site_name, site_url) VALUES (:name, :url)");
      $stmt->execute(array(':name' => $name_value, ':url' => $url_value));
    }
    

    The code above doesn’t include any error checking. Read the PDO manual for examples on error checking with a PDO statement. It can be done either with a try/catch exception block or with PHP warnings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays with following structure: $arr1 = array( array( name => name1,
I have two arrays. One contains id=>count and the other contains id=>name . I'm
I have two arrays like this: $array1 = [ [10, 'Some Name..'], [11, 'Some
I have two arrays idxListResponse & _index both of which have the same structure.
I have this two arrays: $arr1=array( array(id => 8, name => test1), array(id =>
I have two json arrays like var json1 = [{id:1, name: 'xxx' ...}] var
I have two arrays they look like $a1 = array( array('num' => 1, 'name'
I have two arrays... $arr1 = array( 'name', 'date' => array('default' => '2009-06-13', 'format'
I currently have two arrays one the stores a file name and another that
I have two PHP arrays. One contains a group name and another contains a

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.