PHP MySQL select Query Syntax From the Table with MySQLi Example Code

PHP Select Data in MySQL

To select data from the table select query is used. To select all row so you have to use ” * ” symbol.

But if you want to select a particular row or column so you have to put the name of a particular row or column.

Example – 1 Select Data in MySQL Example

$server = "localhost";
$user = "root";
$password = "";
$dbname = "elex_tutorial";

// Create connection
$connection = mysqli_connect($server, $user, $password, $dbname);
// Check connection
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());

$sql = "SELECT id, firstname, lastname, email_id FROM `User`";
$result = mysqli_query($connection, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
} else {
    echo "0 results";


In the above code, we select the record of the “User” table of “elex_tutorial” database. If the code run then the output show a Record of a particular column which are selected in your code.

You can leave a response, or trackback from your own site.

3 Responses to “PHP MySQL select Query Syntax From the Table with MySQLi Example Code”

  1. Rich Reihl says:

    I’ve been exploring for a little for any high quality articles or blog posts on this sort of house . Exploring in Yahoo I finally stumbled upon this site. Studying this info So i am happy to exhibit that I’ve an incredibly just right uncanny feeling I came upon exactly what I needed. I so much no doubt will make sure to do not fail to remember this web site and give it a glance on a continuing basis.|

  2. Julian Bruk says:

    I have read so many articles concerning the blogger lovers however this piece of writing is truly a nice piece of writing, keep it up.|

  3. Kiara says:

    If you are going for most excellent contents like myself,
    just visit this web site all the time for the reason that it offers feature contents, thanks

Leave a Reply to the article

Learn PHP

Learning & Certifications
Follow Us
Facebook Icon   Linked In Icon   Twitter Icon  
Validation and Recognition

Valid CSS! Valid HTML5!          Protected by Copyscape