Can't work out how to fit some code in
Posted: Sun Jul 12, 2009 1:15 pm
I need to have this bit of code output in the code below roughly line 16 below. See commented out section below. However I just can’t seem to work out how to get this to work as it will be outside of the while loop where it’s created in the query at the bottom of this script and thus throw an undefined error. I’m sure it’s obvious but I cannot get my head around this.
Any ideas as to how I can insert this without errors?
Code: Select all
echo($dbRow["counties_idpk"] == $row_GetLocSel['counties_idfk'] ? "selected='selected'" : "") ;Any ideas as to how I can insert this without errors?
Code: Select all
<?php
// Query for insert for multipal select locations
mysql_select_db($database_*****, $*****);
$query_GetLocations = "SELECT * FROM loc ORDER BY cou_idpk ASC";
$GetLocations = mysql_query($query_GetLocations, $*****) or die(mysql_error());
$totalRows_GetLocations = mysql_num_rows($GetLocations);
echo "<select size=\"5\" multiple=\"multiple\" name='counties_idpk[]' >\n >";
while($dbRow = mysql_fetch_array($GetLocations)){
echo "<option value='"
. $dbRow["counties_idpk"]
. "'"
. "'>"
. $dbRow["counties_name"];
// NEED THIS CODE IN HERE BUT IT WONT WORK THIS WAY AS IT STANDS
//echo ($dbRow["counties_idpk"] == $row_GetLocSel['counties_idfk'] ? "selected='selected'" : "") ;
mysql_select_db($database_*****, $*****);
$query_GetLocSel =
"SELECT *
FROM users_locations_test
WHERE counties_idfk = '$dbRow[counties_idpk]' ";
$GetLocSel = mysql_query($query_GetLocSel, $*****) or die(mysql_error());
$totalRows_GetLocSel = mysql_num_rows($GetLocSel);
while($row_GetLocSel = mysql_fetch_assoc($GetLocSel)) {
echo ($dbRow["counties_idpk"] == $row_GetLocSel['counties_idfk'] ? "selected='selected'" : "") ;
echo "</option>\n";
}
}