/    Sign up×
Community /Pin to ProfileBookmark

complete table printer view[emergency]

how to show data on page like phpmyadmin show on printer view page with details like field name and all the data of a particularly table

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@bokehOct 03.2006 — Like this?[code=php]<?php

$db_host = "*****";
$db_username = "*****";
$db_password = "*****";
$db_database = "*****";
$tablename = '*****';

mysql_connect ($db_host , $db_username , $db_password) or die(mysql_error());
mysql_select_db($db_database) or die(mysql_error());

$table = print_table($tablename);

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.mysql_table caption{
color: #008;
font-size: 9pt;
font-family: verdana, sans-serif;
margin: 0 0 5px 0;
white-space: nowrap;
}

.mysql_table th{
color: #008;
font-size: 8pt;
font-family: verdana, sans-serif;

white-space: nowrap;
}

.mysql_table td{
color: #008;
font-size: 8pt;
font-family: verdana, sans-serif;
white-space: nowrap;
}
</style>

<title>MySQL table</title>

</head>

<body>

<?php echo $table ?>

</body>

</html><?php

function print_table($tablename)
{
$output = null;
$query = "SELECT * FROM $tablename";
$query_result = mysql_query($query) or die (mysql_error());
if(mysql_num_rows($query_result) > 0)
{
$output .= '<table class="mysql_table" border="1" cellspacing="0" cellpadding="6">'."n".
'<caption>Table name: "'.$tablename.'"</caption>'."n";
$first_time = true;
while($row = mysql_fetch_assoc($query_result))
{
if($first_time)
{
$first_time = false;
$headings = array_keys($row);
$output .= '<tr>';
foreach($headings as $heading)
{
$output .= '<th>'.$heading.'</th>';
}
$output .= '</tr>'."n";
}
$output .= '<tr>';
foreach($headings as $heading)
{
$output .= '<td>';
$output .= ($row[$heading]) ? $row[$heading] : '&nbsp';
$output .= '</td>';
}
$output .= '</tr>'."n";
}
$output .= '</table>'."n";
}
else
{
$output .= 'The table "'.$tablename.'" does not have anything in it yet'."n";
}
return $output;
}

?>[/code]
Copy linkTweet thisAlerts:
@mahfoozauthorOct 03.2006 — thanks for answer it works

i posted this question with thread name get table data since 10:00 AM but still no response bur recently poste this title and answered, thanks once again
Copy linkTweet thisAlerts:
@mahfoozauthorOct 03.2006 — is it possible to skip 1 or two datafields(heading, data) like data and id,

if yes then how
Copy linkTweet thisAlerts:
@bokehOct 03.2006 — [CODE]function print_table($tablename[color=red], $omit = array()[/color])
{
$output = null;
$query = "SELECT * FROM $tablename";
$query_result = mysql_query($query) or die (mysql_error());
if(mysql_num_rows($query_result) > 0)
{
$output .= '<table class="mysql_table" border="1" cellspacing="0" cellpadding="6">'."n".
'<caption>Table name: "'.$tablename.'"</caption>'."n";
$first_time = true;
while($row = mysql_fetch_assoc($query_result))
{
if($first_time)
{
$first_time = false;
$headings = [color=red]array_diff(array_keys($row), $omit)[/color];
$output .= '<tr>';
foreach($headings as $heading)
{
$output .= '<th>'.$heading.'</th>';
}
$output .= '</tr>'."n";
}
$output .= '<tr>';
foreach($headings as $heading)
{
$output .= '<td>';
$output .= ($row[$heading]) ? $row[$heading] : '&nbsp';
$output .= '</td>';
}
$output .= '</tr>'."n";
}
$output .= '</table>'."n";
}
else
{
$output .= 'The table "'.$tablename.'" does not have anything in it yet'."n";
}
return $output;
} [/CODE]
Now all you need do is feed the function an array of column names to ignore.
Copy linkTweet thisAlerts:
@mahfoozauthorOct 09.2006 — ok thanks

now i want to add a row at the end of table result that calculates all the data( numeric ) verticaly and show the total of each column in the last row. thanks
×

Success!

Help @mahfooz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...