Re: Multidimensional Arrays...
| From: | dwalker | Date: | Sun, 13 Apr 2003 06:00:06 +0000 |
| Subject: | Re: Multidimensional Arrays... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-143646@lists.php.net to get a copy of this message | ||
It seems to me that each query should should use the results of the previous
query to grab further CORRECT information as it pertains to each user etc...
In other words, each query appears to be doing entirely separate
tasks...none, seemingly linked to another. Sure you can plop the results
into an array...but will the data make sense. Garbage in....Garbage out.
I believe what you want to do is to use one or some of the returned values
of a query as KEYS for the next query...otherwise I think you're just
'grabbing' at information within your data base. You might try (just for
test purposes) combining ALL queries into one query just to see the results.
If you get the correct results, then try separating each query (IF YOU
REALLY HAVE A NEED TO).
-----Original Message-----
From: Mark Douglas <Mark.Douglas@Q9.com>
To: Php-General (E-mail) <php-general@lists.php.net>
Date: Saturday, April 12, 2003 10:58 AM
Subject: [PHP] Multidimensional Arrays...
>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_l
e
>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
>
>