Re: mysql and php

From: Date: Mon, 17 Jul 2000 17:47:04 +0000
Subject: Re: mysql and php
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-1204@lists.php.net to get a copy of this message
Thanks all, you have been a great help. I got it to work:) On Mon, 17 Jul 2000, Cody Caughlan wrote: > If that is the case, then you would want to use: > > function prdbopts($name,$size,$table,$field,$sel) { > $res = mysql_db_query("database_name","SELECT DISTINCT $field FROM > $table > ORDER BY $field"); > if(mysql_errno()) { > $err = mysql_error(); > echo __FILE__ . " - " . __LINE__ . ": $err<BR>\n"; > } > if($size == 0) > echo "<SELECT NAME=\"$name\">\n"; > else > echo "<SELECT NAME=\"$name\" > SIZE=\"$size\">\n"; > while($row = mysql_fetch_array($res)) { > echo "<OPTION VALUE=\"$row[$field]\""; > if($row[$field] == $sel) > echo " SELECTED"; > echo ">\n"; > echo "$row[$field]</OPTION>"; > } > echo "</SELECT>\n"; > } > > Chris Hughes wrote: > > > I may have misunderstood the question, I was thinking that youw wanted to > > know which one they selected by the values in the DB. > > Sorry, > > Chris > > > > -----Original Message----- > > From: codyc@cisco.com [mailto:codyc@cisco.com] > > Sent: Monday, July 17, 2000 11:20 AM > > To: Wesley Choate > > Cc: php-db@lists.php.net > > Subject: Re: [PHP-DB] mysql and php > > > > One of the beautiful things about PHP is that it automatically puts all form > > variables for a POST form in HTTP_POST_VARS which is an associative array. > > Of > > course, this relies on 'enable track vars' being enabled in PHP config, > > which > > by default I believe it is. > > so, lets say you have two form variables in your script, one is the name of > > the > > fruit producer, like this: > > > > <input type=text name=producer size=20> > > > > and then lets say you have a select menu with three fruits in it, like this: > > > > <SELECT name=fruits> > > <OPTION VALUE="apple">Apple</OPTION> > > <OPTION VALUE="orange">Orange</OPTION> > > <OPTION VALUE="peach">Peach</OPTION> > > > > so if the user types in a name of the producer and selects a fruit and > > submits > > this form, then assuming you used POST as your form method (PHP also > > supports > > GET and hence uses HTTP_GET_VARS) > > then the two variables will be set: > > > > HTTP_POST_VARS[producer] would be set to what the user typed in > > HTTP_POST_VARS[fruits] would be either apple,orange or fruit. > > > > So you can just check for that. I have provided a function, you pass it the > > name of select variable, in this fruits, and you have two arrays, one with > > the > > values and one with the text to show in the menu. > > So I could have an array like this: > > > > $fruits = array("apple", "peach", "orange"); > > > > and then in the above HTML you would call the function like this: > > > > propts("fruits", 0, $fruits, $fruits, ""); > > > > function propts ($name,$size,$vals,$opts,$sel) { > > if(size == 0) > > echo "<SELECT NAME=\"$name\">\n"; > > else > > echo "<SELECT NAME=\"$name\" > > SIZE=\"$size\">\n"; > > for ($i=0;$vals[$i];$i++) { > > echo "<OPTION VALUE=\"$vals[$i]\""; > > if($sel == $vals[$i]) > > echo " SELECTED"; > > echo ">$opts[$i]</OPTION>\n"; > > } > > echo "</SELECT>\n"; > > } > > > > If you wanted to use numbers as your fruits in the database, then create > > another array that corresponds to the first and put that array name in place > > of > > $vals array in the function. > > (in my example, since I wanted the fruit name to be both the value and the > > text > > in html, I just gave it to the function twice). Notice that if you want a > > particular option to be selected by default you pass that name to the > > function > > as the last argument. > > > > Good luck > > /Cody Caughlan > > > > Wesley Choate wrote: > > > > > Could you show us the code you are using..the html form code and the > > > actually php program that the forms action refers to?? > > > > > > > -----Original Message----- > > > > From: Joanna [SMTP:joanna@blackhole.evilgeeks.com] > > > > Sent: Monday, July 17, 2000 12:02 PM > > > > To: php-db@lists.php.net > > > > Subject: [PHP-DB] mysql and php > > > > > > > > > > > > I have a db with a simple table. One of the fields in the tables are > > > > fruit. I created a HTML SELECT FORM to select what kind of > > > > fruit,apples,peaches,ect... I would like to input the kind of fruit into > > > > the table. I have even tried using php ifelse statements to assign > > > > integers instead of the actual fruit name and I still can't figure it > > > > out. Can someone please help. > > > > The thing I can't figure out is how to know which of the choices have > > been > > > > selected from the form. > > > > > > > > thanks > > > > > > > > > > > > > > > > -- > > > > PHP Database Mailing List (http://www.php.net/) > > > > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > > > > For additional commands, e-mail: php-db-help@lists.php.net > > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > > > > > -- > > > PHP Database Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-db-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > > For additional commands, e-mail: php-db-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > > For additional commands, e-mail: php-db-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > >

« previous php.db (#1204) next »