Doubt Select / PHP

Asked

Viewed 96 times

0

I’m making a select in this way.

$stmt = $lokos->prepare("select CODIGO_PROGRAMA, VERSAO_PROGRAMA,
                         DATA_INSERCAO, DESCRICAO_ALTERACAO from
                         programas_padrao Order by DESCRICAO_ALTERACAO DESC");

This select it will pull all the data that has in my data box.

ex: PROGRAMME 1, PROGRAMME 2, PROGRAMA3

Like I do for mine select or through a if display only the latest instead of displaying PROGRAMA1, PROGRAM 2 and 3?

How do I make it display only 3?


That’s the Original code. Which I’m having trouble doing.

<?php

$user = "SYSDBA";
$pass = "masterkey";
try{
    $lokos=new PDO("firebird:localhost=127.0.0.1;dbname=DUOSIG_APLICACAO",$user,$pass);
}catch(PDOException $e) {
    echo "Falha na conexão.".$e->getcode();
}

$stmt = $lokos->prepare("select CODIGO_PROGRAMA, VERSAO_PROGRAMA, DATA_INSERCAO, DESCRICAO_ALTERACAO from programas_padrao Order by DESCRICAO_ALTERACAO DESC");
$stmt->execute();
$dados = $stmt->fetchAll(PDO::FETCH_OBJ);
foreach ($dados as $row) {
   echo "<li class='nome'>{$row->CODIGO_PROGRAMA} </li> ";
 echo "<li class='versao'>{$row->VERSAO_PROGRAMA} </li> ";
echo "<li class='data'>{$row->DATA_INSERCAO} </li> ";
echo "<li class='descricao'><p>{$row->DESCRICAO_ALTERACAO} </p> </li> ";
}

?>  
  • does Where in program code 3, or puts a date field does Where with the date

  • 1

    To limit the registration number, use LIMIT X, where X is the desired amount. The rest depends on your condition of most recent. If it is the last inserted, you must sort downwards by id using ORDER BY id DESC; if it is the last modified record, you need to store the modification date in a column (type updated_at) and make ORDER BY updated_at DESC.

  • @Andersoncarloswoss Your comment is an answer to this question.

  • 1

    @Ismael, it is possible, I did not understand if this is exactly the problem of the author. And it still depends on the information about what the codition is to define the most recent record. Once the author specifies this, it will be possible to reply completely.

  • This "display only 3": you want it to display only 3 results or it shows only the third program?

  • In the following case. I have several results, think the following I HAVE 1 CAR GRAY COLOR AND CAR RED COLOR BLZ ? , In the Gray car I have a door version, 1.2 and the 3 , And in the red car I also have the version 1.2 and the 3, BLZ ?. I enter the panel and stand, VERSION 1 , 2, AND THE 3 of the gray car. And the same day I stand to Versao 1, 2 and 3 of the red car. Instead of getting all versions posted I want to appear only THE FINAL VERSIONS IE RED CAR -> 3 , GRAY CAR -> 3, instead of appearing all.

  • The question applies to the right Firebird? or is mysql itself?

  • 1

    Only to the Firebird

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.