0

我有几个查询导致动态部分,但我认为这应该是有道理的

$memberID = 7;
$oreVolumePriceQuery = "SELECT od.oreID, od.oreType, od.name, od.inGameID, od.size, ir.officialCorpRate FROM oreData od JOIN itemRates ir ON od.inGameID = ir.typeID order by od.oreID asc";
$oreVolumePriceResult = mysql_query($oreVolumePriceQuery);
while($row = mysql_fetch_assoc($oreVolumePriceResult)){
    $oreType = $row['oreType'];
    $getRefiningRateQuery = "SELECT '$oreType' FROM memberData WHERE member_id = '$memberID'";
    $getRefiningRateResult = mysql_query($getRefiningRateQuery);
    while($row = mysql_fetch_assoc($getRefiningRateResult)){
    $refiningRate = $row['$oreType'];

第一个查询返回类似于下面的结果(实际上是 31 行,但 2 行就足够了)

oreID | oreType | name     | inGameID | size | officialCorpRate
 1    | veld    | veldspar | 1230     | 0.1  | 10.21
 2    | scor    | scordite | 1228     | .15  | 10.2

根据第一行,第二个查询最终是

SELECT veld FROM memberData WHERE member_ID = '7'

这个查询返回正确的结果

veld
 .7

但这一切都在最后一行分崩离析,它动态地选择从查询中提取哪一列。有没有办法解决这个问题?

4

3 回答 3

2

您正在定义两个相同的 $row 名称,将第二个 fetch 重命名为 $row1 forexample

 while($row = mysql_fetch_assoc($oreVolumePriceResult)){
$oreType = $row['oreType'];
$getRefiningRateQuery = "SELECT '$oreType' FROM memberData WHERE member_id = '$memberID'";
$getRefiningRateResult = mysql_query($getRefiningRateQuery);
while($row1 = mysql_fetch_assoc($getRefiningRateResult)){
$refiningRate = $row1[$oreType];
于 2013-01-13T12:46:06.080 回答
0

Variables in single quotes won't be evaluated, so instead of

$refiningRate = $row['$oreType'];

you probably want

$refiningRate = $row[$oreType];

Also, is there a reason you aren't just joining the memberData table to the original query?

于 2013-01-13T12:47:26.397 回答
0

根据经验,您应该始终mysql_error();在查询因未知原因失败时添加。所以,试试这个,因为我做了 3/4 的改变:

$oreVolumePriceQuery = "SELECT od.oreID, od.oreType, od.name, od.inGameID, od.size, ir.officialCorpRate FROM oreData od JOIN itemRates ir ON od.inGameID = ir.typeID order by od.oreID asc";
$oreVolumePriceResult = mysql_query($oreVolumePriceQuery) or die(mysql_error());
while($row = mysql_fetch_assoc($oreVolumePriceResult)){
    $memberID = 7;
    $oreType = $row['oreType'];
    $getRefiningRateQuery = "SELECT '$oreType' FROM memberData WHERE member_id = '$memberID'";
    $getRefiningRateResult = mysql_query($getRefiningRateQuery) or die(mysql_error());
    while($row = mysql_fetch_assoc($getRefiningRateResult)){
    $refiningRate = $row['$oreType'];
于 2013-01-13T12:46:19.950 回答