2013-05-03 51 views
0

這是一個發貨模塊,它允許您選擇商店分支以供本地取貨。 分支在csv中列出,而不在數據庫中。在php中打印或回顯所選選項,不帶表格

<?php 
     if (($n > 1) || ($n2 > 1)) { 
     if ($quotes[$i]['id'] == 'localdelivery') { 
      if (file_exists($quotes[$i]['pricesL'])) { 
      echo '<td class="main" style="padding-right:15px;"><select name="locdeliv">'; 
      $file_handle = fopen($quotes[$i]['pricesL'], "r"); 
      while (!feof($file_handle)) { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      echo '<option value="' . $line_of_text[1] . '">' . $line_of_text[0] . '</option>'; 
             } 
      fclose($file_handle); 
                } 
      else { 
      echo '<td class="main"><select name="locdeliv"><option value="0">file missing</option>'; 
       } 
      echo '</select></td>'; 
               } 
     //else { 
?> 

工作正常。 下面是顯示用戶所認爲的運輸描述代碼:

'title' => print $line_of_text[1], 

我需要呼應無論用戶從下拉列表中選擇

function quote($method = '') { 
    global $order; 

    $this->quotes = array('id' => $this->code, 
         'module' => MODULE_SHIPPING_LOCALDELIVERY_TEXT_TITLE, 
         'pricesL' => MODULE_SHIPPING_LOCALDELIVERY_PRICESFILE, 
         'methods' => array(array('id' => $this->code, 
               'title' => print $line_of_text[1], 
               'cost' => MODULE_SHIPPING_LOCALDELIVERY_COST))); 

    if ($this->tax_class > 0) { 
    $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); 
    } 

    if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title); 

    return $this->quotes; 
} 

這部分。我已經嘗試過各種東西,比如$ file_handle等,但總是得到「1」。 是否有一種簡單的方法將選定的下拉值變爲「標題」? 這允許標題稍後保存在數據庫中。在其他模塊中,'標題'來自語言文件,所以它不會來自數據庫,結賬頁面「不關心」該行是什麼,它將其保存到數據庫,以便我可以看到選擇了哪個選項在行政部門。 使用CSV的原因是公司經常更新分支機構,這是頻繁更新的最簡單方法。

+0

我看到三重還是有'3如果statements'可以組合 – 2013-05-03 00:45:16

+0

PHP是在服務器側執行,因此服務器不能學習用戶已經從下拉選擇在客戶端 - 值除非你使用AJAX,否則直到它被髮回服務器的'

'。 – verbumSapienti 2013-05-03 00:59:34

+0

我會研究一下,因爲結賬頁面已經在表單的其餘部分使用AJAX,只需要將其實現到它。 – Fid 2013-05-03 01:04:18

回答

0

您正在嘗試在定義變量時使用programming constructprint) - 這是不正確的語法。

您需要做的是使用函數Quote,並從返回的數組中獲取值。

$result = $obj->quote(); 
$title = $result['methods'][0]['title']; 
print $title; 

編輯闡述:

你的功能quote被引用$this,這意味着它是一個class內的method。 爲了能夠使用這種方法,您需要將其稱爲,該類本身的以外。我們稱之爲客戶端代碼。

class Foo 
{ 
    public function quotes() { 
    // ** all your code ** 
    return $this->quotes; 
    } 
} 

// outside the class, so client code 
$foo = new Foo(); 
$result = $foo->quote(); 
$title = $result['methods'][0]['title']; 
print $title; 
+0

不幸的是,我不知道該把代碼添加到哪裏。 – Fid 2013-05-03 00:56:51

+0

@fid我編輯得更清楚 – AlexP 2013-05-03 01:10:07