Re: Multidimensional Arrays...

From: Date: Sat, 12 Apr 2003 18:14:03 +0000
Subject: Re: Multidimensional Arrays...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-143619@lists.php.net to get a copy of this message
you con't store both an integer and an array in one key. build your array like so: $data['user']['username_level'] = $bla; $data['user']['area_topic_level'] = $bla; $data['user']['specific_topic_level'] = $bla; $data['user']['topic_value_level'] = $bla; you can add as many elements to $data['user'] as you like you can do this $data['user']['id'] = 123; but you cannot do this $data['user'] = 123; olinux --- Mark Douglas <Mark.Douglas@Q9.com> wrote: > I'm at an impass on how to design a portion of an > application I'm building. > I have four variables, which are all related - > Username, area topic, > specific topic, topic value. Area topic is > relatively static, which points > to specific topic (also static), which points to a > topic value. Topic value > is unique to each username. All of this information > is stored in a database, > and I need to retrieve it and put it into a > formatted table. Initially, I > had intended to use a multidimensional array of > $data[username_level][area_topic_level][specific_topic_level][topic_value_le > vel]. However, I'm finding working with a > multidimensional array very > difficult. I've managed to get two dimensions > working, but that took me far > too long, and moving to the third dimension is > beyond me at this point - I > don't see how I'm going to get to the fourth in this > lifetime. So, here's > what I have so far: > > <?php > $userResult = mysql_db_query($sqldb,"SELECT username > FROM skills_users WHERE > topic IS NOT NULL GROUP BY username") or > die(mysql_error()); > $userData = array(); > while ($row = mysql_fetch_array($userResult)) { > array_push($userData, $row["username"]); > } > //print_r($userData); > > $areaResult = mysql_db_query($sqldb,"SELECT area > FROM skills_topics GROUP BY > area ORDER BY area ASC") or die(mysql_error()); > $areaData = array(); > while ($row = mysql_fetch_array($areaResult)) { > array_push($areaData, $row["area"]); > } > //print_r($areaData); > > $skill_data = array(); > for ($i = 0; $i < count($userData); $i++) { > for ($c = 0; $c < count($areaData); $c++) { > $skill_data[$userData[$i]][$c] = > $areaData[$c]; > } > } > > //print_r($skill_data); > > for ($i = 0; $i < count($userData); $i++) { > for ($c = 0; $c < count($areaData); $c++) { > $area = $skill_data[$i][$c]; > $topicResult = mysql_db_query($sqldb,"SELECT > topic FROM skills_topics > WHERE area = \"".$area."\" ORDER BY topic ASC") or > die(mysql_error()); > $topicData = array(); > while ($row = > mysql_fetch_array($topicResult)) { > array_push($topicData, $row["topic"]); > } > // print_r($topicData); > for ($x = 0; $x < count($topicData); $x++) { > > $skill_data[$userData[$i]][$areaData[$c]][$x] = > $topicData[$x]; > } > } > } > > Note that the third dimension does not work as I > have lost the integer key > values to the first dimension when putting data into > the second. I tried > building the second dimension by using $array[][] > but that just erased the > values in my first dimension, as did looping through > $array[$counter][]. > > Any help is greately appreciated, whether it be an > alternative solution or > an explanation as to what I'm doing wrong with > multidimensional arrays. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com

« previous php.general (#143619) next »