简体   繁体   English

如何从我的表中获取最后一条记录?

[英]How to get the last record from my table?

I am calling some data from my table in phpmyadmin and it duplicates the table for the amount of data that is in the one of phpmyadmin, and I only want the last data that is in my database我正在 phpmyadmin 中从我的表中调用一些数据,它复制了 phpmyadmin 中的数据量的表,我只想要我数据库中的最后一个数据

    </div>
      <?php

    $sql="SELECT * from roberto";
    $result=mysqli_query($conexion,$sql);

    while($mostrar=mysqli_fetch_array($result)){
    ?>
     <table class="table is-striped is-narrow is-hoverable is-fullwidth">
  <thead>
    <tr>
      <th>Tipo</th>
      <th>Niveles</th>
      <th>Estado</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>pH Sensor <spab></th>
      <td><p>Nivel de pH: <strong><span id="PHvalue"></span><?php echo $mostrar['nivelph']; ?></strong></p>  
      </td>
      <td>Funcionando</td>
  </tbody>
  <tbody>
    <tr>
      <th>Caudalímetro</th>
      <td><p><strong><?php echo $mostrar['caudal']; ?>10L/min</strong></p>
      </td>
      <td>Funcionando</td>
  </tbody>
  <tbody>
    <tr>
      <th>Bomba subir pH ↑</th>
      <td><span>""" + str(ph) + """pH</span>
      </td>
      <td>Subiendo el pH↑</td>
  </tbody>
  <tbody>
    <tr>
      <th>Bomba bajar pH ↓</th>
      <td><span>""" + str(ph) + """pH</span>
      </td>
      <td>Bajando el pH↓</td>
  </tbody>
    <tr>
      <th>Nutrientes</th>
      <td><span>1mL/24horas</span>
      </td>
      <td>Activando bomba</td>
  </tbody>
</table>
</section>
<?php
}
?>

ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

如果你想要表中所有行的最后一个,那么这是答案:

SELECT * FROM roberto ORDER BY id DESC LIMIT 1;

SELECT * FROM table_name ORDER BY id DESC LIMIT 1;

此代码带来了插入数据库连接的最后一个 id

printf("Last inserted record has id %d\n", mysql_insert_id($conn));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM