I'm trying to get the $url value to display from the MySQL database but I can only get the $cat value to display correctly can someone please help me learn how to display the $url value.
I now I'm doing something wrong.
Here is the partial code.
// Loop through each subarray:
foreach ($parent as $id => $cat) {
// Display the item:
echo '<li><a href="http:' . $url . '" title="">' . $cat . '</a>';
Here is the complete code.
<?php
require_once ('./mysqli_connect.php'); // Connect to the db.
// Receives one argument: an array.
function make_list ($parent) {
// Need the main $link array:
global $link;
// Start an ordered list:
echo '<ol>';
// Loop through each subarray:
foreach ($parent as $id => $cat) {
// Display the item:
echo '<li><a href="http://' . $url . '" title="">' . $cat . '</a>';
// Check for sublink:
if (isset($link[$id])) {
// Call this function:
make_list($link[$id]);
}
// Complete the list item:
echo '</li>';
} // End of FOREACH loop.
// Close the ordered list:
echo '</ol>';
} // End of make_list() function.
// Connect to the database:
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT * FROM categories ORDER BY parent_id, category ASC");
if (!$dbc) {
// There was an error...do something about it here...
print mysqli_error();
}
// Initialize the storage array:
$link = array();
while (list($id, $parent_id, $category) = mysqli_fetch_array($dbc, MYSQLI_NUM)) {
// Add to the array:
$link[$parent_id][$id] = $category;
}
make_list($link[0]);
mysqli_close($mysqli); // close the connection
?>