php assistance needed

I have 3 tables

TABLE 1 COLUMNS:

`test1`(`id`, `title`, `URL`, `img`, `tagsv`

Open in new window


TABLE 2 COLUMNS:

qa_posts (type, categoryid, userid, created, title, content, tags)

Open in new window


TABLE 3 COLUMNS:

qa_postmetas (postid, title, content) 

Open in new window


- I am looking for php script which will get data from table 1
- if TABLE 1 content column value doesn't exist in qa_postmetas
THEN
- INSERT (recursively)
INSERT INTO qa_posts (type, categoryid, userid, created, title, content, tags) 
(SELECT  'Q_QUEUED', '1', '3', NOW(), f.title, f.img, f.tagsv 
FROM dev.test1 f) 

Open in new window

and then
- GET inserted postid from qa_posts and insert values from table1 in table 3

qa_postmetas (postid <-- (this is what we have just inserted in first insert),
 title, <-- this is hard coded value 'qa_q_extra'
content <-- this is coming from table 1 (URL column)
) )
LVL 5
CalmSoulAsked:
Who is Participating?
 
AielloJCommented:
CalmSoul:

The column names on test1 table have been truncated.  Can you please post all the columns.  Also, can you provide a rough estimate of how many rows you expect this query to fetch and insert?

Best regards,

AielloJ
0
 
Ludwig DiehlSystems ArchitectCommented:
I supposed you are talking about database tables, if so, then what kind of database ? (MySQL, MSSQL, Postgresql, etc).
Please give us more information
0
 
CalmSoulAuthor Commented:
I am using MYSQL

thanks
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
arnoldCommented:
Are you trying to correct a structural error in the database?
i.e. you have interdependent tables but data was entered in a way that did not maintain relational integrity?

You can simply use PHP in a recursive loop retriving data from one table, running selects on the other and when no response, running the insets.  Before you go down this road, I would suggest you make sure your table definitions/constraints/relationships/triggers as well as what inserts/updates these corrected and are setup to maintain data integrity or you will have to repeat this process on a regular basis and have conditions such that data retrieved might be suspect at any point in time.
0
 
Ray PaseurCommented:
If you're new to PHP and MySQL, this article can help you find some good "getting started" resources.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0
 
AielloJCommented:
CalmSoul:

Is this a one-time maintenance operation, or something that will be used on a regular basis? Does it have to be implemented in PHP code recursively? It may be able to be done using a moderately complex SQL query, eliminating coding, debugging, and maintenance.

Regards,

Aielloj
0
 
CalmSoulAuthor Commented:
its one time ...
0
 
AielloJCommented:
CalmSoul:

Thank you for the information.  Can you provide just a bit of detail of why this is needed?  I'm trying to find out if this is unexpected data population due to a data model error, upgrade to an existing system, etc.  If it's due to any type of error, you would do well to address them as per Arnold's earlier post.

I'll look into whether this can be done with a query.

Best regards,

AielloJ
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.