I have a multi-select dropdown in a form pulling information from 2 databases which is not working correctly.
The first part loops throught the table pulls all of the rows from one field in the table and places them in a dropdown box. This part is working correctly. So basically within the dropdown I have a list of different topics.
I then want to go to the second table and select all of the "topics" with regards to a unique id. This table can have many topics per id.
Then cycle through the topics from this second table and whenever it matches one of the topics from the first table place a SELECTED in the option tag.
It sees the first time the two fields match and will highlight this option, but does not see any of the remaining matches.
Here is the code. Can someone please help. I am at a loss. Thank you.
<select name="topic_code" multiple size="17">
<?
// Query to get all topics
$topicquery = "select * from topic_codes ORDER BY topic_desc";
// 2nd query matching id to topics from 2nd table
$sp_topics = "select * from speaker_topics where speaker_id=" . $result_array["speaker_id"];
$result4 = mysql_query($sp_topics) or die(mysql_error());
$result_array4 = mysql_fetch_array($result4, MYSQL_ASSOC);
$topicresult = mysql_query($topicquery) or die(mysql_error());
// Loop through 1st query to create list
while ($topicresult_array = mysql_fetch_array($topicresult, MYSQL_ASSOC)) {
echo "<option value=\"" . $topicresult_array["topic_code"] . "\"";
// If statement from SELECTED
if (($result_array4["topic_code"]) == ($topicresult_array["topic_code"])) {
echo " SELECTED";
}
echo ">" . stripslashes(htmlspecialchars($topicresult_array["topic_desc"])) . "</option>\n";
}
?></select>