Link to home
Create AccountLog in
Avatar of DS928
DS928Flag for United States of America

asked on

Adding A Field To A List

I have a PHP statement that loads a list box.  I have to add the field tblLocDet.DetailID as id, which I did.  Now I need to add it to the listbox itself as the first row so that I can call it to filter some records.  How do I place it in the while statement?  I do not want to see it,.

$sql = "SELECT tblDetails.DetailType AS type, tblLocDet.DetailID AS id,
			GROUP_CONCAT(DISTINCT DetailName ORDER BY DetailName ASC SEPARATOR '|') AS DetailName
			FROM tblLocations INNER JOIN (tblLocDet INNER JOIN tblDetails
			ON tblLocDet.DetailID = tblDetails.DetailID) ON tblLocations.LocationID = tblLocDet.LocationID
			GROUP BY tblDetails.DetailType,tblLocations.CityID,tblLocations.AreaID,tblLocations.CuisineID
			HAVING (((tblLocations.CityID)='16')
			AND ((tblLocations.AreaID)='131')
			AND ((tblLocations.CuisineID)='3'))";
			$result = mysql_query($sql) or die(mysql_error());  

			while ($row = mysql_fetch_assoc($result)) { 
   			echo "<optgroup label='{$row['type']}'>"; 
   			$DetailNames = explode('|', $row['DetailName']); 
   			foreach($DetailNames as $DetailName) { 
    		echo "<option value='".$DetailName."'>".$DetailName."</option>"; 
   			} 
   			echo "</optgroup>"; 

Open in new window

Avatar of DS928
DS928
Flag of United States of America image

ASKER

Tried This.......
$sql = "SELECT tblDetails.DetailType AS type, tblLocDet.DetailID,
			GROUP_CONCAT(DISTINCT DetailName ORDER BY DetailName ASC SEPARATOR '|') AS DetailName
			FROM tblLocations INNER JOIN (tblLocDet INNER JOIN tblDetails
			ON tblLocDet.DetailID = tblDetails.DetailID) ON tblLocations.LocationID = tblLocDet.LocationID
			GROUP BY tblDetails.DetailType,tblLocations.CityID,tblLocations.AreaID,tblLocations.CuisineID
			HAVING (((tblLocations.CityID)='16')
			AND ((tblLocations.AreaID)='131')
			AND ((tblLocations.CuisineID)='3'))";
			$result = mysql_query($sql) or die(mysql_error());  

			while ($row = mysql_fetch_assoc($result)) { 
   			echo "<optgroup label='{$row['type']}'>"; 
   			$DetailIDs = explode('|', $row['DetailID']); 
			$DetailNames = explode('|', $row['DetailName']); 
   			foreach($DetailNames as $DetailName) { 
    		echo "<option value='".$DetailID."''".$DetailName."'>".$DetailID."".$DetailName."</option>"; 
   			} 
   			echo "</optgroup>"; 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of DS928

ASKER

Thank you.