PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP 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 September 11th, 2004, 11:19 AM
jonnymaboy jonnymaboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 6 jonnymaboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question selected value problem with multiple select box

hi all,

i have searched forums but not found what i need. I have a drop down multiple select box which the users must choose at least one option. Once the form is processed it calls itself dispplaying all the details the user has filled in. Now the drop down list is populated froma db but once the user has already selected values before the page calls its self a check must be done to highlight the values they previously selected. (HOPE THIS IS MAKING SENSE!) I have this accomplished but it the only value to be selected is the is the second choice ie if a user selects golf and tennins only the tennins would be selected. the below code is what i have used.

echo " <select name="selectCylinderType[]" multiple>
echo" <option value='0'>Please Select</option>";
while($row=mysql_fetch_array($result))
{
//code to check if the user has made a previous chose in the db
//and if so highlight it in the drop down first check that the passed values
// the $strFKeyValue is a string holding the values the user selected used the foreach... string1,string2, to fill the variable

$arraybreakdown = explode(",", $strFKeyValue);
$arrayLength= count($arraybreakdown);
//echo "<br>the length is $arrayLength";

for($p=0; $p < $arrayLength-1; $p++)
{
//echo "<br>the break down is $arraybreakdown[$p]"; this works fine and prints out the users choice
if ($row[$strPrimaryKey] == $arraybreakdown[$p])
{
// set the variable $selected to selected if records match
$strSelected ="selected";
}
else
{
// leave it blank if records not found
$strSelected="";
}
} //end of for
//print to screen the options in the drop down menu
//the value is the primary key and the option is the fieldname (passed to the function).
echo "<OPTION VALUE=".$row[$strPrimaryKey]." $strSelected> ".$row[$strFieldName]."</OPTION>";

} //end of while

please help i think i need some php similar to javascripts control.selected to go in the variable strSelected but need php

Reply With Quote
  #2  
Old September 11th, 2004, 07:22 PM
jonnymaboy jonnymaboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 6 jonnymaboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
is anyone going to reply

will someone please help!!!

Reply With Quote
  #3  
Old September 15th, 2004, 09:04 AM
aanandi34 aanandi34 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 aanandi34 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i didnt get the problem actually.
do you want to get what all values were selected by the user?
just check out the following site.
if u still dont get any solution,just send what the problem is.
http://www.onlinetools.org/tricks/using_multiple_select.php

Reply With Quote
  #4  
Old September 15th, 2004, 07:33 PM
oyejorge oyejorge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 25 oyejorge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 13 sec
Reputation Power: 0
The problem looks like it's within the for loop, try this one:

PHP Code:
for($p=0$p $arrayLength-1$p++) {
 
if (
$row[$strPrimaryKey] == $arraybreakdown[$p]){
 
$strSelected ="selected";
break; 
///here's the solution
// the for loop will stop so that the next iteration won't reset $strSelected
 
}else{
 
$strSelected="";


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > selected value problem with multiple select box


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT