solarisuser Posted June 29, 2007 Share Posted June 29, 2007 Hello All, I can't get this to work right, $aResults should be ~200 records (mysql query is correct)... $aResults = array(); $get = mysql_query("SELECT id as id,tool as value,pan as info FROM s.tb1 LIMIT 0,200"); $row = mysql_fetch_array($get); $num = mysql_num_rows($get); for ($i=0;$i<count($num);$i++) { $aResults[$i]['id'] = $row['id']; $aResults[$i]['value'] = $row['value']; $aResults[$i]['info'] = $row['info']; } var_dump($aResults); Thanks! Link to comment https://forums.phpfreaks.com/topic/57788-multidimensional-array-help/ Share on other sites More sharing options...
per1os Posted June 29, 2007 Share Posted June 29, 2007 $aResults = array(); $get = mysql_query("SELECT id as id,tool as value,pan as info FROM s.tb1 LIMIT 0,200"); while ($row = mysql_fetch_array($get)) { $aResults[] = $row; } var_dump($aResults); You have to iterate through the query to get all the records. Link to comment https://forums.phpfreaks.com/topic/57788-multidimensional-array-help/#findComment-286245 Share on other sites More sharing options...
Barand Posted June 29, 2007 Share Posted June 29, 2007 Better to use mysql_fetch_assoc() as everything will be stored twice with mysql_fetch_array (associative index and numeric index) Link to comment https://forums.phpfreaks.com/topic/57788-multidimensional-array-help/#findComment-286248 Share on other sites More sharing options...
teng84 Posted June 29, 2007 Share Posted June 29, 2007 $aResults = array(); $get = mysql_query("SELECT id as id,tool as value,pan as info FROM s.tb1 LIMIT 0,200"); $num = mysql_num_rows($get); for ($i=0;$i<count($num);$i++) { $row = mysql_fetch_array($get); $aResults[$i]['id'] = $row['id']; $aResults[$i]['value'] = $row['value']; $aResults[$i]['info'] = $row['info']; } var_dump($aResults); thats the code you have the prob is that you put the $row = mysql_fetch_array($get); outside the loop any way it will work now but its better to use the while loop its shorter Link to comment https://forums.phpfreaks.com/topic/57788-multidimensional-array-help/#findComment-286249 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.