snowboarderz69 Posted February 10, 2010 Share Posted February 10, 2010 Hello everyone, I'm trying to creat a Array with a desired Index but when i Try to choose my index I get the error : $my_array is not a array. Here's my code : $strRequeteCours = "SELECT * FROM t_cours WHERE session IN (" . $idSession . ")"; $strCours = mysql_query($strRequeteCours) or die (mysql_error()); $a_retourner = array(); while ($a_cours = mysql_fetch_assoc($strCours)){ array_push($a_retourner[$a_cours["id_cours"]],$a_cours["nom_cours"] . " " . $a_cours["duree"] . " " . $a_cours["ponderation"] . "<br/>" . $a_cours["description_cours"]); } So I want to push my info into a Array where the Index of the array equal my "id_cours". I alost tryed with the Index 1 to and it didn't worked. Thanks alot ! Link to comment https://forums.phpfreaks.com/topic/191664-array_push-with-desired-index/ Share on other sites More sharing options...
sader Posted February 10, 2010 Share Posted February 10, 2010 u simple can use this technique $array[] = $var; //auto incremented index //or $array['your_key_name'] = $var; Link to comment https://forums.phpfreaks.com/topic/191664-array_push-with-desired-index/#findComment-1010284 Share on other sites More sharing options...
snowboarderz69 Posted February 10, 2010 Author Share Posted February 10, 2010 The problem with this technique is because I'm using a loop, my array will only contain the last value of my mysql_fetch_assoc. It would work perfectly if the arrays had something like the .= for the strings =/ Link to comment https://forums.phpfreaks.com/topic/191664-array_push-with-desired-index/#findComment-1010291 Share on other sites More sharing options...
sader Posted February 10, 2010 Share Posted February 10, 2010 well maybe u need here multi dimensional array $array['key_name'][] = $var; Link to comment https://forums.phpfreaks.com/topic/191664-array_push-with-desired-index/#findComment-1010293 Share on other sites More sharing options...
snowboarderz69 Posted February 10, 2010 Author Share Posted February 10, 2010 Awesome! It's working perfectly Thanks for the help & the fast answer ! Link to comment https://forums.phpfreaks.com/topic/191664-array_push-with-desired-index/#findComment-1010296 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.