How to Select One Value in PHP MySQL Example?

03-Apr-2023

.

Admin

How to Select One Value in PHP MySQL Example?

Hi Dev,

Here, I will show you how to works how to select one value in php mysql example. if you have question about php and mysql select a single value then I will give simple example with solution. This tutorial will give you simple example of displaying single record from mysql table using php. if you want to see example of php sql get single value with code examples then you are a right place. follow bellow step for select one value display using php and mysql query.

Get only a single value from a specific MySQL row.

Example :


index.php

$sql = CREATE TABLE Student (

StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,

StudentName varchar(20),

StudentMarks int

);

Insert some records in the table using insert command :

$sql = INSERT INTO Student (StudentName, StudentMarks) VALUES('Ram', 66);

$sql = INSERT INTO Student (StudentName, StudentMarks) VALUES('Shyam', 98);

$sql = INSERT INTO Student (StudentName, StudentMarks) VALUES('Krish', 77);

Display all records from the table using select statement :

select * from Student;

Output:

+-----------+-------------+--------------+

| StudentId | StudentName | StudentMarks |

+-----------+-------------+--------------+

| 1 | Ram | 66 |

| 2 | Shyam | 98 |

| 3 | Krish | 77 |

+-----------+-------------+--------------+

Get value from a specific MySQL row :

$sql = SELECT StudentName FROM Student WHERE StudentMarks=98;

Output:

+-------------+

| StudentName |

+-------------+

| Shyam |

+-------------+

I hope it could help you...

#PHP