The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Dropdown Menus 'selected="selected"'
As per my previous thread, I am making an edit page where users can edit multiple rows at once, I have the updating working.
I'm now stuck at getting it to show what option the user has selected, when they view the edit page again. PHP Code:
To help you understand what I mean, here's an example of the HTML output: HTML Code:
<td><select class="primary" name="country[3]" tabindex="1"> <option value="1" class="" >Australia</option> <option value="2" class="" >Canada</option> <option value="3" class="" selected="selected">New Zealand</option> <option value="4" class="" >United Kingdom</option> <option value="5" class="" >United States</option> </select></td> <td><select class="primary" name="country[2]" tabindex="1"> <option value="1" class="" >Australia</option> <option value="2" class="" >Canada</option> <option value="3" class="" selected="selected">New Zealand</option> <option value="4" class="" >United Kingdom</option> <option value="5" class="" >United States</option> </select></td> Cheers for your help! Iain |
#2
|
|||
|
|||
Maybe the problem is that you've used a capital letter in 'Country' in this line:
PHP Code:
when the column is named 'country'. That way, $getChecked['Country'] is null which would always match the first id if it were 0. |
#3
|
||||
|
||||
Thanks kh99. Still nothing =/ I've been on this for the past 2 days haha =[
|
#4
|
|||
|
|||
Does the services table only have one record per service? If so, then I don't think you need that extra query to get the selected option, because it's always going to return the same record as is already in $editService. If that's the case then to set $optionselected you'd just want:
PHP Code:
but to be honest I don't see why that would solve the problem. |
#5
|
||||
|
||||
In the service table would be a service that a user has added, and the country is where the service is available.
So for example, User 1 could say offer Dog Trainer in UK (row 1), Baby Sitter in US (row 2), Plumber in NZ (Row 3). At the moment it is pulling all the services, and saying they are all in NZ. As I have the ID field sorted descending order (in $editServices). So from what I can gather it's completely ignoring while($viewCountry = $db->fetch_array($getCountries)) as a loop. Because, I think it should be running PHP Code:
|
#6
|
|||
|
|||
But you're getting a list of services, each with a list of countries, so it has to be doing both loops, right? It seems like it's just the test for the selected one that isn't working.
Oh, I think I know - you have to repeat the 'countries' query each time. Try putting PHP Code:
|
#7
|
||||
|
||||
I seriously owe you a drink! Thank you!
Now, I just need to duplicate it for another drop down, and radio options =] Thank you so much! =] Where did you find that? [EDIT] Oh wait.. that bumps my queries on that page up from 35 to 83, that's without the other drop down, and radio options which could make it increase further. There must be a better way? =/ |
#8
|
|||
|
|||
Quote:
Quote:
PHP Code:
must be getting done more times, right? Are you sure you actually need that one (I'm still not completely clear on the db structure so I'm not sure). |
#9
|
||||
|
||||
Thanks for the link. I had never came across that function before. I guess I didn't look hard enough!
Quote:
If I remove that query and use PHP Code:
For example: Row 1: Dog Trainer in UK HTML Code:
<td><select class="primary" name="country[3]" tabindex="1"> <option value="1" class="" >Australia</option> <option value="2" class="" >Canada</option> <option value="3" class="">New Zealand</option> <option value="4" class="" selected="selected">United Kingdom</option> <option value="5" class="" >United States</option> </select></td> HTML Code:
<td><select class="primary" name="country[3]" tabindex="1"> <option value="1" class="" >Australia</option> <option value="2" class="" >Canada</option> <option value="3" class="">New Zealand</option> <option value="4" class="" selected="selected">United Kingdom</option> <option value="5" class="" selected="selected">United States</option> </select></td> HTML Code:
<td><select class="primary" name="country[3]" tabindex="1"> <option value="1" class="" >Australia</option> <option value="2" class="" >Canada</option> <option value="3" class="" selected="selected">New Zealand</option> <option value="4" class="" selected="selected">United Kingdom</option> <option value="5" class="" selected="selected">United States</option> </select></td> Thanks Kevin. I'm gonna head off (almost 2am here), and play with this again tomorrow. |
#10
|
|||
|
|||
You know, I think maybe you just need a
PHP Code:
after the render to reset that variable. But I don't know why you're not seeing the options building up each time, with the contries repeating over and over. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|