我正在尝试根据其他2个表中的Inner Join更新表。我的SQL查询是:
SELECT virtuemart_media_id
, virtuemart_product_id
FROM jos_virtuemart_medias m
JOIN jos_virtuemart_products p
ON SUBSTRING_INDEX(
SUBSTRING_INDEX(
SUBSTRING_INDEX(m.file_url, '/', -1)
, ".", 1)
,"-",1) = p.product_sku
WHERE 1
到目前为止我所拥有的是:
// Start database stuff
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
//Create query
$query = 'SELECT `virtuemart_media_id`, `virtuemart_product_id` FROM `jos_virtuemart_medias` INNER JOIN `jos_virtuemart_products` ON SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(`jos_virtuemart_medias`.`file_url`, "/", -1), ".", 1),"-",1) = `jos_virtuemart_products`.`product_sku`';
//Set the query
$db->setQuery($query);
$rows = $db->loadColumn();
我接下来想要做的是循环检查并检查#__virtuemart_product_medias中是否存在记录,如果没有,则插入virtuemart_product_id和virtuemart_media_id。
我似乎无法绕过循环?
提前谢谢你 娜