MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 18th, 2002, 10:13 AM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via AIM to steve55 Send a message via Yahoo to steve55
Exclamation Drop Down Menu - populated from a mysql database

Hi,



I have a table in a database and I would like to populate a dropdown menu with some fields from this table, so that a user can select from them and then a search or a display page would be produced on the basis of their selections.....

I am fairly new to php, but have a MySQL database to which I can add/edit/del and produce results from, but am unsure how to do the above..

All help appreciated - please can you make any replies easy to follow..!

Thank You

Reply With Quote
  #2  
Old December 18th, 2002, 11:17 AM
chakotha chakotha is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 2 chakotha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try something along the lines of:

PHP Code:
<?
...
mysql cnx code
...

$sql="SELECT id, thing FROM table";
$result=mysql_query($sql);

$options="";

while (
$row=mysql_fetch_array($result)) {

    
$id=$row["id"];
    
$thing=$row["thing"];
    
$options.="<OPTION VALUE=\"$id\">".$thing;
}
?>
...
html code
...

<SELECT NAME=thing>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT>
...


Hope that helps

Last edited by chakotha : December 18th, 2002 at 03:17 PM.

Reply With Quote
  #3  
Old December 19th, 2002, 03:29 AM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via AIM to steve55 Send a message via Yahoo to steve55
Hi,


Thanks for the reply - it was spot on. I have used your code, which was very easy to understand and have now got a drop down menu which is populated from my database.

However currently it doesn't do anything as yet..

I would also like to add a second drop down menu and possibly even a third.... One menu might be a country, one a town, and one a village for example and then based on their selections after hitting a submit button a page would be returned showing an entrie(s) from the database that match their 'search' criteria as they selected from the drop down menus....

Yet again I haven't a clue how to do this - I could presumably populate the drop down menus now, but wouldn't know how to link them up to produce a results page..

Any more help would be greatly appreciated!

Reply With Quote
  #4  
Old December 23rd, 2002, 03:50 PM
wap wap is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 20 wap User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'm new to php myself but use something similar on my site when doing a search and use the following code assuming the 3 dropdown boxes are named a, b and c

PHP Code:
 $query_aConnection "SELECT * FROM tablename
WHERE field1='
$_GET[a]
AND field2='
$_GET[b]
AND field3='
$_GET[c]
ORDER BY id DESC"



Like I say i'm new to scripting so someone may have a better solution but the above works for me.

Reply With Quote
  #5  
Old March 4th, 2004, 11:03 PM
cygtoad cygtoad is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 cygtoad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Wink

Quote:
Originally Posted by chakotha
PHP Code:
<?
...
mysql cnx code
...

$sql="SELECT id, thing FROM table";
$result=mysql_query($sql);

$options="";

while (
$row=mysql_fetch_array($result)) {

    
$id=$row["id"];
    
$thing=$row["thing"];
    
$options.="<OPTION VALUE=\"$id\">".$thing;
}
?>
...
html code
...

<SELECT NAME=thing>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT>
...


Hope that helps



Reading this post answered my questions, however, if it is going to function as intended for input, you will need to close the option tag like this:

$options.="<OPTION VALUE=\"$id\">".$thing.'</option>';

The former produces a dropdown but won't produce legitimate code for picking a value for input into the database. I played with this a bit before I figured it out. I thought I would post to save others some time.

Reply With Quote
  #6  
Old March 5th, 2004, 02:57 AM
chakotha chakotha is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 2 chakotha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Damn you're dead right - hope not too much confusion caused!

Also it would be better to use

<SELECT NAME=id>

Reply With Quote
  #7  
Old January 27th, 2005, 10:42 PM
smudge smudge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 2 smudge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 28 m 7 sec
Reputation Power: 0
Eureka.

I'm new to php/mysql... but I've gotten this to work... kinda.

The code, as present, works fine. I have a page that draws from multiple tables into multiple different dropdown boxes.
This is an admin page that will allow an admin to create characters on the fly for a MMO. The admin will input things such as name, age, etc himself, but will use the dropdown boxes to select from a set of predefined options.

For instance, one my tables is 'occupation'. I want the admin to be able to choose an occupation from all the selections in this table. The table is lined out as such:

