Ciao.
Posto questo codice:
Codice PHP:
function SELECTED($firstVal, $secondVal){
for($i = 0; $i <= count($secondVal)-1; $i++){
if($firstVal == $secondVal[$i]){
$result = " SELECTED";
return $result;
}
}
}
connessione db...
$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) . ">" . $value . "</option>\n");
}
print ("</select>
\n");
}
le select che ne escono sono sì popolate con tutti i valori dell'array $array_products, ma tutte riportnao come opzione selected sempre la stessa, nonostante l'array contenga non solo un dato.
Il tutto è integrato nel sistema osCommerce, come si può vedere dlale funzioni di query.
Idee?