How about a 2 dimensional array? If I understand you correctly wouldn't this
work:

$result = mysql_query("SELECT id, word, count FROM table", $db);
while ($return = mysql_fetch_array($result)) {
   $id = $return['id'];
   $row[$id]['word'] = $return['word'];
   $row[$id]['count'] = $return['count'];
}

Very rough. Just threw it together now. *shrug*


Regards,
Aragon


> On Monday 10 December 2001 00:36, you wrote:
> > I have a MySQL query that I want to draw an associative array from -
> > but I want the 'key' to the array to be the identifying element of
> > the row, and I'm stuck on how to get what I want.
> >
> > For instance:
> >
> > Each row in the result set contains an id number, a keyword and a
> > count related to that keyword.
> >
> > so in a 'while' loop I can get an associative array like $row["id"],
> > $row["word"], etc. with no problem.
> >
> > However - later (outside of the 'while' loop) I want to be able,
> > given the id number, to get the keyword and the count.  Like this
> > pseudo code:
> >
> >    $id_list(1150, 1160, 1170);
> >    for each $item in $id_list {
> >       print ($item["word"] : $item["count"]);
> >    }
> >
> > The idea is that I want a series of associative arrays that might be
> > otherwise set like...
> >
> >    $1150["word"] = "Blue";
> >    $1150["count"] = 12;
> >    $1160["word"] = "Red";
> >    ...etc....
> >
> > ...except drawn from a MySQL query.
> >
> > Any ideas how to achieve this?
>



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to