Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Funzione che restituisce solo un dato dell'array

    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?

  2. #2
    Perchè non utilizzi semplicemente:

    Codice PHP:
    (in_array($key$array_posizioni) ? ' selected="selected" ' ''

  3. #3
    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_SERVERDB_SERVER_USERNAMEDB_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"
    );
                                } 

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.