Hello,

This is a reply to an e-mail that you wrote on Fri, 1 Aug 2003 at
02:04, lines prefixed by '>' were originally written by you.
> Hi,
> This is what i am doing, querying a database via a select
statement
> (getting
> max 5 records), then dumping everything into an associative array.
And
> then
> assign the arrays value to a variable for easier readibility and
> usability
> like so:
> if(!($rs = mysql_query($q))) // querying
>   { echo "Query failed". mysql_error(); exit; }
>    $n = 0;
>   while ($line = mysql_fetch_assoc($rs)) { //dumping into an
array
>     foreach ($line as $field => $value) {
>       $data[$field][$n] = $value;
>     }
>     $n++;
>   }
> and this is how i use the arrays values (blah is the field name):
> $blah1=$data['blah'][0];
> $blah2=$data['blah'][1];
> $blah3=$data['blah'][2];

The logic you are using is a bit messed up.  You should be aiming to
get an array like...
$data[0]['field1']
        ['field2']
     [1]['field1']
        ['field2']
..and this can be done like this...
  $data = array();
  while ($line = mysql_fetch_assoc($rs)) {
      $data[] = $line;
  }

HTH

David.

--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: http://www.phpmachine.com/

          Professional Web Development by David Nicholson
                    http://www.djnicholson.com/

    QuizSender.com - How well do your friends actually know you?
                     http://www.quizsender.com/
                    (developed entirely in PHP)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to