选择包含价格值和名称的列表

时间:2013-09-11 19:21:04

标签: php forms

我有一个适用于审核阶段的表单。我想做的不是加价混合。说我有这样的下拉列表

<select name="DriverShaft" class="select">
  <option value="" selected="selected">Select Shaft</option>
  <option value="LE- light weight graphite weakest flex">LE- light weight graphite weakest flex</option>
  <option value="LW- Light weight graphite weak flex">LW- Light weight graphite weak flex</option>
  <option value="LM- Light weight graphite medium flex">LM- Light weight graphite medium flex</option>
  <option value="LR- Light weight graphite regular flex">LR- Light weight graphite regular flex</option>
  <option value="GR- Medium weight graphite regular flex">GR- Medium weight graphite regular flex</option>
  <option value="SS- Light weight graphite stiff flex">SS- Light weight graphite stiff flex (low torque)</option>
  <option value="TS- Medium weight graphite stiff flex">TS- Medium weight graphite stiff flex</option>
  <option value="SX- Light weight graphite X-stiff">SX- Light weight graphite X-stiff</option>
  <option value="KS- Light weight steel stiff flex">KS- Light weight steel stiff flex</option>
  <option value="KR- Light weight steel regular flex">KR- Light weight steel regular flex</option>
  <option value="DX- Heavy weight steel extra stiff">DX- Heavy weight steel extra stiff</option>
  <option value="DS- Heavy weight steel stiff flex">DS- Heavy weight steel stiff flex</option>
</select>

在评论中我回应了这样的选项:

echo (!empty($_REQUEST['DriverShaft'])) ? "<div class='reviewItem'><span class='reviewTitle'>Shaft:</span>{$_REQUEST['DriverShaft']}</div>" : "";

然后,如果选择了轴,则会显示轴选择。如何为每个轴添加价格值?所以在评论中它显示了轴的名称,但我也可以从他们的选择中得到一个价格加起来?

1 个答案:

答案 0 :(得分:0)

设置值=价格由:或任何其他字符分隔

value="LE- light weight:50.25">LE- light weight</option>

并在评论中回复了这样的选项:

if (!empty($_REQUEST['DriverShaft'])) {
   list($shaft, $price) = explode(":", $_REQUEST['DriverShaft']);
   echo "<div class='reviewItem'><span class='reviewTitle'>Shaft:</span>{$shaft}</div>";
   echo "<div class='reviewItem'><span class='reviewTitle'>Price:</span>{$price}</div>";
} else echo "";

如果你想要没有人能看到价格甚至没有在HTML文本中 添加存储价格的DB table的ID

value="LE- light weight:12">LE- light weight</option>

需要数据库查询

if (!empty($_REQUEST['DriverShaft'])) {
   list($shaft, $IDprice) = explode(":", $_REQUEST['DriverShaft']);
   if (!empty($IDprice)) {
     // your database logic
      $sql ="SELECT price .... WHERE priceid=:prid";
      ....
     // logic end
   $price = $row['price']; 
   } else $price = "n/a";
     echo "<div class='reviewItem'><span class='reviewTitle'>Shaft:</span>{$shaft}</div>";
     echo "<div class='reviewItem'><span class='reviewTitle'>Price:</span>{$price}</div>";

} else echo "";