-----Ursprungligt meddelande----- Från: nicolas figaro [mailto:nfigaro@xxxxxx] Skickat: den 22 maj 2006 11:50 Till: PHP List Ämne: Re: Array name out of field value with data Jonas Rosling a écrit : > Not so sure if I've tried to work this out before in this list. > I'm trying to make an array name by a field/row value and assigning values > to it. But I'm having some problems getting it to work. > Is it possible to do this? And if, what am I doing wrong? Or is there any > other way to do it? > > while($row=mysql_fetch_array($result)) { > > // Checking if variable/array is not declared > if (!$$row[0]) { > > what do you want to check with the code above ? I don't think $$row[0] will give you anything good. as you're inside your while loop, $row should be declared, but the content of $row[0] depends on your request. you can check if $row[0] is set using "count $row"; but if you have an empty value in the first column, this will give you an empty string as result. try a print_r($row); after your "while". > // Declaring an empty array by the value of sales person code > $$row[0] = array(); > > I still don't understand why you're using $$row above. > // Current sales person code > $code = $row[0]; > > // Putting the product name as a key and the price as a value in the array > eval("\$code[\$row[1]] = \"$row[2]\";"); > do you really want to erase the content of $code you just set above with the eval statement ? $my_array = array(); $my_array[$1] = $2; > } > > } > > Thanks > > Could you please describe a bit more what you'd like to do/set, so we can give you a better help ? N F -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The thing is that I want to name an array by the value in $row[0], sales person code. Once the array is declared it should not be declared again. The field never contains an empty value. After that I want to push in $row[1] as a key with $row[2] as a value, all related to the array name/sales person code. So if an array is declared that is equal as the value in the first field it should input a key and value. For example the array "AT" can contain 10 "collections" of data. Array ( [Product 1] => 1500 [Product 2] => 3000 [Product 3] => 500 ) etc, Hope I have made it a bit more easier to understand now. // Jonas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php