我试图通过像这样的
使用php静态变量来获取数组值$a = $_GET['type'];
if($a==1)
{
$variable = 'cost';
$tablename = 'logistics_bluedart';
}
else if($a==2)
{
$variable = 'shp_cost';
$tablename = 'logistics_prof';
}
else if($a==3)
{
$variable ='shipping_cost';
$tablename = 'logistics_firstflight';
}
$myQuery = mysql_query("select $variable from $tablename");
while($resultData = mysql_fetch_array($myQuery)){
echo $resultData[$variable];
}
但我没有得到任何输出?
答案 0 :(得分:0)
请检查while循环
print_r($resultData);
它的返回数组你可以像成本,shp_cost,shipping_cost这样的密钥包含在数组中。
Other wise used mysql_fetch_assoc($myQuery) instend of mysql_fetch_array($myQuery).
答案 1 :(得分:0)
更改此行:
$myQuery = mysql_query("select $variable from logistics where $type = $a");
<强>替换强>
$myQuery = mysql_query("select $variable from logistics where type = $a");//replace $type to type
答案 2 :(得分:0)
试试这个:
check the $_GET['type'] must not empty.
then check $a must have the values in 1,2,3.
如果上述任何一项没有遵循,那么根据您在上面提到的代码,您将无法获得结果。
-
由于