Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
Select Box - Value selected from variable
Old 10-22-2006, 02:19 PM Select Box - Value selected from variable
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
The option goes into the database, and I want to pull out the data (using PHP) and have the option that they chose as the default value. How can I do this?
feraira is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-22-2006, 09:00 PM Re: Select Box - Value selected from variable
angele803's Avatar
Perfectly Imperfect

Posts: 1,772
Name: Stephanie
Location: Oklahoma
Trades: 2
I have no idea. But you might try asking this in the PHP forum. You might get some answers there.
angele803 is offline
Reply With Quote
View Public Profile
 
Old 10-23-2006, 02:38 AM Re: Select Box - Value selected from variable
pitbull82's Avatar
Super Talker

Posts: 147
Name: Marcin Nabiałek
Location: Poland, Częstochowa
Trades: 0
Assume, that your data for creating select box are inarray $options and value from database is in $selectedValue variable.

PHP Code:
$selectedValue= ... // this is value from database;

echo "<select name='aaa'>";
for (
$i=0,$count=count($options);$i<$count;++$i)
{
   echo 
"<option value='".$options[$i]['value']"'";
   if (
$options[$i]['value']==$selectedValue)
     echo 
" selected='selected'>";
   else
     echo 
">";
   echo 
$options[$i]['description']."</option>";
}
echo 
"</select>"
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
pitbull82 is offline
Reply With Quote
View Public Profile Visit pitbull82's homepage!
 
Old 10-23-2006, 03:18 AM Re: Select Box - Value selected from variable
Skilled Talker

Posts: 97
Trades: 0
in simple terms, add selected='selected' into your option field

e.g.

<option value='xxx' selected='selected'> simple huh?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
daboss is offline
Reply With Quote
View Public Profile Visit daboss's homepage!
 
Old 10-23-2006, 07:15 PM Re: Select Box - Value selected from variable
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Quote:
Originally Posted by pitbull82 View Post
Assume, that your data for creating select box are inarray $options and value from database is in $selectedValue variable.

PHP Code:
$selectedValue= ... // this is value from database;

echo "<select name='aaa'>";
for (
$i=0,$count=count($options);$i<$count;++$i)
{
   echo 
"<option value='".$options[$i]['value']"'";
   if (
$options[$i]['value']==$selectedValue)
     echo 
" selected='selected'>";
   else
     echo 
">";
   echo 
$options[$i]['description']."</option>";
}
echo 
"</select>"
I've just tried this. This is the code I have used...
PHP Code:
$selectedValue"Tom"// this is value from database;

$options = array();
$options[0] = "Tom";
$options[1] = "Charlie";

echo 
"<select name='test'>";
for (
$i=0,$count=count($options);$i<$count;++$i)
{
   echo 
"<option value='".$options[$i]['value']"'";
   if (
$options[$i]['value']==$selectedValue)
     echo 
" selected='selected'>";
   else
     echo 
">";
   echo 
$options[$i]['description']."</option>";
}
echo 
"</select>"
I get the following error:
Code:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /mounted-storage/home17a/sub002/sc19014-UDPB/alldrumtabs.com/warnings.php on line 12
Line 12 being:
PHP Code:
echo "<option value='".$options[$i]['value']"'"
feraira is offline
Reply With Quote
View Public Profile
 
Old 10-24-2006, 01:12 AM Re: Select Box - Value selected from variable
pitbull82's Avatar
Super Talker

Posts: 147
Name: Marcin Nabiałek
Location: Poland, Częstochowa
Trades: 0
Here's the exact code:
PHP Code:
<?php
$selectedValue
"Charlie"// this is value from database;

$options = array();
$options[0]['value'] = "Tom";
$options[0]['description'] = "Tom";
$options[1]['value'] = "Charlie";
$options[1]['description'] = "Charlie";

echo 
"<select name='test'>";
for (
$i=0,$count=count($options);$i<$count;++$i)
{
   echo 
"<option value='".$options[$i]['value']."'";
   if (
$options[$i]['value']==$selectedValue)
     echo 
" selected='selected'>";
   else
     echo 
">";
   echo 
$options[$i]['description']."</option>";
}
echo 
"</select>";
?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
pitbull82 is offline
Reply With Quote
View Public Profile Visit pitbull82's homepage!
 
Reply     « Reply to Select Box - Value selected from variable
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.56476 seconds with 12 queries