RE: how to extract fields from associative array into different variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[snip]
In what way would this simplify or ease my pain?
The difficulty, it seems to me, is not in retrieving the rows, but
rather how to pass the row data to the variables. And since the number
of rows is variable, I believe that the only way to assign the variables
is by use of a loop? I think I'm beating my head against the wall for
nothing... :-(
[/snip]

You asked for easier. In this way the data is assigned to a usable
variable right out of the gate and that is an array variable. You can
actually use it with either mysql_fetch_array or mysql_fetch_row. 

Here is your query;

$sql = "SELECT first_name, last_name, book_author.ordinal
      FROM author, book_author
      WHERE book_author.bookID = $idIN && book_author.authID = author.id
ORDER BY ordinal";

You need not declare another array, but do it this way instead;

   if ($results = mysql_query($sql, $db)) {
        while ( $row = mysql_fetch_array($results, MYSQL_ASSOC) ) {
            echo $row['first_name'];
		echo $row['last_name'];
....etcetera.....
        }
    }

The lazy part I will agree with :)

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux