In this tutorial I am going to show you how to fetch data from mysql using php. Let\u2019s take an example of my last post that was insert data in mysql using php form<\/a>. In that post I have created a form with 2 fields and save both of fields in a mysql table with datetime. In this post we are going to fetch data from posts table. <\/p>\n We have already created database as demo in my previous post so no need to create new database. Only mysql database connection is required. <\/p>\n If you want fetch all records against Step 1: Create database connection: <\/h3>\n
\r\n\r\n<\/pre>\n
Step 2: Write and run mysql fetch query<\/h3>\n
$sql<\/code> variable is a sql statement.
$result <\/code> is calling
mysqli_query()<\/code> function which takes 2 parameter, 1 is a database connection and 2 is a sql statement. <\/p>\n
\r\n\r\n<\/pre>\n
Step 3: Fetch Single row <\/h3>\n
mysqli_fetch_row()<\/code> function is used to fetch row against sql statement.<\/p>\n
\r\n\t$singleRow = mysqli_fetch_row($result);\r\n\tprint_r($singleRow);\r\n<\/pre>\n
$sql<\/code> query then you need to apply while loop.<\/p>\n
\n