i have this connection
<?php
$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_name = 'databasename';
$conn = mysql_connect($db_host,$db_user,$db_pass) or die(mysql_error());
mysql_select_db($db_name,$conn);
mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8');
?>
but my old connection dosen't work with this code
//connect to database
$link = mysqli_connect('localhost','root','');
mysqli_select_db($link,'databasename');
//get all rows
$query = mysqli_query($link,'SELECT * FROM categories');
while ( $row = mysqli_fetch_assoc($query) )
{
$menu_array[$row['catid']] = array('catname' => $row['catname'],'parentid' => $row['parentid']);
$menu_array[$row['catid']] = array('catname' => $row['catname'],'parentid' => $row['parentid'],'catid'=>$row['catid']);
}
//recursive function that prints categories as a nested html unorderd list
function generate_menu($parent)
{
$has_childs = false;
//this prevents printing 'ul' if we don't have subcategories for this category
global $menu_array;
//use global array variable instead of a local variable to lower stack memory requierment
foreach($menu_array as $key => $value)
{
if ($value['parentid'] == $parent)
{
//if this is the first child print '<ul>'
if ($has_childs === false)
{
//don't print '<ul>' multiple times
$has_childs = true;
echo '<ul>';
}
echo '<li><a href="category.php?catid='. $value['catid'] . '">' . $value['catname'] . '</a>';
generate_menu($key);
//call function again to generate nested list for subcategories belonging to this category
echo '</li>';
}
}
if ($has_childs === true) echo '</ul>';
}
I think My erro located between this code .. Finally i need just replace mysqli_connect to mysql_connect Without I
while ( $row = mysqli_fetch_assoc($query) )
{
$menu_array[$row['catid']] = array('catname' => $row['catname'],'parentid' => $row['parentid']);
}