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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.