Jump to content

Recommended Posts

Hi,

 

Here is an extract of my while loop

 

while ($personquery = mysql_fetch_array($personfetch, MYSQL_ASSOC))
          {
           
          echo "$personfetch[first_name]";
} 

 

This will list each person now I want to do an INSERT to the database on every single member that is being listed I can only get it to INSERT for the one.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/226988-mysql-query-insert-in-while-loop/
Share on other sites

For each person that is echoed I want them to be inserted into members tables. I tried doing

 

mysql_query ("INSERT INTO `current_members` (`id`, `membername`) 
VALUES
('', '$personfetch[first_name]') ");

 

Although this simply inserts just the first name and not all of the list. Hope this is clearer

EDIT: Maq beat me to it, but I'll post this anyway

=====================================

 

As Maq insinuated you don't need to pull records using a SQL statement just to insert them in another table. You can do everything with a single query. Just use the first query (which you don't show) to generate the values for the select statement. Also, since I assume id is an auto-increment row you do not need to include it in the INSERT query.

 

$query = "INSERT INTO `current_members` (`membername`)
          SELECT first_name FROM sometable";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.