Saturday, 21 May 2011

Learn PHP online : PHP day - 24

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>

No comments:

Post a Comment

Visual comparison of the two methods, creating a simple table.

Option 1, using PHP: // PHP $html = '<table>' ;     foreach ( $data as $row ) {     $html .= '<tr>...