first thing: you don't really need a printf function for that ( echo or print can work too)
it's simple... all you need to know is the use of html table tag & connecting your php code to the backend data.
code might go like this :-
it's better to use the data for connection in a separate file like I am using db_login.php
<?php
$db_host = 'localhost';
$db_database = 'store';
$db_username = 'md';
$db_password = 'md';
?>
Then connection would go like :
<?php
include('db_login.php'); // including the login file
$connection = mysql_connect($db_host, $db_username, $db_password );
if(!connection) // in case connection fails
{
die("Could not connect to the database: <br>" . mysql_error());
}
//now select the database
$db_select = mysql_select_db($db_database);
if(!$db_select) //in case selection fails
{
die("could not select the database<br>" . mysql_error());
}
// query
$query = "select * from info where rollno < 3" ;
//putting the result of your query
$result = mysql_query ( $query );
if ( !$result )
{
die("could not query the database:<br>" . mysql_error());
}
while ( $result_row = mysql_fetch_row($result) )
{
echo "rollno $result_row[1]" . "<br>";
echo "name $result_row[0]"."<br><br>";
}
$result = mysql_query ( $query );
/* In case you want to access your columns using the names in associative arrays, use
while ( $result_row = mysql_fetch_array($result, MYSQL_ASSOC) )
{
echo "rollno " . $result_row['rollno'] . "<br>";
echo "name " . $result_row['name']."<br><br>";
}
*/
mysql_close($connection); //closes your database connection
?>