Jump to content

php/mysql help needed


spider2240

Recommended Posts

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 by spider2240
Link to comment
Share on other sites

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.

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.