【发布时间】:2013-05-03 00:40:14
【问题描述】:
这是一个配送模块,允许您选择分店进行本地取货。 分支列在 csv 中,而不是在数据库中。
<?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 {
?>
效果很好。 下面的代码显示了用户所看到的运输描述:
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;
}
这部分
'title' => print $line_of_text[1],
我需要回显用户从下拉列表中选择的任何内容。我尝试了各种方法,例如 $file_handle 等,但结果总是得到“1”。 有没有一种简单的方法可以将选定的下拉值放入“标题”? 这允许稍后将标题保存在数据库中。在其他模块中,“标题”取自语言文件,因此它永远不会来自数据库,并且结帐页面“不在乎”该行是什么,它将其保存到数据库中,因此我可以看到选择了哪个选项在行政上。 使用 CSV 的原因是公司经常更新分支机构,这是经常更新的最简单方法。
【问题讨论】:
-
我看到的是三重还是有
3 if statements可以组合 -
PHP 在服务器端执行,因此服务器无法获知用户从客户端下拉列表中选择的值,直到将其以
<form>发回服务器,当然,除非你使用 AJAX。 -
我会调查一下,因为结帐页面已经在表单的其余部分使用了 AJAX,只需要在其中实现它。
-
发回您的发现 - 很乐意为您提供帮助
标签: php csv printing echo option