Re: Form Handling

From: Date: Mon, 30 Oct 2000 02:30:21 +0000
Subject: Re: Form Handling
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-22596@lists.php.net to get a copy of this message
This is how I do it: <? echo '<SELECT NAME="f[id]">'."\n"; $sql = "SELECT * FROM table"; $r = mysql_query($sql); while($row = mysql_fetch_array($r)){ echo '<OPTION VALUE="'.$row['id'].'" '; // $f['id'] is either the form element or // a value you pulled out from the db and put // into $f['id'] if($row['id'] == $f['id']){ echo ' SELECTED '; } echo '>'.$row['title'].'</OPTION>'."\n"; } echo '</SELECT>'."\n"; ?> --Joe On Sun, Oct 29, 2000 at 08:32:00PM -0600, Robert Abbate wrote: > I am looking for a little help with HTML form handling with MySQL. > > I want the HTML to print the correct option from the database when I have a > drop-down list. > > I need PHP to take the answer from the database (let's say it's "05") and > print: > > <SELECT NAME="month"> > <OPTION VALUE="01" >01 > <OPTION VALUE="02" >02 > <OPTION VALUE="03" >03 > <OPTION VALUE="04" >04 > <OPTION SELECTED VALUE="05" >05 > <OPTION VALUE="06" >06- > <OPTION VALUE="07" >07 > <OPTION VALUE="08" >08 > <OPTION VALUE="09" >09 > <OPTION VALUE="10" >10 > <OPTION VALUE="11" >11 > <OPTION VALUE="12" >12 > </select> > > > > This is what I have thus far: > > > mysql_connect("localhost", "$user", "$password"); > mysql_select_db("$database"); > > > $query = mysql_query("SELECT * FROM my_table WHERE (url = '$url')"); > $info = mysql_fetch_array($query); > > // The query gives this result: "2001-05-15" and is assigned to: "$sub_date > " > > $sub_date = $info["submit_date"]; > list($submit_year, $submit_month, $submit_day) = split ("-", $sub_date, 10); > > $month_array = array("01", "02", "03", "04", > "05", "06", "07", "08", "09", > "10", "11", "12"); > > for($i=0, reset($submit_month); > $i<count($month_array); $i++) { > echo "<OPTION"; > if(current($month_array)==$submit_month) { > echo " selected "; > next($month_array); > } > echo " VALUE=\"$submit_month\"> $submit_month\n"; > } > > When it prints the result, it gives: > > > <b>Warning</b>: Variable passed to reset() is not an array or object in > <b>/home/internetsubmit.net/www/simplehost/url.php</b> on line > <b>17</b><br> > <OPTION selected VALUE="01"> 01 > <OPTION VALUE="01"> 01 > <OPTION VALUE="01"> 01 > <OPTION VALUE="01"> 01 > <OPTION VALUE="01"> 01 > <OPTION VALUE="01"> 01 > <OPTION VALUE="01"> 01 > <OPTION VALUE="01"> 01 > <OPTION VALUE="01"> 01 > <OPTION VALUE="01"> 01 > <OPTION VALUE="01"> 01 > <OPTION VALUE="01"> 01 > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net ================================================================================ = Joe Stump joestump98@yahoo.com http://www.miester.org = ================================================================================ "Real programmers don't comment their code. It was hard to write, it should be hard to understand."

« previous php.general (#22596) next »