2017-07-14 2 views
0

Ich versuche, alle herunterladbaren Dateien auf der Produktseite zu bekommen und anzuzeigen. hier ist mein Code:opencart bekomme alle herunterladbaren Dateien

Modell:

public function download_m($product_id) { 
    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'"); 
    if ($query->num_rows) { 
     return array(
     'product_id'  => $query->row['product_id'],   
     'download_id'  => $query->row['download_id'] 
    ); 
    } 
} 

Controller:

$download_m = $this->model_catalog_product->download_m($product_id); 

Ansicht:

print_r($download_m) 

Datenbank:

enter image description here

wie Sie sehen gibt es zwei herunterladbare Artikel mit product_id , aber es nur zurück 3 nicht 3,4. Was habe ich falsch gemacht?

Antwort

2

versuchen diesen Code Ergebnis zu erhalten, wie Sie

wollen
$return_result=array(); 
if ($query->num_rows) { 
    foreach ($query->rows as $result) { 
    $return_result[]=array(
     'product_id'  => $result['product_id'],   
     'download_id'  => $result['download_id'] 
    ); 
} 
} 
return $return_result; 
0

Verwenden Sie Schleife für jedes Ergebnis wie folgt.

if ($query->num_rows) { 
    foreach ($query->rows as $result) { 
     return array(
      'product_id'  => $result['product_id'],   
      'download_id'  => $result['download_id'] 
     ); 
    } 
} 

Sie können diese Art von Code überall in Opencart-Dateien überprüfen.

+0

zurückgeben 'Array ([product_id] => 95 [download_id] => 3)' ' – Pedram

+0

Da Sie Array von einzelnen Index Rückkehr – Nimish

Verwandte Themen