Generate table at run time for database data


#1

plz tell me how to generate Table at run time according to data in database in php
i have some idea that it might be done by using Loops but plz help me
e.g
if i have some records in db like name & email
but i don’t know the exact amount or the amount of data is large so how could i generate the desigred amount of rows/columns at run time


#2
Hello mohsin1122, i think you have created a table in you database having following three field id, name, email save below code and put your db connection detail and run i think your looking for this [php] <? /*replace dbuser and dbpassword with your dbusr and password */ $con = mysql_connect("localhost","dbuser","dbpassword"); if (!$con){ die('Could not connect: ' . mysql_error()); } //replace dbname with your database name mysql_select_db("dbname", $con);

//replace tblname with your table
$result = mysql_query(“SELECT * FROM tblname”);
$no_record = mysql_num_rows($result);
if($no_record > 0)
{
echo ‘

’;
echo ‘’;
while($row = mysql_fetch_array($result))
{
echo ‘’;
}
echo ‘
Name Email
’.$row[‘name’].’ ’.$row[‘email’].’
’;
}
else
{
echo ‘There is no record found’;
}
?>
[/php]
i hope this will helpful for you.
Reply your feedback
SR

#3

#4
:) :) :D It's really nice to hear your problem is resolve.. ~~SR~~

#5

plz tell me 1 more thing
if u dont mind

now the records are fetched ,now i want that when i click on any record its all data is filled in text fields for editing,updation


#6
hello mohsin1122, you have to create another code for update data which is based on id. like as echo ' '.$row['name'].' '.$row['email'].' ';

also create a new file that contain the update and insert process.

SR