http://72.29.78.150/~restore/test.php
Code: Select all
include($DOCUMENT_ROOT . '/connect.php');
$all_categories = array();
$selected_categories = array();
// This selects the all the available categories which is in the table product_categories
echo("<form>");
$result = mysql_query("select * from product_categories order by name asc");
// build an array of those results
while($row = MySQL_fetch_assoc($result)){
$all_categories[] = $row['name'];
print_r($all_categories);
echo("<br>Array For All Categories<br>");
}
//$all_categories = array('cat 1','cat 2','cat 3','cat 4'); // or wherever you get it from
//$selected_categories = array();
// get the DB results from the products which is the products table
$result = mysql_query("select * from products where id='41708'");
// build an array of those results
while($row = MySQL_fetch_assoc($result)){
$selected_categories = array_merge($selected_categories,explode(',',$row['categories']));
echo("<br><br>Array for Selected Categories These are suppose to be highlighted in the select box");
print_r($selected_categories);
}
echo '<select name="category[]" multiple="true" size="5">';
// build your options
foreach($all_categories as $category){
echo("<br><br>");
echo '<option value="'.$category.'"';
if(in_array($category,$selected_categories)){
echo ' selected="selected"';
}
echo '>'.$category.'</option>';
}
echo("</select></form>");