Jump to content

[SOLVED] Mass INSERT and grabbing ID from another table


acctman

Recommended Posts

I'm going to be using two tables (see below). Basically I need to access the r_members table and foreach m_id in that table, create and insert into r_messages applying the 'r_members.m_id' into r_messages.msg_recip allow with all the present field info. this is all i've come up with so far INSERT INTO r_messages ... IN ( SELECT m_id FROM r_members )

 

Table: r_members

Field: m_id (userid)

 

Table: r_messages

Fields:

msg_sender : 39

msg_recip : (userid from r_members.m_id)

msg_subj : Test

msg_text : Test Subject

msg_ip : 127.0.0.1

msg_status : 1

Link to comment
Share on other sites

if it's coming from a variable, just use mysql_real_escape_string() on it first. it will properly escape it

 

its being inserted directly into the database via phpmyadmin. i figureed the query would process a lot faster than going through http

Link to comment
Share on other sites

Ah, in that case, you just need to add a \ before it:

INSERT INTO r_messages (msg_sender,msg_recip,msg_subj,msg_text,msg_ip,msg_status) SELECT 39,m_id,'Test Subject','This isn\'t a good test message','127.0.0.1',1 FROM r_members

Link to comment
Share on other sites

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.