2013-05-03 50 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