Search answer with a line minus

0

Using practically the same php, except for the search part, returns the complete list, when I add the search part, one is always missing, usually the 1st of the list.

Id pac Last Name DNI 1 Alvarez Gomez Alvaro 80100105

2 Bernardez Alvarez Bernardo 80100100

3 Carles Alvarez Carlos 80100101

4 Daniels Alvaro Daniela 80100102

5 Estebanez Gomez Esteban 80100103

6 Alvarez Gomez Alejo 80100104

<?php  
     include('99_conn.php');

$search = '';
if (isset($_POST['search'])) {
    $search = $_POST['search'];
}
$sql020 = "SELECT 00_idpac, 00_apellido, 00_nombres, 00_dni from $t00 where 00_apellido LIKE '%".$search."%' ";
if (!$res020 = $conexion->query($sql020) )
{
    echo $conexion->error;
    exit;
}
$fila = $res020->fetch_assoc();
    if($res020->num_rows > 0){
        echo "<table>";
            echo "<tr>";
                echo "<th>Id </th>";
                echo "<th>Apellido</th>";
                echo "<th>Nombres</th>";
                echo "<th>DNI</th>";
            echo "</tr>";
            echo "<tr><th>. </th> </tr>";
        while($rw020 = $res020->fetch_array()){
            echo "<tr><td> </td> </tr>";
            echo "<tr>";
                echo "<td>" . $rw020['00_idpac'] . "</td>";
                echo "<td>" . $rw020['00_apellido'] . "</td>";
                echo "<td>" . $rw020['00_nombres'] . "</td>";
                echo "<td>" . $rw020['00_dni'] . "</td>";
            echo "</tr>";
        }
        echo "</table>";
}
mysqli_close($conexion);
?>

I would appreciate any guidance in this regard. 2nd question in a similar case many years ago, I could establish that if I pressed any part of the row, I would refer to another page with the id (for example, I paste a single line) as in this case the html is included in the php and not the other way around, like in the example I hit, I'm half lost. Thanks.

<td width="100"><div><a href="Gar_4_invc_liv.php?reemplazo=<?php echo $row_RS7['reemplazo']; ?>" target="_self" class="link"><?php echo $row_RS7['desc']; ?></a></div></td>
    
asked by Silvia Gaviota Garcia 04.10.2017 в 02:18
source

1 answer

1

Why is the first one always missing?

$fila = $res020->fetch_assoc();

$ res020 is a resource for accessing results and fetch_assoc () reads the first record and advances the pointer, then, in the while ($ rw020 = $ res020 -> fetch_array ()) starts with the second record and, automatically, advances the pointer for the next iteration. When the records are finished, it returns false and ends the cycle.

In summary, fetch _ * () methods read the current record and advance the pointer.

How to create a link?

    while($rw020 = $res020->fetch_array()){
        // Modifica la ruta (pagina.php), variable (id)
        // y valor ($rw020['00_idpac'])
        // de acuerdo a tus necesidades
        $link = 'pagina.php?id=' . $rw020['00_idpac'];
        echo "<tr><td> </td> </tr>";
        echo "<tr>";
            // Donde necesites el link:
            echo "<td><a href=\"$link\">" . $rw020['00_idpac'] . "</a></td>";
            echo "<td>" . $rw020['00_apellido'] . "</td>";
            echo "<td>" . $rw020['00_nombres'] . "</td>";
            echo "<td>" . $rw020['00_dni'] . "</td>";
        echo "</tr>";
    }

With this the link was added only in the first column, but there is no problem if you decide to add it also in the others.

    
answered by 04.10.2017 / 07:00
source