NoDoze Posted November 27, 2006 Share Posted November 27, 2006 First Question:How do you do it? How do you get a pull down list to be the contents from a mysql database?Second Question:For example... You have a list of numbers in a drop down list, 101, 102, 103, 104, ect. that are getting pulled from the msql database...How do you make it so that when a user chooses, say 103 on the form, this number gets removed from the msql db list....so that the next person who shows up will then have 101, 102, 104, ect....? Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/ Share on other sites More sharing options...
Gruzin Posted November 27, 2006 Share Posted November 27, 2006 You can try this script:[code]<select name="wordlist"> <option value="1" selected>Select Word</option><?phprequire("config.php");$result = mysql_query("SELECT * FROM spell");while($row = mysql_fetch_array($result)){ echo '<option value="' . $row['words'] . '"> ' . $row['words'] . "</option>\n ";}?></select>[/code] Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-131178 Share on other sites More sharing options...
NoDoze Posted November 27, 2006 Author Share Posted November 27, 2006 SWEET! Worked like a charm! THANKS!Now on to the second question....If someone chooses one of the options, I need it to be removed from the database....? Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-131203 Share on other sites More sharing options...
NoDoze Posted November 27, 2006 Author Share Posted November 27, 2006 I got this much:DELETE from table_name [WHERE conditions];So I know how to delete a table entry, but how do I get it to delete what the user chooses from the form?So that when the option is chosen it's deleted from the database...Any ideas??? Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-131225 Share on other sites More sharing options...
corbin Posted November 27, 2006 Share Posted November 27, 2006 I wouldnt delete it, but I personally hate deleting things. Instead I would make another row and name it like 'active' and set it to 0 if it had been chosen, but make the defaut for it 1 so that they would begin active.Anyways this should work...[code=php:0]<?function form() { //function to output the formecho "<form action=\"\" method=\"POST\">";echo "<select name=\"wordlist\"> <option value=\"1\" selected>Select Word</option>"; // i can never remember the syntax for drop down boxes so this is Gruzin's :p$result = mysql_query("SELECT * FROM spell");while($row = mysql_fetch_array($result)){ echo '<option value="' . $row['words'] . '"> ' . $row['words'] . "</option>\n ";}echo "</select>";}function update_form($field) { //function to delete the rows//$q = "UPDATE `spell` SET `active` = '0' WHERE `words` = '{$field}'"; //this will update the row like i said...$q = "DELETE FROM `active` WHERE `words` = '{$field}'";if(mysql_query($q)) {return true;}else return false;}$link = @mysql_connect(); //set all your mysql crapif(@mysql_select("dbname", $link) {if(!$_POST) {form();}else {if(is_numeric($_POST['wordlist'])) {//update the DBif(update_form($_POST['wordlist'])) {echo "Thanks for your input.";}else echo "Server error; Please try later";}else {echo "Incorrect input";}}}else {echo "Database error. Please try again later.";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-131231 Share on other sites More sharing options...
NoDoze Posted November 28, 2006 Author Share Posted November 28, 2006 ok, wow, thanks, but I think that was way too much info...heh...This is what I have so far:[code]<select name="project_number" class="txtbox"> <option value="1" selected></option><?php$result = mysql_query("SELECT * FROM projnum");while($row = mysql_fetch_array($result)){ echo '<option value="' . $row['project_number'] . '"> ' . $row['project_number'] . "</option>\n ";}mysql_query("DELETE FROM projnum WHERE project_number = 'project_number'");?></select>[/code]But it's not deleting the number....?I know you're intentions wee good "corbin", but....Let me give you some background....This is in a html form posting to a mysql database and emailing the form.I just need the delete line... :)The changing the entry to active or not is an awesome idea, which I'm pretty sure I'll incorporate, but for now I just need to delete it.Thanks a bunch guys! Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-131246 Share on other sites More sharing options...
NoDoze Posted November 28, 2006 Author Share Posted November 28, 2006 Also, just to add, and to try to answer some of the possible confusion...The form is posting to on table and the project numbers are being pulled from a different table, but in both tables the row is called project_number...of course to make things confusing....Hence why you see the form field being called project_number AND the options being called project_number... Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-131257 Share on other sites More sharing options...
NoDoze Posted November 28, 2006 Author Share Posted November 28, 2006 Can anyone help me??? Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-131432 Share on other sites More sharing options...
NoDoze Posted November 28, 2006 Author Share Posted November 28, 2006 This is what I have so far:[code]<select name="project_number" class="txtbox"> <option value="1" selected></option><?php$result = mysql_query("SELECT * FROM projnum");while($row = mysql_fetch_array($result)){ echo '<option value="' . $row['project_number'] . '"> ' . $row['project_number'] . "</option>\n ";}mysql_query("DELETE FROM projnum WHERE project_number = 'project_number'");?></select>[/code]So I know how to delete a table entry, but how do I get it to delete what the user chooses from the form? Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-131709 Share on other sites More sharing options...
NoDoze Posted November 28, 2006 Author Share Posted November 28, 2006 I've tried just about EVERY permutation of:mysql_query("DELETE FROM projnum WHERE project_number='$project_number'");But it STILL won't delete the row from the table....Can anyone help me!?! Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-131733 Share on other sites More sharing options...
corbin Posted November 28, 2006 Share Posted November 28, 2006 Try setting the number manually or setting $project_number right before the query, and see if it works. Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-131849 Share on other sites More sharing options...
NoDoze Posted November 28, 2006 Author Share Posted November 28, 2006 heh huh?Number manually?$project_number right before query?Hmmmm, ya lost me....[code]<select name="project_number" class="txtbox"> <option value="1" selected></option><?php$result = mysql_query("SELECT * FROM projnum");while($row = mysql_fetch_array($result)){ echo '<option value="' . $row['project_number'] . '"> ' . $row['project_number'] . "</option>\n ";}mysql_query("DELETE FROM projnum WHERE project_number='$project_number'");?></select>[/code]I think the issue is with $project_number I don't think it's picking up the chosen variable...perhaps?Seams so simple, yet I'm having the hardest time with it!?! ...funny. Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-131865 Share on other sites More sharing options...
NoDoze Posted November 29, 2006 Author Share Posted November 29, 2006 BumpAnyone? Help Please? Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-132420 Share on other sites More sharing options...
NoDoze Posted November 29, 2006 Author Share Posted November 29, 2006 ok....do I have to grovel, beg, and plea?Pleeeeeeeeaaaasssssseeeeee......can someone help me?????This is the only thing that is preventing usage of this form....the last thing I need for it to work....Pleeeeeeeaaaaassssseeeee....help..... Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-132448 Share on other sites More sharing options...
dk4210 Posted November 30, 2006 Share Posted November 30, 2006 Did you get it to work No doze? Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-132461 Share on other sites More sharing options...
NoDoze Posted November 30, 2006 Author Share Posted November 30, 2006 Nope....This is what I have so far:[code]<select name="project_number" class="txtbox"> <option value="1" selected></option><?php$result = mysql_query("SELECT * FROM projnum");while($row = mysql_fetch_array($result)){ echo '<option value="' . $row['project_number'] . '"> ' . $row['project_number'] . "</option>\n ";}mysql_query("DELETE FROM projnum WHERE project_number='$project_number'");?></select>[/code] Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-132463 Share on other sites More sharing options...
NoDoze Posted November 30, 2006 Author Share Posted November 30, 2006 Sheeesh....still no help.... Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-132907 Share on other sites More sharing options...
NoDoze Posted November 30, 2006 Author Share Posted November 30, 2006 :'( Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-133046 Share on other sites More sharing options...
NoDoze Posted December 4, 2006 Author Share Posted December 4, 2006 Bump. Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-135114 Share on other sites More sharing options...
jcbarr Posted December 4, 2006 Share Posted December 4, 2006 You have to define the $project_number variable.The form has to submit the variable so that the script can pick it up. Right now you are using an empy variable. Until there is some value associated with $project_number it will not delete anything in the table. Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-135184 Share on other sites More sharing options...
NoDoze Posted December 4, 2006 Author Share Posted December 4, 2006 Here is the code:[code]<form action="/distribution/phorm.php" method="post" name="form"><table width="800" border="0"><tr><td colspan="2"><span class="txt-ast">*</span>Initiation Date: <input name="date" type="text" class="txtbox" size="11" maxlength="11" value="<?php echo date('m-d-Y');?>"></td></tr><tr><td width="273"><span class="txt-ast">*</span>Project Number: <select name="project_number" class="txtbox"> <option value="1" selected></option><?php$result = mysql_query("SELECT * FROM projnum");while($row = mysql_fetch_array($result)){ echo '<option value="' . $row['project_number'] . '"> ' . $row['project_number'] . "</option>\n ";}mysql_query("DELETE FROM projnum WHERE project_number = 'project_number'") or die(mysql_error());?></select></td><td width="517"><span class="txt-ast">*</span>Responsible Individual: <input name="resposible_individual" type="text" class="txtbox" size="3" maxlength="3"><font size="1"><span class="style1"> ( max 3 characters )</span></font></td></tr><tr><td colspan="2"><span class="txt-ast">*</span>Project Description: <input name="project_description" type="text" class="txtbox" size="30" maxlength="30"><font size="1"><span class="style1"> ( max 30 characters )</span></font></td></tr><tr><td colspan="2"><span class="txt-ast">*</span>County: <input name="county" type="text" class="txtbox" size="30" maxlength="30"><font size="1"><span class="style1"> ( max 30 characters )</span></font></td></tr><tr><td height="32" colspan="2">State, City, River Basin: <input name="region" type="text" class="txtbox" size="30" maxlength="30"></td></tr><tr><td height="32" colspan="2"><span class="txt-ast">*</span>Client: <input name="client" type="text" class="txtbox" size="30" maxlength="30"><font size="1"><span class="style1"> ( max 30 characters )</span></font></td></tr><tr><td colspan="2" align="left" valign="top"> </td></tr><tr><td colspan="2"><center><INPUT TYPE=HIDDEN NAME="PHORM_CONFIG" VALUE="pilconfig.php"><input name="add" type="submit" id="add" value="Add New Project"></center></td></tr><tr><td colspan="2"><center><span class="txt-ast">* <font size="1">are field that MUST be completed.</font></span></center></td></tr></table></form>[/code] Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-135195 Share on other sites More sharing options...
jcbarr Posted December 5, 2006 Share Posted December 5, 2006 I believe you have another thread about the same thing. They are on track in that one. You really shouldn't post two threads for the same question. Link to comment https://forums.phpfreaks.com/topic/28666-pull-down-list-from-mysql/#findComment-135247 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.