Non andrebbe bene, in quanto mi metterebbe selected a tante opzioni quanti sono i valori dell'array, mentre ovviamente il selected va solo su un'opzione.
Ho però risolto il problema e posot il codice, dovesse servire a qualcuno.
Codice PHP:
function SELECTED($firstVal, $secondVal){
if($firstVal == $secondVal){
$result = " SELECTED";
return $result;
}
}
$conn = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD);
if (!$conn){
die("Errore: " . mysql_error());
}
mysql_select_db(DB_DATABASE, $conn);
$get_existing_data = tep_db_query("SELECT * FROM " . TABLE_EVIDENZA . " ORDER BY pos LIMIT " . IN_EVIDENZA_LIST_QUANTITY . "");
while($posizioni = tep_db_fetch_array($get_existing_data)){
$array_posizioni[] = $posizioni['id_prod'];
}
$get_data = tep_db_query("SELECT " . TABLE_PRODUCTS . ".products_id, " . TABLE_PRODUCTS . ".products_status, " .
"" . TABLE_PRODUCTS_DESCRIPTION . ".products_name FROM " . TABLE_PRODUCTS . " " .
"INNER JOIN " . TABLE_PRODUCTS_DESCRIPTION . " ON " .
"(" . TABLE_PRODUCTS . ".products_id = " . TABLE_PRODUCTS_DESCRIPTION . ".products_id) " .
"WHERE " . TABLE_PRODUCTS . ".products_status = 1 " .
"ORDER BY " . TABLE_PRODUCTS_DESCRIPTION . ".products_name");
while($row = tep_db_fetch_array($get_data)){
$array_products[$row[products_id]] = $row[products_name];
}
mysql_close($conn);
for($i = 1; $i<=IN_EVIDENZA_LIST_QUANTITY; $i++){
print ("<select name=\"select" . $i . "\">\n");
foreach($array_products as $key => $value){
print ("<option value=\"" . $key . "\"" . SELECTED($key, $array_posizioni[$i-1]) . ">" . $value . "</option>\n");
}
print ("</select>
\n");
}