I was hoping someone can help me convert this piece of code from object form to procedural form.
So I can have a sense of what to do for when I try to convert the larger piece of code that is all in object form that this snippet came from.
I'm a brand new beginner.
$sql = "SELECT id, label, link_url, parent_id FROM dyn_menu ORDER BY parent_id, id ASC";
$items = mysql_query($sql);
while ($obj = mysql_fetch_object($items)) {
if ($obj->parent_id == 0) {
$parent_menu[$obj->id]['label'] = $obj->label;
$parent_menu[$obj->id]['link'] = $obj->link_url;
} else {
$sub_menu[$obj->id]['parent'] = $obj->parent_id;
$sub_menu[$obj->id]['label'] = $obj->label;
$sub_menu[$obj->id]['link'] = $obj->link_url;
$parent_menu[$obj->parent_id]['count']++;
}
}
mysql_free_result($items);
I know there is something wrong with this code?
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT id, label, link_url, parent_id FROM dyn_menu ORDER BY parent_id, id ASC");
if (!$dbc) {
// There was an error...do something about it here...
print mysqli_error();
}
while ($obj = mysql_fetch_assoc($dbc)) {
if ($obj->parent_id == 0) {
$parent_menu $obj['id']['label'] = $obj['label'];
$parent_menu $obj['id']['link'] = $obj['link_url'];
} else {
$sub_menu $obj['id']['parent'] = $obj['parent_id'];
$sub_menu $obj['id']['label'] = $obj['label'];
$sub_menu $obj['id']['link'] = $obj['link_url'];
$parent_menu $obj['parent_id']['count']++;
}
}
mysql_free_result($dbc);