1

我有一个在审查阶段效果很好的表格。我想做的不是增加价格来混合。说我有这样的下拉菜单

<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>" : "";

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

4

1 回答 1

0

设置value= 以价格分隔:或任何其他字符

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 源文本中也没有人可以看到价格,请添加存储价格
的 IDDB table

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 "";
于 2013-09-11T20:30:25.593 回答