开发者社区> 问答> 正文

检查PHP中其他文件的值

我试图弄清楚如何比较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>

展开
收起
社区秘书 2019-12-09 17:01:59 491 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
阿里云栖开发者沙龙PHP技术专场-深入浅出网络编程与swoole内核-吴镇宇 立即下载
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载