how to extract fields from associative array into different variables

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

 



Is there an easier or simpler way to do this?
code:

$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";

    $author = array();
    if ( ( $results = mysql_query($sql, $db) ) !== false ) {
        while ( $row = mysql_fetch_array($results, MYSQL_ASSOC) ) {
            $author[] = $row;
        }
    }
$numrows = mysql_num_rows($results);
switch ($numrows)
{
case 5:
  $first_nameIN = $author[0]['first_name'];
  $last_nameIN = $author[0]['last_name'];
  $first_name2IN = $author[1]['first_name'];
  $last_name2IN = $author[1]['last_name'];
  $first_name3IN = $author[2]['first_name'];
  $last_name3IN = $author[2]['last_name'];
  $first_name4IN = $author[3]['first_name'];
  $last_name4IN = $author[3]['last_name'];
  $first_name5IN = $author[4]['first_name'];
  $last_name5IN = $author[4]['last_name'];
  break;
case 4:
  $first_nameIN = $author[0]['first_name'];
  $last_nameIN = $author[0]['last_name'];
snip....

-- 
Hervé Kempf: "Pour sauver la planète, sortez du capitalisme."
-------------------------------------------------------------
Phil Jourdan --- pj@xxxxxxxxxxxxx
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
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