AbydosGater Posted July 15, 2007 Share Posted July 15, 2007 Hi Guys, Im having some sort of problem with my SQL Query and its Fetch_array. If you look at the following code.. It should echo out the data from my table in the format "key: Val" and it does but its pulling more data then it should.. If you look at the output of the following code. <?php mysql_connect('localhost', 'root', ''); mysql_select_db("sb"); $plugins_list=mysql_query("SELECT * FROM sb_plugins WHERE sb_plugins.status = 'init' ORDER BY sb_plugins.priority ASC"); while($plugin=mysql_fetch_array($plugins_list)){ foreach ($plugin as $key => $val){ echo $key .': '.$val.'<br />'; } } ?> Output: 0: 1 pID: 1 1: Main Menu name: Main Menu 2: main_menu dir: main_menu 3: menu.class.php file: menu.class.php And so on there is more.... But i dont get where the "1: Main Menu" or "2: main_menu" array objects are coming from!?! It should not have any Keys as numbers only the field names from the database. Does anyone know why its pulling the "Number: Value" aswell as "Key Val"?? Please any help would be greatful! Its driving me mad i cant see what i did wrong. Quote Link to comment Share on other sites More sharing options...
lur Posted July 15, 2007 Share Posted July 15, 2007 http://php.net/mysql_fetch_array mysql_fetch_array -- Fetch a result row as an associative array, a numeric array, or both array mysql_fetch_array ( resource result [, int result_type] ) result_type: The type of array that is to be fetched. It's a constant and can take the following values: MYSQL_ASSOC, MYSQL_NUM, and the default value of MYSQL_BOTH. Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted July 15, 2007 Author Share Posted July 15, 2007 Ah Yes, Thanks Lur.. Lol been using MySql fetch array for a year or two now and never came across that problem Heh. Thanks all working now. Andy Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 15, 2007 Share Posted July 15, 2007 Use mysql_fetch_assoc instead. mysql_fetch_array returns two types of arrays:- an associative array and a numerical array. mysql_fetch_assoc returns just an associative array - which is what you want. Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted July 15, 2007 Author Share Posted July 15, 2007 Oh right yes. Will simply change that now! Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.