typeID / name / description
1 / artist / I paint stuff.
2 / janitor / I clean stuff
3 / boxer / I hit stuff

I have a page addCharacter.php that populates a dropdown box with the 'name'(s) of the occupations listed in table 'occupation'.

What I'm having difficulty doing, is when the admin chooses a profession for his character, I need it to create a character and assign the corresponding 'occupationID" into the 'occupation' in the 'characters' table.

For instance. Each character in my 'character' table has the following:

characterID / name / age / occupation

a record might look like this:

1 / Mike Tyson / 34 / 3

.. where the '3' in the in 'occupation' column of the 'characters' table is a foreign key to 'occupationID' in the 'occupation' table and actually represents 'boxer'.

Does this make sense? Confusing I know.

So, the problem I'm having, is when the admin selects 'boxer' when they are creating a character, I need my form to input in the 'character' table the value '3' in the 'occupation' column... and I can't get it to do that.. it just enters a '0'. (I can, however, get all other records to update i.e. name, age, etc. I can create a new character just fine.. I just cannot get that value to input correctly).

Here is the code I have:
//this code is bringing in the values for the dropdown.
$sql="SELECT name FROM occupation";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$id2=$row["occupationId"];
$occupationName=$row["name"];
$options.="<OPTION VALUE=\"$id2\">".$occupationName.'</option>';


<br>Name:
<br><input type="text" name="name" <?php echo "value=\"$name\"" ?>>
<br>
<br>Age:
<br><input type="text" name="age" <?php echo "value=\"$age\"" ?>>
<br>
<br>Occupation:
<br><SELECT NAME=id2>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT>
<br>


Again... I need the corresponding numeral value of whatever occupation the user selects to be entered into the table.. not the name of the occupation. So if the admin creates 'janitor', I need the value '2' input into the characters 'occupation' column in the 'characters' table.

Thanks in advance for your help.. sorry for the lengthy explanation.

Reply With Quote
  #8  
Old January 28th, 2005, 12:00 AM
smudge smudge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 2 smudge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 28 m 7 sec
Reputation Power: 0
*sigh*

Happens more than I care to admit.. but I figured this out about an hour after posting this.

Thanks!!

Reply With Quote
  #9  
Old February 11th, 2005, 12:26 PM
Sneef Sneef is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 1 Sneef User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 49 sec
Reputation Power: 0
Needed echo

Had an "unexpected =" when using your code at:

<OPTION VALUE=0>
-> <?php=$options?>
</select></td>

