©
This document uses PHP Chinese website manual Release
(PHP 4, PHP 5)
odbc_result_all — Print result as HTML table
$result_id
[, string $format
] )Prints all rows from a result identifier produced by odbc_exec() . The result is printed in HTML table format.
result_id
The result identifier.
format
Additional overall table formatting.
Returns the number of rows in the result or FALSE
on error.
[#1] vaibhav [2010-06-08 00:49:28]
code for php mssql odbc connection and executing an stored procedure
<?php
$package_code = 'AUS03B';
$client_id = 499;
$conn = odbc_connect(DSN,USER,PASS,SQL_CUR_USE_ODBC);
//SQL_CUR_USE_IF_NEEDED,SQL_CUR_USE_ODBC ,SQL_CUR_USE_DRIVER SQL_CUR_DEFAULT
$sql_result = odbc_prepare($conn, "EXEC usp_packagesearch_xml '$package_code','$client_id'");
$result = odbc_execute($sql_result);
//$string = odbc_result($sql_result,1);
$string = odbc_result_all($sql_result,"border=1");
?>
[#2] alvaro at demogracia dot com [2009-04-30 02:26:59]
The $format parameter is an optional string that gets inserted in the <table> tag. The string is printed as-is. E.g.:
<?php
odbc_result_all($res, 'id="users" class="listing"');
?>
... prints:
<table id="users" class="listing" >...
[#3] ZAPtheZAPs dot schulze dot zap at zap dot telstra dot com [2004-05-02 02:12:24]
a revised version marius' code that works with Memo fields. (also returns rather than prints strings)
function ODBCResourceToHTML($res, $sTable, $sRow)
{$cFields = odbc_num_fields($res);
$strTable = "<table $sTable ><tr>";
for ($n=1; $n<=$cFields; $n++)
{$strTable .= "<td $sRow><b>". str_replace("_", " ", odbc_field_name($res, $n)) . "</b></td>";}
$strTable .= "</tr>";
while(odbc_fetch_row($res))
{ $strTable .= "<tr>";
for ($n=1; $n<=$cFields; $n++)
{$cell = odbc_result($res, $n);
if ($cell=='') {$strTable .= "<td $sRow> </td>";}
else {$strTable .= "<td $sRow>". $cell . "</td>";}}
$strTable .= "</tr>";}
$strTable .= "</table>";
Return $strTable;}
DEAR MODERATORS: you would save yourselve much much time by making this entire manual into a wiki (ie like http://en.wikipedia.org ) and within a year this would be the best manual on anything!!
best wishes, Erich
[#4] marius at stones dot com [2003-06-24 10:21:52]
I've written this little function that functions simirarly to odbc_result_all, but works with MySQL:
function _mysql_result_all($result, $tableFeatures="") {
$table .= "<!--Debugging output for SQL query-->\n\n";
$table .= "<table $tableFeatures>\n\n";
$noFields = mysql_num_fields($result);
$table .= "<tr>\n";
for ($i = 0; $i < $noFields; $i++) {
$field = mysql_field_name($result, $i);
$table .= "\t<th>$field</th>\n";
}
while ($r = mysql_fetch_row($result)) {
$table .= "<tr>\n";
foreach ($r as $kolonne) {
$table .= "\t<td>$kolonne</td>\n";
}
$table .= "</tr>\n";
}
$table .= "</table>\n\n";
$table .= "<!--End debug from SQL query-->\n\n";
return $table;
}
Enjoy...
[#5] cchristianed at netzero dot net [2003-04-02 10:31:55]
About the $result reseting array instead of using:
1) odbc_fetch_row($result, 1);
use:
2) odbc_fetch_row($result, 0);
1) will fail because it will not show first record, arrays start with subscript 0.
[#6] sanjay dot ghimire at kpmg-infodesign dot com [2002-12-04 03:47:45]
I wrote a small function slightly similiar to odbc_record_all, but there you can use format for both table and rows separately, which is not by odbc_record_all. hope it will be useful some how.
--- Sanjay, Germany
Here is code:
odbc_result_all_ex($result, 'Border=0 cellspacing=0 cellpadding=5', "style='FONT-FAMILY:Tahoma; FONT-SIZE:8pt; BORDER-BOTTOM:solid 1pt gree'");
function odbc_result_all_ex($res, $sTable, $sRow)
{
$cFields = odbc_num_fields($res);
$strTable = "<table $sTable>";
$strTable .= "<tr>";
for ($n=1; $n<=$cFields; $n++)
{
$strTable .= "<td $sRow><b>". str_replace("_", " ", odbc_field_name($res, $n)) . "</b></td>";
}
$strTable .= "</tr>";
while(odbc_fetch_row($res))
{
$strTable .= "<tr>";
for ($n=1; $n<=$cFields; $n++)
{
if (odbc_result($res, $n)=='')
{
$strTable .= "<td $sRow> </td>";
}
else
{
$strTable .= "<td $sRow>". odbc_result($res, $n) . "</td>";
}
}
$strTable .= "</tr>";
}
$strTable .= "</table>";
Print $strTable;
}
[#7] rabbott at calstatela dot edu [2000-08-15 17:46:00]
odbc_result_all($result) cycles through
$result. So a subsequent call to odbc_fetch_row($result) will fail.
You must use odbc_fetch_row($result, 1)
to reset $result. (But when I do that,
I get a crash!)
[#8] martin dot vgagern at gmx dot net [2000-03-25 13:49:14]
As some people stated in the ODBC overview, some buggy drivers always return the number of rows to be -1. AFAIK the only way to help this situation is to count the rows by calls to odbc_fetch_into or odbc_fetch_row and then build the table yourself.