spider2240 Posted February 28, 2015 Share Posted February 28, 2015 (edited) I am trying to insert list of items from dev.test1 table, but I am struggling with logic ... Face following problems: - Before insert statements I would like to add "if not exists" - select content from dev.qa_postmetas - f.URL which I am getting in second query is not coming from correct row in dev.test1 - If want to select f.URL where f.title = b.title INSERT INTO dev.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) LIMIT 1; INSERT INTO dev.qa_postmetas (postid, title, content) (select MAX(b.postid) , 'qa_q_extra',f.URL from dev.qa_posts b left JOIN dev.test1 as f on b.postid = f.id) LIMIT 1 ; Any assistance will be appreciated Edited February 28, 2015 by spider2240 Quote Link to comment https://forums.phpfreaks.com/topic/294972-phpmysql-help-needed/ Share on other sites More sharing options...
rwhite35 Posted February 28, 2015 Share Posted February 28, 2015 If you are using PDO or even mysqli, I would suggest turning on error reporting so you see what errors are being thrown. Take a look at this query where its doing something similar with a sub query running before insert statement. $query = "INSERT INTO gali_img ( galc_id, gali_name, gali_type, gali_display, gali_active, gali_date ) VALUES ( ( SELECT galc_id FROM galc_cat ORDER BY galc_id DESC LIMIT 1 ), :galiName, :galiType, :galiDisplay, :galiActive, :galiDate)"; Notice that the sub query is the first VALUES item. Hope that helps. BTW I'm using a PDO driver here, and the :galiName are alias binders for each field. Quote Link to comment https://forums.phpfreaks.com/topic/294972-phpmysql-help-needed/#findComment-1507088 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.