1

I'm showing records in a table from my database.

BUT If I have 6 records, my .php file shows me 5... It shows me one record less: I've looking in pages like this, but I still have the error...

Any idea?

This is my code:

    <?php 
    include 'conexion.php';
    $contabla=conexion();
    $sqltabla="select * from precotizacion p, producto pro where p.idproducto=pro.id";
    $resutadotabla=mysql_query($sqltabla,$contabla);
    $dato=mysql_fetch_array($resutadotabla);

$contador=0;
while ($dato=mysql_fetch_array($resutadotabla))
{
    $contador++;
    echo "<td>".$contador."</td>";
    echo "<td>".$dato['id']."</td>";
    echo "<td>".$dato['parte']."</td>";
    echo "<td>".$dato['descripcion']."</td>";
    echo "<td><input size='3' name='pcanitdad' id='idcantidad' value ='1' onchange='editarproducto(this.value)'> </td>";
    echo "<td>".$dato['pfinal']."</td>";
    echo "<td>subtotal</td>";
    echo "<td>Descuento aplicado</td>";
    echo "<td>total";
    echo "<td><select name='desc' id='desc' onchange='descuento(this.value)'>
    <option >Aplicar</option>
    <option >1</option>
    <option >2</option>
    <option >3</option>
    <option >4</option>
    <option >5</option>
    </select></td>";
    echo '<td><a href="abcs/eliminarprecotizacion.php?id='.$dato['id'].'"> Eliminar producto </a></td>';
    echo "</tr>";
}
?> 
Community
  • 1
  • 1
Jean
  • 593
  • 2
  • 6
  • 19
  • Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). [This article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide. – Jay Blanchard Nov 04 '14 at 17:40
  • Already try to running the mysql query into your mysql or phpmyadmin? How many records that it shows? – Crazenezz Nov 04 '14 at 17:44
  • @Crazenezz On my phpmyadmin shows me ALL the recrods... the problem is my .php file shows me one less – Jean Nov 04 '14 at 17:45
  • Did you try echoing without classes and ids – Indra Kumar S Nov 04 '14 at 17:47

2 Answers2

2

Before going into while, please delete this line:

$dato=mysql_fetch_array($resutadotabla);

That line will get the first records and then it will go into the while loop, and starting with the second one.

Crazenezz
  • 3,416
  • 6
  • 31
  • 59
1

I found the mistake!! I had to remove this line:

$dato=mysql_fetch_array($resutadotabla);
Jean
  • 593
  • 2
  • 6
  • 19