I have a file 'functions.php' in which I have made function to read a table. Now I am calling this function in another php file with class name, Can any one tell me how It will work. Coding is here
"function.php"
class Database{
private $connection;
public function _construct(){
$this->connection=mysql_connect("localhost","root","");
mysql_select_db(opm, $this->connection);
}
// Read Project table
function read_projects()
{
$query = "SELECT * ";
$query .= "FROM projects";
$query .= "WHERE status=1";
$query .="orderby end_date";
$result_set = mysql_query($query, $this->connection);
if($result_set)
{
$rows =array();
if(mysql_num_rows($result_set>0))
{
while($row=mysql_fetch_array($result_set))
{
$rows = $row;
}
}
else {
$rows[0][project_id]=0;
$rows[1][title]="No Record Found";
// All Rows here
//type_id`, `cat_id`, `status`
$rows[2][start_date]="";
$rows[3][end_date]="";
$rows[3][no_of_phases]="";
$rows[4][client_id]="";
$rows[3][type_id]="";
$rows[3][cat_id]="";
$rows[3][status]="";
}
return $rows;
}else {return false; }
}
}
?>
Here is file in which I am calling this function:
main.php
<?php
include("../include/functions.php");
$vars = new Database();
$vars.read_projects();
?>
<table>
<?php while($row){ ?>
<tr>
<td><?php echo $rows[0] ?></td>
<td><?php echo $rows[1] ?></td>
<td><?php echo $rows[4] ?></td>
<td><?php echo $rows[3] ?></td>
<td><?php echo $rows[5] ?></td>
<td><?php echo $rows[8] ?></td>
</tr>
<?php } ?>
</table>