So I replaced the "=" with "echo" (I'm a noob, so let me know if this is wrong) to get this:

<OPTION VALUE=0>
<?php echo $options ?>
</select></td>


Works fine for me now, I just hope it returns both "id" and "thing" in the array itself.

Reply With Quote
  #10  
Old May 26th, 2005, 09:31 AM
stubbsini stubbsini is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 8 stubbsini User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 47 m 15 sec
Reputation Power: 0
I tried this using the following code, but didn't get anything other than a value of 'Choose' in my dropdown box:

Code:
<?
  
  $sql="SELECT id, name FROM artist";
  $result=mysql_query($sql);
  
  $options="";
  
  while ($row=mysql_fetch_array($result)) {
  
  	$id=$row["id"];
  	$name=$row["name"];
  	$options.="<OPTION VALUE=\"$id\">".$name.'</option>';
  }
  ?>
  
  <SELECT NAME=id>
  <OPTION VALUE=0>Choose
  <? echo $options?>
  </SELECT>


The table I am trying to connect to is called artist, and has the two fields (id and name). Is it something obvious that I'm missing here?

*I have tried this without the single quotes around </option>
*I have tried this with = instead of echo

Reply With Quote
  #11  
Old June 25th, 2007, 01:42 PM
sublime82 sublime82 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2007
Location: Washington D.C.
Posts: 1 sublime82 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 46 sec
Reputation Power: 0
Greetings,

I would greatly appreciate any help on this problem I am having.

...Here is the working code that I currently have for creating a drop down menu that is populated by a table...

PHP Code:
 $sqlOptions "SELECT title, id FROM table";
    
$resultOptions mysql_query($sqlOptions);
    
$example[] = mosHTML::makeOption('X'"Select a Category");
    
    while(
$opt mysql_fetch_array($resultOptions))
        {
            
$example[] = mosHTML::makeOption($opt['id'], $opt['title']);
        }    
    
$lists["tableid"] = mosHTML::selectList($example"text"'class="inputbox" 
size="1"'
"value""text"$opt['title']);
    unset(
$example); 


...Here is the code that displays the drop down menu...

PHP Code:
<?php echo $lists['tableid']; ?>


Here is my question... Does anyone know how to turn this piece of code into a multiple drop down menu?

Meaning a user would select an option from the first drop down menu. Based off of that users selection another drop down menu would populate from a table underneath of it.

For example a user selects a State, then is able to select a city located inside of that state, then is able to select an area code within that city... Something along those lines.

So essentially all three menu's are populated from tables in a database, but the queries for those drop down menu's are based off of drop down menu selections.

I would greatly appreciate any solutions if available.

Reply With Quote
  #12  
Old October 21st, 2007, 09:39 PM
Entity Entity is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 11 Entity User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 47 sec
Reputation Power: 0
Send a message via MSN to Entity
Im having trouble with this script. The info gets put into the variable fine enough, but while in a certain area of the page, it doesn't get added to the box. heres a copy of what i have...
Code:
                        foreach($category['games'] as $game){
                        
                                echo '<tr>
                                        <td'.$class.' style="width:6%">'.$game['gId'].'</td>
                                        <td'.$class.'>'.$game['gName'].'</td>
                                        <td'.$class.'>'.$game['gSwfFile'].'</td>
                                        <td'.$class.' style="width:8%">';
                                        
                                        if($game['gVisible'] == 1){
                                                echo 'yes <a href="?cmd=dovisible&gid='.$game['gId'].'&value=0">Hide</a>';
                                        } else {
                                                echo 'no <a href="?cmd=dovisible&gid='.$game['gId'].'&value=1">Show</a>';
                                        }
                                        
                                        echo '</td>
                                        <td'.$class.'>'.$game['Played'].' times  <a href="'.$_SERVER['PHP_SELF'].'?cmd=reset&id='.$game['gId'].'">(Reset)</a></td>
                                        <td'.$class.' style="width:7%"><a href="'.$_SERVER['PHP_SELF'].'?cmd=delg&id='.$game['gId'].'">Delete</a></td>
                                        <td'.$class.' style="width:10%"><a href="'.$_SERVER['PHP_SELF'].'?cmd=upg&id='.$game['gId'].'">Up</a> | 
                                        <a href="'.$_SERVER['PHP_SELF'].'?cmd=downg&id='.$game['gId'].'">Down</a></td>
                                        <td>
                                        <select name="id">
                                        <?php echo $catopts?>
                                        </select>
                                        </td>
                                </tr>';
                        
                        }
                        
                        echo '</table>';

Catops is the variable with the info. When i tried this at the end of the page, outside of everything, it worked fine.
Also, how do i DO things with this? IE i want to make a button that applies the settings when pushed.

Reply With Quote
  #13  
Old March 3rd, 2009, 04:56 PM
justasiam justasiam is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 11 justasiam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 38 sec
Reputation Power: 0
Quote:
Originally Posted by chakotha
[PHP]$sql="SELECT id, stock_no FROM table";
$result=mysql_query($sql);

$options="";

while ($row=mysql_fetch_array($result)) {

$id=$row["id"];
$thing=$row["stock_no"];
$options.="<OPTION VALUE=\"$id\">".$thing.'</option>';
}
?>
...
html code
...

<SELECT NAME=stock_no>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT>

?>

OK, I can see why you use the $id, it is because that is the primary field in the table. In my case, the "stock_no" field is the primary one. I want to make a drop-down menu populated by what is in the "stock_no" field. Currently, there are 580 rows. How can I modify your code to work for me?

Reply With Quote
  #14  
Old March 3rd, 2009, 05:28 PM
justasiam justasiam is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 11 justasiam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 38 sec
Reputation Power: 0
OK, I am using this code to pull all the values of the "stock_no" field in my database and display it as a pull-down list.
Code:
<?php

require_once('../Catalog/incl_productlist_dbconnect.php');
require_once('../Catalog/incl_productlist_variables.php');

mysql_connect($hostname, $username, $password) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname);

