[PHP] Arrays from forms

2001-02-04 Thread Jamie

Can someone please help me with this code I'm having major problems with
arrays. This code is part of a function I'm writing to deal with an array
returned from a HTML form of check boxes so if anyone has an example of this
sort of thing I'd appreciate a look at it. Anyway Code follows :

//Reading from a data base
$db = mysql_connect("$DB_Server", "$DB_Login, $DB_Password");
 mysql_select_db("$DB_Name",$db);
 $results = mysql_query("SELECT option_type, code FROM options WHERE
code='000' ORDER BY option_type",$db);
 mysql_fetch_array($results);
// From what  understand I should have an array some thig like this:
// ("Size"="A4" , "Size" = "A3", "Size"="A5", "Colour"="Red", etc..);
 $types = array_values($results);
// OK so now I think I have an array like this:
// ("A4" , "A3", "A5", "Red", etc..);
  while ($type =array_pop($types)){
   echo $type."br";
 }
// Now I'm expecting this list to be printed to be outputted
A4
A5
A3
Red
etc...

I'm figureing that this would be a good way to retreive a listing from the
web site arrays and test and insert them one by one.

/// The table options

option_type || code || option_preferences
Size || 000 || A4
Size || 000 || A3
Size || 000 || A5
Colour || 000 || Red
Colour || 000 || Blue
Colour || 000 || Green



Re: [PHP] Arrays from forms

2001-02-04 Thread Steve Werby

"Jamie" [EMAIL PROTECTED] wrote:
 $results = mysql_query("SELECT option_type, code FROM options WHERE
 code='000' ORDER BY option_type",$db);
  mysql_fetch_array($results);
 // From what  understand I should have an array some thig like this:
 // ("Size"="A4" , "Size" = "A3", "Size"="A5", "Colour"="Red", etc..);

According to your SQL statement that doesn't appear to be true.  According
to your SQL statement you'll return two fields: option_type and code.

  $types = array_values($results);
 // OK so now I think I have an array like this:
 // ("A4" , "A3", "A5", "Red", etc..);
   while ($type =array_pop($types)){
echo $type."br";
  }

I'd avoid using array_values() and array_pop().  Simply do this:

while ( $row = mysql_fetch_array( $result ) )
{
$option_type = $row[option_type];
$code = $row[code];
echo "$option_type $codebr";
}

Hopefully that'll be enough to get you going.

--
Steve Werby
COO
24-7 Computer Services, LLC
Tel: 804.817.2470
http://www.247computing.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]