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
Link to comment
https://forums.phpfreaks.com/topic/294972-phpmysql-help-needed/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.