[eluser]daparky[/eluser]
I need a little help converting the following old SQL's
Code:
function getFeature($id) {
$sql = " SELECT f.feature_id AS id,
f.feature_category AS catId,
f.feature_template AS tempId,
f.feature_added AS added,
f.feature_addedby AS addedBy,
f.feature_edited AS edited,
f.feature_editedby AS editedBy,
f.feature_parent AS parent,
f.feature_approved AS approved,
f.feature_order AS forder,
f.feature_on AS fon,
f.feature_off AS foff,
c.category_name AS catName,
t.template_name AS tempName,
t.template_page AS tempPage
FROM db_features f,
db_templates t,
db_categories c
WHERE f.feature_id = '".$id."'
AND t.template_id = f.feature_template
AND c.category_id = f.feature_category";
$result = mysql_query($sql);
$det = array();
$rs = mysql_fetch_array($result);
$det['id'] = $rs['id'];
$det['tempId'] = $rs['tempId'];
$det['added'] = $rs['added'];
$det['addedBy'] = $rs['addedBy'];
$det['edited'] = $rs['edited'];
$det['editedBy'] = $rs['editedBy'];
$det['on'] = $rs['fon'];
$det['off'] = $rs['foff'];
$det['parent'] = $rs['parent'];
$det['catId'] = $rs['catId'];
$det['approved'] = $rs['approved'];
$det['order'] = $rs['forder'];
$det['catName'] = stripslashes($rs['catName']);
$det['tempName'] = stripslashes($rs['tempName']);
$det['tempPage'] = $rs['tempPage'];
$attributes = $this->featureAttributes($id, $rs['tempId']);
$z=0;
foreach($attributes as $key => $value) {
$det[$key] = $value;
$det[$z] = $value;
$z++;
}
return($det);
}
function featureAttributes($feature, $template) {
$sql = " SELECT a.attribute_id,
at.type_name as type,
ta.attribute_form_name as form
FROM db_templates t,
db_template_attributes ta,
db_attributes a,
db_attribute_types at
WHERE t.template_id = '".$template."'
AND ta.template_id = t.template_id
AND a.attribute_id = ta.attribute_id
AND at.type_id = a.attribute_type
ORDER BY ta.attribute_order ASC";
$result = mysql_query($sql) or die (mysql_error());
while($rs = mysql_fetch_array($result)) {
$attSql = " SELECT fa.fa_".$rs['type']."
FROM db_feature_attributes fa
WHERE fa.fa_feature_id = '".$feature."'
AND fa.fa_attribute_id = '".$rs['attribute_id']."'";
$attResult = mysql_query($attSql) or die (mysql_error());
$attRs = mysql_fetch_array($attResult);
$att[$rs['form']] = $attRs['fa_'.$rs['type']];
}
return($att);
}
to Codeigniters Active Record. Please note that i want the results to output as objects, the above queries are for arrays.
The output result looks like this:
Code:
<?php
$form = $cCms->tempAttributes(1);
$feature = $cCms->getFeature(1);
for($i=0; $i<count($form); $i++) { ?>
<input name="<?= $form[$i]['form'] ?>" type="text" style="width:100%;" value="<?= $feature[$form[$i]['form']]; ?>" />
<?php
} ?>
I've been trying all night and cannot achieve anything from it. Basically i'm converting a CMS to Codeigniter.
Any help would be much appreciated.