Using select statement we can fetch the data from mysql table.
here we will use 2 function to fetch the data .first is mysql_query() to execute query and mysql_fetch_array() to return the data. this will return data as associative,numeric,or as both.
if you use second parameter/argument in mysql_fetch_array() as MYSQL_ASSOC- it will return array as associative array and using index as name instead of number to fetch the data.
Example
—–
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?php $databasehostname = 'localhost'; $databaseuser = 'root'; $databasepassword = ''; $connection = mysql_connect($databasehostname, $databaseuser, $databasepassword); if(! $connection ) { die('Could not connect: ' . mysql_error()); } $sqlqry = 'SELECT id, name FROM mydoubts_data'; mysql_select_db('mydoubts_data'); $output = mysql_query( $sqlqry, $connection ); if(! $output ) { die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_array($output, MYSQL_ASSOC)) { echo "ID :{$row['id']} <br> ". "NAME : {$row['name']} <br> ". "--------------------------------<br>"; } echo "Fetched data successfully\n"; mysql_close($connection); ?> |