Saturday 7 May 2011

Mysql_fectch_row and Mysql_table_name and Mysql_list_tables and Mysql_list_dbs php script




Mysql_list_dbs:  By using this function we can get the list of database available in database server.

Mysql_list_tables: By using this function we can get the list of tables available in database.

Mysql_table_name: By using this function we can get the table name of a result set.

Mysql_fectch_row: By using this function we can read a record from result set and we can locate the result set pointer at the beginning of the next record. It returns the record values as a numeric array.

How to fetch the database table values?
How to display the database on browser?


Script: save this file in htdocs as script.php and open the browser type http://localhost/script.php

<table border="12">
<th style="background-color:yellow; color:red"> Username </th>
<th style="background-color:yellow; color:red"> Password </th>
<?php
mysql_connect("localhost","root","");
mysql_select_db("mynewdb");
$data=mysql_query("select * from tbl_user");
$count=1;
while ($rec=mysql_fetch_row($data))
{
if($count%2==0)
$color="blue";
else
$color="green";
$count++;
echo "<tr style='background-color:$color'>
<td> $rec[0]</td><td><$rec[1]</td></tr>";
}
?>
</table>



2 comments:

  1. Jackson has been able to meet a lot of new friends php notes this week. It's so fun that some of my very close friends are php notes having babies around the same time.

    ReplyDelete
  2. This picture was taken on Wednesday with 2 of my closest friends from nursing school. Stacy Morris had Will php notes same day Jackson was born, and our hospital rooms were next to each ophp notesr. Katie Guess had McNeill about a month later. (Melanie, we'll have to get you and Mattie in php notes picture next time!)

    ReplyDelete