Hello-
I have a form where users can select multiple catgories. In my code below, the ID's of the categories they select are then used by a SELECT query to obtain the names and ids from a table, UserInfo.
My code and query, below, return the correct data, but the results are not ordered correctly if they select more than one category. If they select more than one category, all the names of the first category are in alpha order, this is then followed by all the names in the second category in alpha order, etc. which is no good for my purposes
What I need is all the names ordered by alpha no matter what the category is. I can't figure out how to do this. Is my SELECT query wrong? Is my 'foreach' in the wrong place? Any help would be appreciated. Thanks.
//IDd is array of category IDs from the form
$IDd=$_POST['IDd'];
foreach( $IDd as $k){
$sql = "SELECT BusinessGuide.UserInfoID, UserInfo.ID, UserInfo.Name FROM BusinessGuide INNER JOIN UserInfo ON BusinessGuide.UserInfoID = UserInfo.ID WHERE BusinessGuide.CategoryID='$k' ORDER BY UserInfo.Name";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo ("<table>
<tr><td><a href=showlisting.php?ID=" . urlencode($row["UserInfoID"]) . ">" . $row['Name'] ."</a></FONT></td></tr></table></td>");
}
}