How to show a single record in PHP

0

I have the following code, it connects to the database and executes a query and I store it in result2 until it is all right, but at the time that I print the records I want that only prints a single record only the date and time and not the time with minutes.

Someone could guide me to find a solution.

        <tr class="header">
            <th>Nombre</th>
            <th>fecha</th>
            <th>Hora</th>

            <th>Int</th>        
            <th>
                <p>Escoger Todos</p>
                <input  type="checkbox" id="checkAll"/>
            </th>
        </tr>

<?php

  if($myrow = mysql_fetch_array($result2))
    {
     do
      {
      $cuenta_eventos++;             

?>

 <tr> 
   <th><?php printf("%s",$myrow["nombre"]);?></th>
   <th><?php printf("%s",$myrow["fecha"]);?></th>
   <th><?php printf("%s",$myrow["hora"]);?></th>

   <th><?php printf("%s",$myrow["int"]);?></th>  

   <th><p>Escoger Evento</p><input type="checkbox" class="case" name="case[]" value="<?php printf("%s",$myrow["nombre"]);?>"></th>
 </tr>

 <?php     
      }while ($myrow = mysql_fetch_array($result2));
   }else {
         } 

 ?>

I get the following result:

Nombre     |   Fecha        |   Hora      |   Int

SANT       |   2016-10-03   | '03:00:00'  |     1m
FNAT       |   2016-10-03   | '03:00:00'  |     1m
FNAT       |   2016-10-03   | '03:07:00'  |     1m
FNAT       |   2016-10-03   | '03:016:00' |     1m

The result I want to obtain is the following:

Nombre     |   Fecha        |   Hora      |   Int

SANT       |   2016-10-03   | '03:00:00'  |     1m
FNAT       |   2016-10-03   | '03:00:00'  |     1m
    
asked by Houdini 05.10.2016 в 23:49
source

2 answers

1

As you have been told before, with the date and the parameter H , you already get the result, leaving your code as follows

      <tr class="header">
            <th>Nombre</th>
            <th>fecha</th>
            <th>Hora</th>

            <th>Int</th>        
            <th>
                <p>Escoger Todos</p>
                <input  type="checkbox" id="checkAll"/>
            </th>
        </tr>

<?php

  if($myrow = mysql_fetch_array($result2))
    {
     do
      {
      $cuenta_eventos++;             

?>

 <tr> 
   <th><?php printf("%s",$myrow["nombre"]);?></th>
   <th><?php printf("%s",$myrow["fecha"]);?></th>
   <th><?php printf("%s",date('H', $myrow["hora"]).":00:00";);?></th>

   <th><?php printf("%s",$myrow["int"]);?></th>  

   <th><p>Escoger Evento</p><input type="checkbox" class="case" name="case[]" value="<?php printf("%s",$myrow["nombre"]);?>"></th>
 </tr>

 <?php     
      }while ($myrow = mysql_fetch_array($result2));
   }else {
         } 

 ?>

What has not been clear to me is if you want to only show you a record, in which case to the SQL query, you must add at the end LIMIT 1 , or you want to show all, and only modify the time.

    
answered by 06.10.2016 / 09:52
source
3

To get just the time, just use the format H to pause the date and then fill it with :00:00 :

$time = strtotime($myrow["hora"]);
$hour = date('H', $time).":00:00";
    
answered by 06.10.2016 в 00:13