Zisly
Intermediate OT User
- Joined
- Jun 9, 2008
- Messages
- 7,338
- Reaction score
- 120
Hello!
I've been sitting here for some hours trying to figure out whats going on but I just can't, I'm probably missing something simple but I just can't notice it >.<
My problem:
I'm trying to use the data of a global array to connect to a mysql database, which just doesn't work for some reason.
I made a test file to see if my way of doing it was wrong but nope, I was doing it right, at least judging from the example.
So, something has to be wrong with the main code, anyone who could give it a look?
Where I'm calling the function:
config.php:
And the function file:
I've been sitting here for some hours trying to figure out whats going on but I just can't, I'm probably missing something simple but I just can't notice it >.<
My problem:
I'm trying to use the data of a global array to connect to a mysql database, which just doesn't work for some reason.
I made a test file to see if my way of doing it was wrong but nope, I was doing it right, at least judging from the example.
So, something has to be wrong with the main code, anyone who could give it a look?
Where I'm calling the function:
PHP:
<?PHP
include("footer.php");
include("config.php");
include("menus.php");
$topmenu = LoadTopMenu();
?>
config.php:
PHP:
// Database
$database_host = "localhost";
$database_user = "root";
$database_pass = "xxxx";
$database_db = "teamworker";
$CONFIG = array(
"db_host" => $database_host,
"db_user" => $database_user,
"db_pass" => $database_pass,
"db_db" => $database_db);
And the function file:
PHP:
<?php
include("config.php");
// Loads top menus
function LoadTopMenu()
{
global $CONFIG;
$top_menu = '';
// Connect to the MYSQL database
mysql_connect($CONFIG['db_host'], $CONFIG['db_user'], $CONFIG['db_pass']) or die(mysql_error());
// Select the DB
mysql_select_db($CONFIG['db_db']) or die(mysql_error());
// Load top menu
$query = mysql_query( 'SELECT * FROM `top_menu`;' )or die(mysql_error());
while ( $row = mysql_fetch_array( $query ) )
{
// load top menu, {destination, img, text*2}
$tempVar = '<li><a href="'.$row['dest'].'" title="'.$row['text'].'">'.$row['text'].'</a></li>';
// Append to variable
$top_menu = $top_menu.$tempVar;
}
// return the variable with the menus
return $top_menu;
}
?>