You are on page 1of 17

Step 4

register_action.php
Selects the database
Step 4
register_action.php Executes the mysql query to
store the registered
mentee information into
database
Step 5

Step 5: Run your registration form from the localhost now


Step 6

Step 6: Check your database. It should be updated somewhat like that


Connecting Database to PHP

Now how do we fetch the data stored in database from frontend ??


Retrieving Data From
MySQL
There are four different ways to fetch the data from database using PHP.

▪Mysql_fetch_array()
▪Mysql_fetch_row()
▪Mysql_fetch_assoc()
▪Mysql_fetch_object()

All of the above will return one row from table at a time and then the next row
and so on . So usually we use these functions along with a while loop
mysql_fetch_ro
w()
$query = mysql_query (“select * from tbl_baabtra_mentees");
while($fetch=mysql_fetch_row($query))
{
echo $fetch[0]; //prints first column the retrieved row
echo $fetch[1]; //prints second column the retrieved row
}
mysql_fetch_asso
c()
$query = mysql_query (“select * from tbl_baabtra_mentees");
while($fetch=mysql_fetch_assoc($query))
{
echo $fetch[‘vchr_uname’]; //prints first column the
retrieved row
echo $fetch[‘vchr_phone’]; //prints second column the
retrieved row
}
mysql_fetch_arra
y()
$query = mysql_query (“select * from tbl_baabtra_mentees");
while($fetch=mysql_fetch_array($query))
{
echo $fetch[0]; //prints first column the retrieved row
echo $fetch[‘vchr_phone’]; //prints second column the
retrieved row
}
mysql_fetch_obje
ct()
•$query = mysql_query (“select * from tbl_baabtra_mentees");
while($fetch=mysql_fetch_object($query))
•{
• echo $fetch -> ‘vchr_uname’; //prints first column the retrieved row
echo $fetch -> ‘vchr_phone’; //prints second column the retrieved
row
•}
mysql_fetch_obje
ct()
•$query = mysql_query (“select * from tbl_baabtra_mentees");
while($fetch=mysql_fetch_object($query))
•{
• echo $fetch -> ‘vchr_uname’; //prints first column the retrieved row
echo $fetch -> ‘vchr_phone’; //prints second column the retrieved
“Returns an object with properties that correspond to the fetched row and moves
row the internal data pointer ahead.”
•}
Okay…!!
So what are we waiting for now..??
Lets do it then
Let’s Get Back With Our
Task
Step 7: Set a header to redirect from
‘register_action.php’ to ‘view_baabtra_mentees.php’

header(‘Location: view_baabtra_mentees.php’);
Let’s Get Back With Our
Task

Step 8: Now fetch the data from tbl_baabtra_mentees and display it in a


table format.
Step 8
uses mysql_fetch_row function.
returns each row of data from the
mysql table
Step 8
fetches using the column
number

You might also like