$sql="SELECT stock_no FROM $usertable";
$result=mysql_query($sql);

$options="";

while ($row=mysql_fetch_array($result)) {

    $StockNo=$row["stock_no"];
    $options.="<OPTION VALUE=\"$StockNo\">".$StockNo.'</option>';
}
?>
			<SELECT NAME=stock_no><OPTION VALUE=0>Choose<?=$options?></SELECT>

The question is "How do I do this same thing in another field and automatically strip away all duplicate values?". You see, I have another field named "sub_cat". Many of the items in the db contain the same value in this field. I want to generate a pull-down list and remove all the duplicates.

Can this be done?

Reply With Quote
  #15  
Old March 8th, 2009, 09:34 PM
clmirand clmirand is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 1 clmirand User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 0
Quote:
Originally Posted by justasiam
OK, I can see why you use the $id, it is because that is the primary field in the table. In my case, the "stock_no" field is the primary one. I want to make a drop-down menu populated by what is in the "stock_no" field. Currently, there are 580 rows. How can I modify your code to work for me?




hi there, i tried using/testing the code starting from the first one but in every tests i did, i encounter this error,
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\drop_down_menu.php on line 8

hope you could help me

Thanks,

Reply With Quote
  #16  
Old November 17th, 2009, 08:52 AM
vyjayanth vyjayanth is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 1 vyjayanth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 52 sec
Reputation Power: 0
order data from mysql to drop down and send to another table

Hi, I have this code where I call phy names from User data table and display it in a drop down box, now when I select multiple physicans and save The data gets stored in some format with the Physician Ids. But when I save and reselect that persons details, the previous selected physicians donot show up. Please help me with a for loop or something so that I can do it
The insertion procedure for rest is done as stated 'Insertion' below


I have added
$_post['Refer_to_phy'] = serialize ($_post['Refer_to_phy'] );
$_post['Refer_to_phy'] = htmlentities($_post['Refer_to_phy'] );

<select name="Refer_to_phy" multiple="multiple" class='text_9' style="width:150px" size="6">
<option value=''>--Select Physicians--</option>
<?php
$vquery_c = "select * from users order by id";
$vsql_c = mysql_query($vquery_c);

while($vrs=mysql_fetch_array($vsql_c))
{
$pro_ty=$vrs["user_type"];
if($pro_ty==1){
$phyName_drop = $vrs['fname'];
if($vrs['fname'] != '' && $vrs['lname'] != ''){
$phyName_drop = $vrs['lname'].', '.$vrs['fname'];
}
else if($vrs['fname'] == '' && $vrs['lname'] != ''){
$phyName_drop = $vrs['lname'];
}
$phyName_drop .= $vrs['mname'];
echo "<option value='$vrs[id]' $sel >".trim(ucwords($phyName_drop))."</option>";
$sel='';
}
}
?>


</select>

Insertion
$insert_id = $objManageData->AddRecords($_POST,'refferPhysician');

function AddRecords($fieldName,$tableName){
$fieldsName = array();
$values = array();
echo 'Skey';
foreach($fieldName as $key => $val){
$fieldname = $val;

$chkStr = substr($key,0,3);
if($chkStr != 'txt') {
$fieldsName[] = $key.'';
$values[] = "'".addslashes($val)."'";
}
}
$fieldsName = implode(",",$fieldsName);
$values = implode(",",$values);
$insertQuery = "Insert into $tableName ($fieldsName) Values ($values)";
$qryId = $this->query($insertQuery);
$inserID = $this->insertID();
return $inserID;
}

Reply With Quote
  #17  
Old December 15th, 2009, 07:19 AM
maishatsana maishatsana is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2009
Posts: 1 maishatsana User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 28 sec
Reputation Power: 0
Populate drop down onchange of another dropdown

I'm new to php and i want to populate a dropdown onchange of another drop down.

For eg. I have Country dropdown onChange of this i want to populate states drop down.


<?php

$server = "localhost";
$username = "root";
$password = "";
$db_name = "test";
$db = mysql_connect($server,$username,$password) or DIE("Connection to database failed, perhaps the service is down !!");
mysql_select_db($db_name,$db) or DIE("Database name not available !!");
$sql="SELECT CID,CountryName FROM countries";
$result=mysql_query($sql);
$optionscountry="";
if(mysql_num_rows($result))
{
// we have at least one user, so show all users as options in select form
while($row = mysql_fetch_row($result))
{
$optionscountry.="<option value=\"$row[0]\">$row[1]</option>";

}
}
else
{
$optionscountry.="<option value=\"\">No users created yet</option>";
}
if(isset($_POST['states'])
$optionsstates= $_POST['states'];

function generateState($countryID)
{
echo $countryID;
$sql="SELECT StateID,StateName FROM states where CID=".$countryID;
$result=mysql_query($sql);

if(mysql_num_rows($result))
{
// we have at least one user, so show all users as options in select form
while($row = mysql_fetch_row($result))
{
$optionsstate.="<option value=\"$row[0]\">$row[1]</option>";

}
}
else
{
$optionsstate.="<option value=\"\">No users created yet</option>";
}

}
?>
<html>
<head></head>
<body>
<div>
<select name="countryDropDown" onChange="generateState(this.form)">
<OPTION VALUE=0 >Select Country
<?php echo $optionscountry?>
</select>
<select name="stateDropDown">
<OPTION VALUE=0 >Select State
<?php echo $optionsstate?>
</select>
</div>

</body>
</html>


In the above code i have generatestate() function so how to invoke it from client side.

Any help would be appreciated.

Thanks,

Sana

Reply With Quote
  #18  
Old January 2nd, 2010, 09:34 PM
akhilesh890 akhilesh890 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 1 akhilesh890 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 12 sec
Reputation Power: 0
connecting dropdown box to mysql database

I am doing a project on airline management system.Being reletively new to php and database,can anyone tell me how to connect my dropdown box contents to that in my MySQL database using PHP5?
the structure of my database is:
S.NO(int) FROM(varchar) TO(varchar) DEP(time) ARR(time) FARE(int)


I need 2 dropdownboxes - from and to which will be the data stored in my database FROM and TO.Help is much appreciated.

Reply With Quote
  #19  
Old January 16th, 2010, 08:39 PM
nareshrana nareshrana is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 1 nareshrana User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 24 sec
Reputation Power: 0
Quote:
Originally Posted by akhilesh890
I am doing a project on airline management system.Being reletively new to php and database,can anyone tell me how to connect my dropdown box contents to that in my MySQL database using PHP5?
the structure of my database is:
S.NO(int) FROM(varchar) TO(varchar) DEP(time) ARR(time) FARE(int)


I need 2 dropdownboxes - from and to which will be the data stored in my database FROM and TO.Help is much appreciated.


You can use a very simple code.
e.g.
<?php
$database="DBNAME";
mysql_connect ("localhost", "root", "");(or use exact "ip/hostname","username to login to DB","Password if any")
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "SELECT feildname1,fieldname2 FROM tablename" )
or die("SELECT Error: ".mysql_error());
$options="";
while ($row=mysql_fetch_array($result)) {

$firstvalue=$row["fieldname1"];
$secondvalue=$row["fieldname2"];
$options.="<OPTION VALUE=\"$firstvalue\">".$firstvalue.'</option>';
$options1.="<OPTION VALUE=\"$secondvalue\">".$secondvalue.'</option>';

}

<SELECT NAME=p>
<OPTION VALUE=0>
<?php echo $options?>
</SELECT>
<SELECT NAME=q>
<OPTION VALUE=0>
<?php echo $options1?>
</SELECT>

I think, this should work for you.

Reply With Quote
  #20  
Old April 12th, 2010, 01:05 AM
Punitha Punitha is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2010
Posts: 2 Punitha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 49 sec
Reputation Power: 0
Hi all,

I too new for PHP. I had learned lot of information's from this thread. Thanks.

Reply With Quote
  #21  
Old May 17th, 2010, 12:25 PM
Frankenfine Frankenfine is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2010
Posts: 1 Frankenfine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 26 sec
Reputation Power: 0
I have the dropdown list working , thanks.

But how do I enable ACTION to link to new page of content?
I have a menu with this linking function:

$menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />';

but how do I enable this within the <SELECT> HTML function?

Reply With Quote
  #22  
Old June 5th, 2010, 01:06 AM
Techboy Techboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 2 Techboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 38 sec
Reputation Power: 0
Select user from dropdown and send a preconfigured email

Hi there this script looks like some thing that can be used with a little exstra code to send a email to an user in the database any one who can make a working script to do this??

The script will be used to send a confirmation email for a payd item then user comes back from paypal. I have a cokie script to insure that the user is come from right place. A user in the database shal resieve the email that the Item is payed.

If possible make oppinity for the customer to write a little message for user too will be ekstra nice.

and maybe store the information in a table in the database

I will be very pleased if possible.

Thx in advance

Brian Olsen

Reply With Quote
  #23  
Old July 10th, 2010, 08:06 AM
bennyjon bennyjon is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2010
Posts: 1 bennyjon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 23 sec
Reputation Power: 0
Hello,

I am quite new in PHP. I want to populate two items from the database table voyage. That is avoyage_no and vessel_name. When avoyage_no list is clicked I need to list the vessel_name also in the same list menu, but the value vessel_name to be passed to the vessel_name list after the avoyage_no selection is made. After that based on this selection I need to populate other columns from the table in the head field. I tried to populate avoyage_no and vessel with the following code. But the values doesn't come. Can any body help?

<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="POST">
<table width="849" border="1">
<tr>
<td width="140" height="29">Book ID </td>
<td width="199"><input name="voyage_id" type="text" id="voyage_id" /></td>
<td width="37">Week</td>
<td width="218">&nbsp;</td>
<td width="58">Date</td>
<td width="157"><input name="bk_date" type="text" id="bk_date" /></td>
</tr>
</table>
<table width="849" border="1">
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("benny",$con);
$sql="select voyage.avoyage_no,voyage.vessel_id,vessel.vessel_n ame,
vessel.vessel_id from voyage,vessel where vessel.vessel_id=voyage.vessel_id";

$result=mysql_query($sql);

$options="";

While ($row=mysql_fetch_array($result)) {

$avoyage=$row["avoyage_no"];

$vsl_name=$row["vessel_name"];

$options.="<OPTION VALUE=\"$avoyage\">".$vsl_name;
}
?>
<tr>
<td width="160">Schedule Voyage</td>
<td width="48"><select name=avoyage_no>
<OPTION VALUE=0>Choose
<?=$options?>
</select></td>
<td width="73">Vessel</td>
<td width="126"><select name="select">
</select></td>
<td width="144"><input name="week_no" type="text" id="week_no" /></td>
<td width="44">ETA</td>
<td width="208"><input name="eta" type="text" id="eta" /></td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>

Reply With Quote
  #24  
Old December 21st, 2010, 09:47 AM
Fletch Fletch is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2010
Posts: 1 Fletch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m
Reputation Power: 0
Red face I have a closely related problem with Drop Down + Mysql & selecting

Hi Guys, I am new to this forum so forgive if I should have posted somewhere else.....

I have a project that I have been working on for sometime and a recent problem which I have search long and hard on the net for a solution:

in my php / html page I have a Drop Down list which I populate with a php script accessing mysql and giving me the list of tables in a database (Simples yes?) So no problems there:

Here's the Script for this part:
<select name="TableName2" size="1" id="TableName2">
PHP Code:
<?php $host 'Localhost'$pass '*****'$user '****';
mysql_connect($host$user$pass) or die("Username '$username' or Password ******* incorrect:"); mysql_select_db("Packhouse") or die(mysql_error()); $result mysql_query("SHOW Tables FROM Packhouse") or die(mysql_error()); while ($row mysql_fetch_array($result)) { 
echo 
'<option value="' $row['Tables_in_Packhouse'] . '">' $row['Tables_in_packhouse'] . '</option>';};?>
</select>
Code end:

Okay the problem I'm having is that when I select from the list
and then press my Submit buttom the data in the rest of the form posts to the Action PHP page just fine but the Value selected in the Dropdown did not post, suggesting that no value was captured

I have been going around in circles with this problem for days now please please please can anyone help me

I am not a programmer and really just learning on the fly to be honest and appreciate any help that comes my way.

Fletch

Reply With Quote
  #25  
Old April 15th, 2011, 03:15 PM
jvance38 jvance38 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2011
Posts: 2 jvance38 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 50 sec
Reputation Power: 0
I'm having this same problem, did you get any response to this thread

