我有这个代码:
function getPricing() {
$returnarr = array();
$dcid = (isset($_REQUEST['dcid'])) ? "WHERE datacentre_id='" . mysql_real_escape_string($_REQUEST['dcid']) . "'" : '';
$addons = $_REQUEST['addon'];
if ($addons == "true")
$sql = "SELECT * FROM addonprices $dcid ORDER BY addon_desc ASC";
else
$sql = "SELECT l.l_name, p.* FROM pricing p LEFT JOIN locations l ON l.location_id=p.datacentre_id $dcid ORDER BY CASE splitsize WHEN 'f' THEN 0 WHEN 'w' THEN 1 WHEN 'h' THEN 2 WHEN 'q' THEN 3 WHEN '2U' THEN 4 WHEN '1U' THEN 5 ELSE 6 END DESC, amps ASC";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$returnarr[] = $row;
}
header('Content-type: application/json');
echo json_encode($returnarr);
}
我需要在两个 select 语句中添加另一个表,加入$dcid
,表被调用slas
,列是currency
我尝试了一些事情但没有运气。
我正在尝试将货币拉入 javascript 文件以使用此 switch 语句获取价格:
var currency = "";
switch (row.currency) {
case '1' :
currency = "£";
break;
case '2' :
currency = " $";
break;
case '3' :
currency = "€";
break;
default:
currency = "£";
break;
}
即使货币应该等于 2 或 3,它仍然显示为默认值......我不确定是 switch 语句错误还是 sql 查询。
更新
只是对这一行有问题:
$sql = "SELECT l.l_name, p.*, slas.currency FROM pricing p LEFT JOIN locations l ON l.location_id=p.datacentre_id LEFT JOIN slas ON slas.datacentre_id = p.datacentre_id $dcid ORDER BY CASE splitsize WHEN 'f' THEN 0 WHEN 'w' THEN 1 WHEN 'h' THEN 2 WHEN 'q' THEN 3 WHEN '2U' THEN 4 WHEN '1U' THEN 5 ELSE 6 END DESC, amps ASC";
摘自下面的答案。