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:
// Get list of countries for Country option
$countryOptions = '';
$getCountries = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "countries ORDER BY title ASC");
// Get user services
$editServices = $vbulletin->db->query_read("
SELECT *
FROM " . TABLE_PREFIX . "services
WHERE userid = '" . $vbulletin->userinfo['userid'] . "'
ORDER BY id DESC
");
while ($editService = $vbulletin->db->fetch_array($editServices))
{
while($viewCountry = $db->fetch_array($getCountries))
{
// Check which Country is seleted
$getChecked = $db->query_first("SELECT id, country FROM " . TABLE_PREFIX . "services WHERE country = " . $viewCountry['id'] . " AND id = " . $editService['id']);
$optiontitle = $viewCountry['title'];
$optionvalue = $viewCountry['id'];
$optionselected = ($viewCountry['id'] == $getChecked['Country']) ? 'selected="selected"' : '';
$optionclass = '';
$countryOptions .= render_option_template($optiontitle, $optionvalue, $optionselected, $optionclass);
}
// Register 'editservicebit' template variables
$templater = vB_Template::create('editservicebit');
$templater->register('id', $editService['id']);
$templater->register('title', $editService['title']);
$templater->register('description', $editService['description']);
$templater->register('country', $editService['country']);
$templater->register('free', $editService['free']);
$templater->register('active', $editService['active']);
$templater->register('countryOptions', $CountryOptions);
$editservicebit .= $templater->render();
}
The code above only seems to be matching
$viewCountry['id'] == $getChecked['Country'] on the first row from the editServices query, and applying selected="selected" to that country in each row, even when another country has been selected for that service. It isn't looping with
while($viewCountry = $db->fetch_array($getCountries)). I had tried a foreach loop instead, and had got somewhere, but it still wasn't working, so I went back to the start to try again, but it feels like I'm banging my head against a brick wall, and going round in circles.
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>
Can someone point me in the right direction again?
Cheers for your help!
Iain