Thursday, June 26, 2014

print data by reusable code in PHP


database namd : student table name : stud table name : course Def: print data by reusable code and table name as per given can have any fields

<?php
$link=mysql_connect("localhost","root","");
mysql_select_db("student");
$res=mysql_query("select * from stud");
printdata($res);

echo "<hr>";
$res=mysql_query("select * from tblcourse");
printdata($res);

function printdata($datas)
{
echo "<table border=1>";
while($row=mysql_fetch_array($datas,MYSQL_NUM))
{
echo "<tr>";
foreach($row as $k=>$v)
{
echo "<td>",$v,"</td>";
}
echo "</tr>";
}
echo "</table>";

}
?>


No comments: