我试图弄清楚如何比较2个不同文件中的2个不同值。我想从一侧到另一侧比较资源。如果我的资源超出了我的需要,那么我想显示“提交”按钮。谢谢你们!在这两个代码上,我都将字符串从Int转换为一个更容易的比较。我的问题是在A代码的末尾,我在该代码中发出“ IF”语句,并且仅当所有条件都满足时,我才希望它有效。
文件A中的代码,我的升级成本在哪里?数据库将返回所有建筑物以及以下升级成本:
<tr>
<td colspan="2"><b><center>Actual</center></b></td>
<td colspan="7"><b><center>Recursos per passar al proper nivell</center></b></td>
</tr>
<tr>
<td><b><center>Edifici</center></b></td>
<td><b><center>Nivell Actual</center></b></td>
<td><b><center>Seguent Nivell</center></b></td>
<td><b><center>Cristall</center></b></td>
<td><b><center>Fusta</center></b></td>
<td><b><center>Marbre</center></b></td>
<td><b><center>Raim</center></b></td>
<td><b><center>Sofre</center></b></td>
</tr>
<?php
include("connexio.php");
$consulta_edificis="SELECT nom_edifici,nivell FROM edificis ORDER BY id_edifici ASC"; //consultem el nom i el nivell acual del edifici
$resultat_edificis=mysqli_query($connect,$consulta_edificis);
while($consulta_nivell=mysqli_fetch_array($resultat_edificis)) //Treiem el nom i nivell actual.
{
$nivell_actual=(int)$consulta_nivell['nivell']; //convertim el string a numero enter
$nivell_actual=$nivell_actual+1; //sumem 1 ja que a la taula de nivells també tenim el nivell 0.
$consulta_seguent_nivell="SELECT id_nivell,cost_upgrade_cristall,cost_upgrade_fusta,cost_upgrade_marbre,cost_upgrade_raim,cost_upgrade_sofre FROM nivells LIMIT 1 OFFSET $nivell_actual"; //consulta per saber el que ens costarà pujar al seguent nivell.
$resultat_pujar_nivell=mysqli_query($connect,$consulta_seguent_nivell);
while($consulta_cost_seguent_nivell=mysqli_fetch_array($resultat_pujar_nivell))
{ //imprimim resultats
?>
<tr>
<td><?php echo $consulta_nivell['nom_edifici']?></td>
<td><?php echo $consulta_nivell['nivell']?></td>
<td><?php echo $consulta_cost_seguent_nivell['id_nivell']?></td>
<td><?php echo $consulta_cost_seguent_nivell['cost_upgrade_cristall']?></td>
<td><?php echo $consulta_cost_seguent_nivell['cost_upgrade_fusta']?></td>
<td><?php echo $consulta_cost_seguent_nivell['cost_upgrade_marbre']?></td>
<td><?php echo $consulta_cost_seguent_nivell['cost_upgrade_raim']?></td>
<td><?php echo $consulta_cost_seguent_nivell['cost_upgrade_sofre']?></td>
<?php
$cost_cristall=(int)$consulta_cost_seguent_nivell['cost_upgrade_cristall'];
$cost_fusta=(int)$consulta_cost_seguent_nivell['cost_upgrade_fusta'];
$cost_marbre=(int)$consulta_cost_seguent_nivell['cost_upgrade_marbre'];
$cost_raim=(int)$consulta_cost_seguent_nivell['cost_upgrade_raim'];
$cost_sofre=(int)$consulta_cost_seguent_nivell['cost_upgrade_sofre'];
?>
<?php include("materials.php"); ?>
<td><?php if ($cristall>$cost_cristall && $fusta>$cost_fusta && $marbre>$cost_marbre && $raim>$cost_raim && $sofre>$cost_sofre): ?>
<input type="submit" value="enviar">
<?php else: ?>
<p>no</p>
<?php endif; ?></td>
</tr>
<?php
}
}
mysqli_close($connect);
?>
</table>
来自文件B的代码,这里有我的资源:
include("connexio.php");
$consulta_valors="SELECT * FROM materials LIMIT 1";
$resultat_valors=mysqli_query($connect,$consulta_valors);
while($consulta=mysqli_fetch_array($resultat_valors))
{
$consulta['cristall'];
$consulta['fusta'];
$consulta['marbre'];
$consulta['raim'];
$consulta['sofre'];
$cristall=(int)$consulta['cristall'];
$fusta=(int)$consulta['fusta'];
$marbre=(int)$consulta['marbre'];
$raim=(int)$consulta['raim'];
$sofre=(int)$consulta['sofre'];
}
mysqli_close($connect);
?>
</table>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。