Select PHP + Mysql

Asked

Viewed 132 times

0

Guys, I’m a beginner in web programming and I’m having trouble creating a CRUD, the insert worked OK, but the next step is SELECT is not running as it should and I would like you to help me see what my mistake is. I’m doing it this way:

<?php 
$conect = mysqli_connect('127.0.0.1','root','');
$db = mysqli_select_db($conect, 'Crud');
$query_select = "SELECT altura, cpf, endereco, nascimento, nome, peso  FROM Cliente";                
$select = mysqli_query($conect, $query_select);
$fetch = mysqli_fetch_row($select);
while ($fetch = mysqli_fetch_row($select)) {
    echo "<p>".$fetch[0]."</p>";
}
?>

1 answer

0


The problem is that you take the first query value before and do nothing, in the while it takes the value below and the first is "lost".

<?php 
    $conect = mysqli_connect( '127.0.0.1', 'root', '' );
    $db = mysqli_select_db( $conect, 'Crud' );
    $query_select = "SELECT altura, cpf, endereco, nascimento, nome, peso FROM Cliente";
    $select = mysqli_query( $conect, $query_select );
    while( $fetch = mysqli_fetch_row( $select ) )
    {
        echo $fetch[0];
    }
?>

It is good to check whether the query was successfully executed before processing if( $select ).

  • Thank you very much João, I am very used to java type languages, c# and when I arrived in php I was a bit lost. But you cleared up a lot!

Browser other questions tagged

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