the following shows two SQL queries, one is always done, the other, is dependent on a value from the first, i am not, however an SQL guru yet, but I think that there is a way to join the two queries into one, thus eliminating the need for a lot of this code.
Keep in mind that the query would need to work in any instance, from my reading so far, would this be a left join? the problem is that the two queries are from the same table.
//Here is the first SQL Query - in it's context it will only ever return 1 record
$sSelect = "SELECT * ";
$sFrom = "FROM ".$aConfiguration['TABLES']['categories']." ";
$sWhere = "WHERE blogc_id = '".$_POST['blogc_id']."'";
$sSql = $sSelect.$sFrom.$sWhere;
${"r".$aConfiguration['TABLES']['categories']} = $oBlog->oDB->query($sSql);
//Turn that record into an array
$aCategoryInfo = $oBlog->oDB->fetch_array(${"r".$aConfiguration['TABLES']['categories']});
//If the parent ID field is greater than or equal to one, then perform a duplicate query simply to get the name of the parent ID
if ($aCategoryInfo['blogc_pid'] >= 1) {
//Second SQL Query - Also will only return one record
$sSelect = "SELECT blogc_name ";
$sFrom = "FROM ".$aConfiguration['TABLES']['categories']." ";
$sWhere = "WHERE blogc_id = '".$aCategoryInfo['blogc_pid']."'";
$sSql = $sSelect.$sFrom.$sWhere;
${"r".$aConfiguration['TABLES']['categories']} = $oBlog->oDB->query($sSql);
$aParentCategoryInfo = $oBlog->oDB->fetch_array(${"r".$aConfiguration['TABLES']['categories']});
//Merge the name of the parent category into the original array as 'blogc_pid_name'
$aCategoryInfo['blogc_pid_name'] = $aParentCategoryInfo['blogc_name'];
}