www.webdeveloper.com
Results 1 to 2 of 2

Thread: HOw to use foreach for MYSQL Query

Hybrid View

  1. #1
    Join Date
    Mar 2014
    Posts
    6

    HOw to use foreach for MYSQL Query

    Hey I have a php array adn for each value of array I want to run a query and get the result.

    How I can use foreach here pls guide with some example.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    Well, the first thing I'd do is try to figure out how to do it all in one query if possible, as doing a separate query N number of times in a loop can be resource-intensive. For instance, you could build a single insert query from your array of data, since you can use this SQL format:
    Code:
    INSERT INTO table_name (
      col_1,
      col_2,
      col_3
    )
    VALUES
      ('row1_1', 'row1_2', 'row1_3'),
      ('row2_1', 'row2_2', 'row2_3'),
      ('row3_1', 'row3_2', 'row3_3')
    ;
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles