Re: [PHP-DB] Drop-down box in php
From: andy amol I am using the following code, but it is not populating my script. If you can help I would be grateful. I am using mysql as database. ? $sql = SELECT course_id FROM course; $sql_result = mysql_query($sql) or die(Couldn't execute query.); while ($row = mysql_fetch_array($sql_result)) { $type = $row[course_id]; $typedesc =$row[dept_id]; $option_block .= OPTION value=\$type\$typedesc/OPTION; You're using [dept_id], but not selecting that column in your query. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Drop-down box in php
I use html forms with select field size 1 and the option values and/or what is supposed to appear in the box. This you populate by your DB query, maybe using an array and a loop (from 0 to ..). Torsten andy amol schrieb: hi, I would like to know how to create and populate drop down boxes in php. I want the value to be populated from database. What I am try to do is to provide the forign key value as combo box option, so that I do not have to check for referential integrity. Also if you can help me with a date validation program I will be grateful. Thanks in advance. - Do you Yahoo!? Yahoo! Photos: High-quality 4x6 digital prints for 25¢ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Drop-down box in php
You mean select/select html dropdown-s? print 'select name=sg'; $r = mysql_query(SELECT id, field1, fieldn FROM table WHERE fieldn = 'sg'); while($RESULT = mysql_fetch_array($)) { print 'option value='.$RESULT['id'].''.$RESULT['fieldn']'./option'; } print '/select'; Validating: just check the $_POST['sg'] value, against is_numeric(), then you can do a SELECT, to check whether the id exists. You can find some more examples, on php net manual pages andrej andy amol wrote: hi, I would like to know how to create and populate drop down boxes in php. I want the value to be populated from database. What I am try to do is to provide the forign key value as combo box option, so that I do not have to check for referential integrity. Also if you can help me with a date validation program I will be grateful. Thanks in advance. - Do you Yahoo!? Yahoo! Photos: High-quality 4x6 digital prints for 25¢ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Drop-down box in php
From: andy amol [EMAIL PROTECTED] I would like to know how to create and populate drop down boxes in php. I want the value to be populated from database. What I am try to do is to provide the forign key value as combo box option, so that I do not have to check for referential integrity. You still have to check. Just because you provide a discreet number of options in a select box doesn't mean that's really all the user can choose from. There are many ways to manipulate the data. That being said, just create a loop as you draw items from your database. ?php echo 'select name=something size=1'; $sql = SELECT name FROM products WHERE ...; $result = query($sql); while($row = fetch_assoc($result)) { echo option value=\{$row['name']}\{$row['name']}/option\n; } echo /select; I don't know what database you're using, so query() and fetch_assoc() are generic. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Drop-down box in php
If it is a MySWL database, the following code works great ? $sql = select choice, description from views; $result = mysql_query($sql) or die(mysql_error()); $viewing = ; $viewing .= select name=\view_code\\n; while ($view_list = mysql_fetch_array($result)) { $view_code = $view_list[choice]; $view_desc = stripslashes($view_list[description]); $viewing .= option value=\$view_code\$view_desc/option\n; } $viewing .= /select; ? Of course you'll have to change it to fit your needs, but I just have a while loop that gets the information and then dumps each line it gets out to a temp variable. On the pages that include this one is where the displaying comes out. HTH, Robert -Original Message- From: andy amol [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 20, 2004 11:53 AM To: David Robley; [EMAIL PROTECTED] Subject: [PHP-DB] Drop-down box in php hi, I would like to know how to create and populate drop down boxes in php. I want the value to be populated from database. What I am try to do is to provide the forign key value as combo box option, so that I do not have to check for referential integrity. Also if you can help me with a date validation program I will be grateful. Thanks in advance. - Do you Yahoo!? Yahoo! Photos: High-quality 4x6 digital prints for 25¢ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Drop-down box in php
hi, I am using the following code, but it is not populating my script. If you can help I would be grateful. I am using mysql as database. ? $sql = SELECT course_id FROM course; $sql_result = mysql_query($sql) or die(Couldn't execute query.); while ($row = mysql_fetch_array($sql_result)) { $type = $row[course_id]; $typedesc =$row[dept_id]; $option_block .= OPTION value=\$type\$typedesc/OPTION; } ? SELECT name=selecttype id=selecttype ? echo $option_block; ? /SELECT thanks. John W. Holmes [EMAIL PROTECTED] wrote: From: andy amol I would like to know how to create and populate drop down boxes in php. I want the value to be populated from database. What I am try to do is to provide the forign key value as combo box option, so that I do not have to check for referential integrity. You still have to check. Just because you provide a discreet number of options in a box doesn't mean that's really all the user can choosefrom. There are many ways to manipulate the data.That being said, just create a loop as you draw items from your database.echo ''; $sql = SELECT name FROM products WHERE ...; $result = query($sql); while($row = fetch_assoc($result)) { echo {$row['name']}\n; } echo ; I don't know what database you're using, so query() and fetch_assoc() are generic. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php - Do you Yahoo!? Yahoo! Photos: High-quality 4x6 digital prints for 25¢
Re: [PHP-DB] Drop down box NOT populated
Jsut a guess... Your row has a capital 'A' in the SQL statement, and a lower case 'a' in teh $row[] call.. does that matter? Larry Sandwick [EMAIL PROTECTED] 22/01/2004 15:46 Please respond to [EMAIL PROTECTED] To [EMAIL PROTECTED] cc Subject [PHP-DB] Drop down box NOT populated Can anyone tell me what I am missing here, The Select statement does not populate my drop down window? My drop down box is empty ! [snip] ? include '../db.php'; $how = mysql_query(SELECT count(distinct(account)) from Backlog) or die (Something bad happened: . mysql_error()); $how_many = mysql_result($how, 0); echo h3$how_many Accounts to pick from !!!/h3; $sql = mysql_query(SELECT distinct(Account) FROM Backlog)or die (Something bad happened here: . mysql_error()) ; echo select name=\account\\n; echo option\n; while ($row = mysql_fetch_array($sql)) { echo ' option value='.$row[account].''.$row[account]./option\n; } echo /select\n; ? [end snip] Larry Sandwick Sarreid, Ltd. Network/System Administrator phone: (252) 291-1414 x223 fax : (252) 237-1592 * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. ***
Re: [PHP-DB] Drop down box NOT populated
From: [EMAIL PROTECTED] Jsut a guess... Your row has a capital 'A' in the SQL statement, and a lower case 'a' in teh $row[] call.. does that matter? Yep, that would matter, but not the exact problem. I don't know if this thread has already been answered or not, so... The real problem is with this: $sql = mysql_query(SELECT distinct(Account) FROM Backlog)or die (Something bad happened here: . mysql_error()) ; echo select name=\account\\n; echo option\n; while ($row = mysql_fetch_array($sql)) { echo ' option value='.$row[account].''.$row[account]./option\n; because there is no account index in $row. You're not selecting account, you're selecting distinct(Account). So, you could do it the hard way and use $row['distinct(Account)'] as your value or change your SQL to: $sql = mysql_query(SELECT distinct(Account) AS acc FROM Backlog)or die and use $row['acc']. This is called making an alias. You alias the distinct(account) column to be called acc. You can name the alias what ever you want. If you developed with your error_reporting() set to E_ALL, you'd have gotten a notice about Undefined index 'account' in $row that may have tipped you off to all of this. Hope this helps. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Drop down box NOT populated
Instead of: $row = mysql_fetch_array($sql) Use: $row = mysql_fetch_assoc($sql) Humberto Silva World Editing Portugal -Original Message- From: John W. Holmes [mailto:[EMAIL PROTECTED] Sent: sexta-feira, 23 de Janeiro de 2004 15:42 To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Drop down box NOT populated From: [EMAIL PROTECTED] Jsut a guess... Your row has a capital 'A' in the SQL statement, and a lower case 'a' in teh $row[] call.. does that matter? Yep, that would matter, but not the exact problem. I don't know if this thread has already been answered or not, so... The real problem is with this: $sql = mysql_query(SELECT distinct(Account) FROM Backlog)or die (Something bad happened here: . mysql_error()) ; echo select name=\account\\n; echo option\n; while ($row = mysql_fetch_array($sql)) { echo ' option value='.$row[account].''.$row[account]./option\n; because there is no account index in $row. You're not selecting account, you're selecting distinct(Account). So, you could do it the hard way and use $row['distinct(Account)'] as your value or change your SQL to: $sql = mysql_query(SELECT distinct(Account) AS acc FROM Backlog)or die and use $row['acc']. This is called making an alias. You alias the distinct(account) column to be called acc. You can name the alias what ever you want. If you developed with your error_reporting() set to E_ALL, you'd have gotten a notice about Undefined index 'account' in $row that may have tipped you off to all of this. Hope this helps. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Drop down box NOT populated
From: Humberto Silva [EMAIL PROTECTED] Instead of: $row = mysql_fetch_array($sql) Use: $row = mysql_fetch_assoc($sql) While I'm in the habit of doing that, using fetch_array() isn't going to cause any problems with regard to the original post. Which one you use is really a matter of personal opinion and rarely affects the code. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Drop down box NOT populated
I confess i didn't read the original post ... You're absolutely right ... Humberto Silva World Editing Portugal -Original Message- From: John W. Holmes [mailto:[EMAIL PROTECTED] Sent: sexta-feira, 23 de Janeiro de 2004 16:03 To: Humberto Silva Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Drop down box NOT populated From: Humberto Silva [EMAIL PROTECTED] Instead of: $row = mysql_fetch_array($sql) Use: $row = mysql_fetch_assoc($sql) While I'm in the habit of doing that, using fetch_array() isn't going to cause any problems with regard to the original post. Which one you use is really a matter of personal opinion and rarely affects the code. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Drop down box NOT populated
Larry Sandwick wrote: Can anyone tell me what I am missing here, The Select statement does not populate my drop down window? My drop down box is empty ! ? include '../db.php'; $how = mysql_query(SELECT count(distinct(account)) from Backlog) or die (Something bad happened: . mysql_error()); $how_many = mysql_result($how, 0); echo h3$how_many Accounts to pick from !!!/h3; $sql = mysql_query(SELECT distinct(Account) FROM Backlog)or die (Something bad happened here: . mysql_error()) ; echo select name=\account\\n; echo option\n; ^^ Try removing this line. while ($row = mysql_fetch_array($sql)) { echo ' option value='.$row[account].''.$row[account]./option\n; } echo /select\n; ? -- Stuart -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Drop down box NOT populated
- Original Message - From: Larry Sandwick To: [EMAIL PROTECTED] Sent: Thursday, January 22, 2004 3:46 PM Subject: [PHP-DB] Drop down box NOT populated Can anyone tell me what I am missing here, The Select statement does not populate my drop down window? My drop down box is empty ! [snip] ? include '../db.php'; $how = mysql_query(SELECT count(distinct(account)) from Backlog) or die (Something bad happened: . mysql_error()); $how_many = mysql_result($how, 0); echo h3$how_many Accounts to pick from !!!/h3; $sql = mysql_query(SELECT distinct(Account) FROM Backlog)or die (Something bad happened here: . mysql_error()) ; echo select name=\account\\n; echo option\n;-- WHAT IS THIS DOING HERE ! while ($row = mysql_fetch_array($sql)) { echo ' option value='.$row[account].''.$row[account]./option\n; } echo /select\n; ? [end snip] Larry Sandwick Sarreid, Ltd. Network/System Administrator phone: (252) 291-1414 x223 fax : (252) 237-1592
RE: [PHP-DB] Drop down box
From: Ben Cairns [EMAIL PROTECTED] To: php-db [EMAIL PROTECTED] Subject: RE: [PHP-DB] Drop down box Date: Thu, 1 Mar 2001 14:06:21 + Hope this helps -- Ben Cairns - Head Of Technical Operations intasept.COM Tel: 01332 365333 Fax: 01332 346010 E-Mail: [EMAIL PROTECTED] Web: http://www.intasept.com "MAKING sense of the INFORMATION TECHNOLOGY age @ WORK.." Hope what helps? *lol* _ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. -- PHP Database 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]
Re: [PHP-DB] Drop down box
The action you want is only available using JavaScript. You need to submit the form without a submit button. The "select" tag has the "OnChange" event which is scriptable. You can use the JavaScript statement "this.form.submit();" associated with the "OnChange" event. form... select name="x" OnChange="this.form.submit();"option.. /select.../form It's a good idea to include the submit button as well, for browers that don't support javascript, or for those who turn it off. That way your site will always work properly. -- PHP Database 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]
Re: [PHP-DB] Drop down box
At 06:32 PM 3/1/2001 -0300, you wrote: The action you want is only available using JavaScript. True but the action *you* want is most definitely not what many of your *users* are going to want. If you use Javascript this way your site will be un-navigable if Javascript is turned off or the browser does not support it. What's the big deal about a single button click? Also, using Javascript this way means that if a user is just curious what the choices are, you force a refresh without them necessarily wanting one. IMHO of course. Cheers - Island Net AMT Solutions Group Inc. Telephone: 250 383-0096 1412 Quadra Toll Free:1 800 331-3055 Victoria, B.C. Fax:250 383-6698 V8W 2L1 E-Mail:[EMAIL PROTECTED] Canada WWW: http://www.islandnet.com/ - -- PHP Database 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]
Re: [PHP-DB] Drop down box
The event "OnChange" only happens when the user open the drop down list and change ( select ) a new value, this is not "just looking" . I don't like this kind of solution. If I have to put a button on the page I think the selection list must disappear. Why not give the user a interface with less "clicks"? May be we can reach another interface approach which turn it possible. Jayme. -Mensagem Original- De: Ron Brogden [EMAIL PROTECTED] Para: [EMAIL PROTECTED] Enviada em: quinta-feira, 1 de maro de 2001 18:48 Assunto: Re: [PHP-DB] Drop down box At 06:32 PM 3/1/2001 -0300, you wrote: The action you want is only available using JavaScript. True but the action *you* want is most definitely not what many of your *users* are going to want. If you use Javascript this way your site will be un-navigable if Javascript is turned off or the browser does not support it. What's the big deal about a single button click? Also, using Javascript this way means that if a user is just curious what the choices are, you force a refresh without them necessarily wanting one. IMHO of course. Cheers -- --- Island Net AMT Solutions Group Inc. Telephone: 250 383-0096 1412 Quadra Toll Free:1 800 331-3055 Victoria, B.C. Fax:250 383-6698 V8W 2L1 E-Mail: [EMAIL PROTECTED] Canada WWW: http://www.islandnet.com/ -- --- -- PHP Database 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] -- PHP Database 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]