Posted: Sun Oct 28, 2007 5:49 am
Here is the current full script since I have modified the test page to make sure that other vairables and stuff is not shown Thanks for all the help from everyone that has posted to this. below is the script and also the link to the test page. I will be logging who goes to this page to track abuse Hopefully this does not happen.
http://72.29.78.150/~restore/test.php
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>");