| | |
OPTION problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 28
Reputation:
Solved Threads: 0
Hi
i m trying to get the values from database and put it into the select options..
i m using code-
but i m getting displayes with the values as--
means values getting displayed one after another and not in option..
why so..
plz help
i m trying to get the values from database and put it into the select options..
i m using code-
PHP Syntax (Toggle Plain Text)
<?php $con = mysql_connect("localhost","cdccpl","d123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("cdccpl_aus", $con); $result = mysql_query("SELECT * FROM bak_bill_cust"); while( $row = mysql_fetch_array( $result ) ): $option = $row["cust_code"]; echo "<option value='$row[cust_code]'>$row[cust_code]</option>"; endwhile; mysql_close($con);?>
but i m getting displayes with the values as--
PHP Syntax (Toggle Plain Text)
Customer auswidestonemanpnicholsonllwmplnewuserguestanftasturnbullanglic
means values getting displayed one after another and not in option..
why so..
plz help
echo your option tags inside of a select tag like this:
PHP Syntax (Toggle Plain Text)
<select name="test" id="test"> <option value="value 1">option 1</option> <option value="value 2">option 2</option> <option value="value 3">option 3</option> </select>
The End
Well firstly
>>>
I actually wasn't even aware PHP could use that format for while loops but I wouldn't advise its use given that it completely breaks the Perl-like syntax and just makes for ugly code.
php Syntax (Toggle Plain Text)
$result = mysql_query("SELECT * FROM bak_bill_cust"); while( $row = mysql_fetch_array( $result ) ): $option = $row["cust_code"]; echo "<option value='$row[cust_code]'>$row[cust_code]</option>"; endwhile;
php Syntax (Toggle Plain Text)
$result = mysql_query("SELECT * FROM bak_bill_cust"); while( $row = mysql_fetch_assoc( $result ) ) { $option = $row["cust_code"]; echo "<option value='$option'>$option</option>"; }
I actually wasn't even aware PHP could use that format for while loops but I wouldn't advise its use given that it completely breaks the Perl-like syntax and just makes for ugly code.
Last edited by ShawnCplus; Feb 27th, 2008 at 3:32 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Not sure if your porblem is solved yet, but here is something I use all the time for drop downs.
First get your connection string going. preferably using an include.
then use the following code, adapting statement to your needs:
This works well for holding the users selected values when error checking as well...
hope this helps
First get your connection string going. preferably using an include.
then use the following code, adapting statement to your needs:
php Syntax (Toggle Plain Text)
<?php $result = mysql_query("SELECT * FROM users ORDER BY username ASC") or die(mysql_error()); $sticky= ''; if (isset($_POST['id'])) $sticky = ($_POST['id']); $pulldown1 = '<select name="id">'; $pulldown1 .= '<option></option>'; while($row = mysql_fetch_array($result)) { if($row['id'] == $sticky) { $pulldown1 .= "<option selected value=\"{$row['id']}\"> {$row['username']} - {$row['id']} </option>\n"; } else { $pulldown1 .= "<option value=\"{$row['id']}\"> {$row['username']} - {$row['id']} </option>\n"; } } $pulldown1 .= '</select>'; echo $pulldown1; ?>
hope this helps
I keep hitting "escape", but I'm still here!!!!
:}
:}
try
PHP Syntax (Toggle Plain Text)
$sql = "SELECT * FROM bak_bill_cust"; $query = mysql_query($sql) or die('Error: ' . mysql_error()); $select = '<select name="test">'; $select .= '<option value=""></option>'; while ($row = mysql_fetch_assoc($query)) { $select .= '<option value="' . $row['cust_code'] . '">' . $row['cust_code'] . '</option>'; } $select .= '</select>'; echo $select;
![]() |
Similar Threads
- Dell Laptop Upgrade Problem (Windows NT / 2000 / XP)
- URGENT :: Odd Windows Booting Problem (Windows NT / 2000 / XP)
- Folder Option Problem (Windows NT / 2000 / XP)
- Final GUI JFrame problem with actionlistner method (Java)
- File and Printer Shareing Problem (Networking Hardware Configuration)
- Major Folder Option Problem (Windows NT / 2000 / XP)
- Properties option problem XP (Windows NT / 2000 / XP)
- Folder Option Problem (Windows NT / 2000 / XP)
Other Threads in the PHP Forum
- Previous Thread: Can't create sessions
- Next Thread: Displaying Data
Views: 687 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess 5.2.10 access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error file files folder form forms function functions google header href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql mysqlquery oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap sockets source space speed sql structure syntax system table thesishelp tutorial update updates upload url validation validator variable video web xml youtube






