I wanted to know if there was a way to do an IF ELSE statement within SQL syntax or if someone could help me with CASE. Basically if a file name (string) is found in the file_url column then change where I want to use secondary information. I hope my example can help further explain what I am trying to do.
$sql = "SELECT vm.file_url FROM #__virtuemart_medias AS vm
INNER JOIN #__virtuemart_product_medias AS pm ON vm.virtuemart_media_id = pm.virtuemart_media_id
WHERE pm.virtuemart_product_id = {$product_id} ";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$FILEURL = $row["vm.file_url"];
if ($FILEURL == "thumb_phone01.jpg"){
$sql .= "AND pm.ordering = 2";
}
else {
$sql .= "AND pm.ordering = 1";
}
$this->_db->setQuery($sql);
$img = $this->_db->LoadResult();
return $img;
}
Thank you.
One option would be to use CASE and REGEXP:
Here is the SQL Fiddle.
Good luck.