I'm having the same problem and was wondering if any responses came in regarding this thread?

Quote:
Originally Posted by stubbsini
I tried this using the following code, but didn't get anything other than a value of 'Choose' in my dropdown box:

Code:
<?
  
  $sql="SELECT id, name FROM artist";
  $result=mysql_query($sql);
  
  $options="";
  
  while ($row=mysql_fetch_array($result)) {
  
  	$id=$row["id"];
  	$name=$row["name"];
  	$options.="<OPTION VALUE=\"$id\">".$name.'</option>';
  }
  ?>
  
  <SELECT NAME=id>
  <OPTION VALUE=0>Choose
  <? echo $options?>
  </SELECT>


The table I am trying to connect to is called artist, and has the two fields (id and name). Is it something obvious that I'm missing here?

*I have tried this without the single quotes around </option>
*I have tried this with = instead of echo

Reply With Quote
  #26  
Old June 28th, 2011, 09:34 PM
shpemu shpemu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 2 shpemu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 23 sec
Reputation Power: 0
Quote:
Originally Posted by jvance38
I'm having the same problem and was wondering if any responses came in regarding this thread?


Check your code; when I post my PHP code, I don't mix single-quotes and double-quotes, you might try using one or the other:

Instead of this:
Code:
$options.="<OPTION VALUE=\"$id\">".$name.'</option>';


Try this:
Code:
$options.="<OPTION VALUE=\"$id\">$name</option>";

and see what happens. Also, you may want to altar this line:
Code:
<?=$options?>

to look like this:
Code:
<?=$options; ?>

I've had people tell me these changes are no big deal, but in my experience it's made a difference.

Reply With Quote
  #27  
Old June 28th, 2011, 09:44 PM
shpemu shpemu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 2 shpemu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 23 sec
Reputation Power: 0
"Selected" options

I'm having difficulty with getting an item previously selected to list as selected in a dropdown. For instance, if a user picks AZ as their state in a state dropdown, then they want to go back and edit their info, the dropdown doesn't recognize that AZ was their choice; I can't get the code to work right. Here's a sample of the code (this works, but the dropdown doesn't 'select' the previously chosen state):
Code:
<? $pop_states="SELECT form_value, form_name 
FROM CustomerForm where form_group = 'States' 
ORDER BY form_name";
$pop_states_result=mysql_query($pop_states);
$state_options="";
while ($staterow=mysql_fetch_array($pop_states_result)) {
	$form_value=$staterow["form_value"];
	$form_name=$staterow["form_name"];
	$state_options.="<option value=\"$form_value\">$form_name</option>";
} ?>


I've tried posting the code in this manner:
Code:
<? $state=$_GET['state'];
$pop_states="SELECT form_value, form_name 
FROM CustomerForm where form_group = 'States' 
ORDER BY form_name";
$pop_states_result=mysql_query($pop_states);
$state_options="";
while ($staterow=mysql_fetch_array($pop_states_result)) {
	$form_value=$staterow["form_value"];
	$form_name=$staterow["form_name"];
	if($form_value == $state){
		$selected = " selected";
	} else { ($form_value == $state){
		$selected = "";
	}
	$state_options.="<option $selected value=\"$form_value\">$form_name</option>";
} ?>

and a few variations of this, but the result is the entire page is blank. Any suggestions would be greatly appreciated.

Reply With Quote
  #28  
Old November 15th, 2011, 07:22 AM
Pat43Da2 Pat43Da2 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 1 Pat43Da2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 19 sec
Reputation Power: 0
thank you for sharing

Reply With Quote
  #29  
Old November 21st, 2011, 10:03 PM
James42 James42 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 5 James42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 56 sec
Reputation Power: 0
Damn you're dead right - hope not too much confusion caused!

Also it would be better to use[img](URL address blocked: See forum rules)[/img]
[img](URL address blocked: See forum rules)[/img]
[img](URL address blocked: See forum rules)[/img]

Reply With Quote
  #30  
Old December 6th, 2011, 02:07 AM
LallingerD LallingerD is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 2 LallingerD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 12 sec
Reputation Power: 0
Thanks for the reply - it was spot on.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Drop Down Menu - populated from a mysql database


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap