Hey, I’ve never had to use an array before today, and now I feel like I have a fairly complicated situation where arrays will be necessary.
Basically, I’m pulling information from a database (don’t worry, I don’t have any questions involving databases). I want to fill an array(s) with information from the database so I can be sure to prevent duplicates from appearing.
To be exact, I’m filling a <select> (dropdown menu) with categories from my database. It’s pretty easy to do this without arrays with one category, but the problem is, my database entries can have up to 3 categories each. So I want to pull all of these categories from the database, store them in the array (without duplicates) and list them in the <select>.
Here’s the code I have to fill the <select> using just 1 category. Could someone help me also include category2, and category3, without duplicates?
[code=php]$result = mysql_query($query);
$num = mysql_numrows($result);
$i = 0;
$prev = “”;
echo “<form name=”select_category” action=”directory.php” method=”GET”>n
<input type=”hidden” name=”member_type” value=”$member_type”>n
<select name=”category”>n
<option value=”all” selected>View All Categories</option>n”;
while ($i < $num) {
$category = mysql_result($result, $i, “category”);
if ($category != $prev) {
$prev = $category;
echo “<option value=”$category””;
if ($category == $_GET[‘category’]) {
echo ” selected “;
}
echo “>$category</option>n”;
}
$i++;
}
echo “</option>n
<input type=”submit” name=”submit” value=”View This Category”>n
</form>n”;