Help with array sample error in PHP

-2

I have to consult a MySQL database (Server version: 5.5.55-38.8-log - Percona Server (GPL), Release 38.8, Revision 11f5bbd) that carries the barrels of a brewery.  The fields are few and simple: barrel number, lot, location and date of last movement. My problem is that when I do the query, the first result disappears , which, for example to check stock, gives us a barrel of less, and when a query is made to see how many barrels there are in a client, gives us one less and so with all the queries. Here is my code. The example is to consult all the barrels of a lot.

    <?php
    $result=mysql_query("select * from stock where lote='$lote'");
    $row=mysql_fetch_array($result);
    rsort($row);

    <div class="row" style="background-color:#000">

    <?php  while ($row = mysql_fetch_array($result)) {?>

    <div class="col-sm-1" style="background-color:#000">
    <?php echo $row ["barril"];?>
    </div>

    <div class="col-sm-1" style="background-color:#000">
    <?php echo $row['lote'];?>
    </div>

    <div class="col-sm-2" style="background-color:#000">
    <?php echo $row ["ubicacion"];?>
    </div>

    <div class="col-sm-1" style="background-color:#000">
    <?php echo $row['cap'];?>
    </div>

    <div class="col-sm-2" style="background-color:#000">
    <?php echo $row['fechaultimo'];?>
    </div>

    <br/>
    <?php } mysql_free_result($result);?> 
    </div>
asked by Damian Bericat 23.08.2018 в 03:28
source

1 answer

1

I think the problem may come in that you read the first record before the loop but you do not do anything with it:

$row=mysql_fetch_array($result);

And then when you start the loop you call mysql_fetch_array again, retrieving the following record that you are trying:

<?php  while ($row = mysql_fetch_array($result)) {?>

I would try to remove the first line that I mentioned and the next one. These two, let's go:

$row=mysql_fetch_array($result);
rsort($row);
    
answered by 23.08.2018 в 12:06