johnnyk Posted June 19, 2006 Share Posted June 19, 2006 [code]$row = mysql_fetch_array(mysql_query("SELECT a, b FROM `table`"))print_r($row);/*outputs:Array( [0] => text [a] => text [1] => blah blah blah [b] => blah blah blah)*/[/code]Why is each column placed in the array twice? Is that supposed to happen? Quote Link to comment https://forums.phpfreaks.com/topic/12409-row-array/ Share on other sites More sharing options...
wildteen88 Posted June 19, 2006 Share Posted June 19, 2006 Yes as the mysql_fetch_array returns an array with both associative and number indicesif you want to use numbers for the array keys use this:mysql_fetch_array(mysql_query("SELECT a, b FROM `table`"), MYSQL_NUM)But if you want letters for the array keys use this:mysql_fetch_array(mysql_query("SELECT a, b FROM `table`"), MYSQL_ASSOC) Quote Link to comment https://forums.phpfreaks.com/topic/12409-row-array/#findComment-47444 Share on other sites More sharing options...
johnnyk Posted June 19, 2006 Author Share Posted June 19, 2006 [!--quoteo(post=385777:date=Jun 19 2006, 03:43 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 19 2006, 03:43 PM) [snapback]385777[/snapback][/div][div class=\'quotemain\'][!--quotec--]Yes as the mysql_fetch_array returns an array with both associative and number indicesif you want to use numbers for the array keys use this:mysql_fetch_array(mysql_query("SELECT a, b FROM `table`"), MYSQL_NUM)But if you want letters for the array keys use this:mysql_fetch_array(mysql_query("SELECT a, b FROM `table`"), MYSQL_ASSOC)[/quote]Why does it return it as both? Would specifying MYSQL_NUM or MYSQL_ASSOC make it return the results faster? Quote Link to comment https://forums.phpfreaks.com/topic/12409-row-array/#findComment-47451 Share on other sites More sharing options...
wildteen88 Posted June 19, 2006 Share Posted June 19, 2006 Because if you dont specify the secound parameter as the the type you want the result to be return as mysql_fetch_array will retun both number indicies and associative arrays. I wont make it return the result faster, well it will but you wont be able to notice as its very small. Quote Link to comment https://forums.phpfreaks.com/topic/12409-row-array/#findComment-47455 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.