using mysqli how do i select a certain data field from a table in php

  Kiến thức lập trình

using mysqli how do i select a certain data field from a table in php

i tried the

$query = “SELECT * FROM comments WHERE username = $search;”;

//check connection
if($mysqli->connect_error){
    die("connection failed: " . $mysqli->connect_error);
}

$result = $mysqli->query($query);

if($result->num_rows > 0){
    //output data for each row
    while($row = $result->fetch_assoc()){
        echo "
        <tr>
            <td>" . $row["id"] . "</td>
            <td>" . $row["username"] . "</td>
            <td>" . $row["comment_text"] . "</td>
      
        </tr>";


    }

}

New contributor

odjirigho dalil is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT