Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : ODBC Functions (Unified) : odbc_result_all

odbc_result_all

Print result as HTML table (PHP 4, PHP 5)
int odbc_result_all ( resource result_id [, string format] )

Examples ( Source code ) » odbc_result_all

<?php
    
//connect to database
    
$Link odbc_connect("mysqlNavioo""phpUser""");

    
//use the freetrade database
    
odbc_do($Link"USE ft3");

    
//prepare query for inserting new SKUs for item 1
    
$Query "INSERT INTO sku (Item, Name, SalePrice) ";
    
$Query .= "VALUES(1, ?, ?) ";
    
$Result odbc_prepare($Link$Query);

    
//insert these rows
    //2003 Calendar, 20.00
    //2004 Calendar, 20.50
    //2005 Calendar, 21.00
    
for($index 2003$index <= 2005$index++)
    {
        
$values[0] = "$index Calendar";
        
$values[1] = 20.00 + (0.50 * ($index-2000));
        
odbc_execute($Result$values);
    }

    
//dump all SKUs for item 1
    
$Query "Select ID, Name, SalePrice " .
        
"FROM sku " .
        
"WHERE Item = 1";
    
$Result odbc_do($Link$Query);
    
odbc_result_all($Result'border="1"');

    
//close connection
    
odbc_close($Link);
?>

Code Examples / Notes » odbc_result_all

rabbott

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!)


php dot net

It is a bit easier and more powerful if you instead use CSS styles within the form argument"
odbc_result_all($res1,  'name="datatable" id="datatable"');


marius

I've written this little function that functions simirarly to odbc_result_all, but works with MySQL:
/**
* This function emulates the odbc_result_all function, which will return a HTML table cosisting of
* the results of an SQL query.
* Usage: pass a mysql result set to this function, and it will return (not output) a string containing
* an HTML table
* Parameters:
* - $result is your mysql result set (result of a mysql_query() function call)
* - $tableFeatures is a string containing any HTML TABLE features you would like in the table
*   (eg. BORDER="0" etc.)
*/
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...


sanjay dot ghimire

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>&nbsp;</td>";
}
else
{
$strTable .= "<td $sRow>". odbc_result($res, $n) . "</td>";
}
}
$strTable .= "</tr>";
}

$strTable .= "</table>";

Print $strTable;

}


cwhite1000

Here is an example of how to use the form argument"
odbc_result_all($res1, "BGCOLOR='#AAFFAA' border='3' width=30% bordercolordark='#FF0000'");


result of odbc_result_all into an array

global $tableau;
function callback($buffer)
{
global $tableau;
$tableau=array();
$tab=explode("</tr>",$buffer);
array_pop($tab);
$entete=explode("</th>",substr($tab[0],11));
array_pop($entete);
foreach($entete as $numcol => $nomcol)
{ $entete[$numcol]=substr($nomcol,4); }
array_shift($tab);
foreach($tab as $numligne => $ligne)
{
  $ligne=explode("</td>",substr($ligne,5));
  array_pop($ligne);
  foreach($ligne as $numcol => $cellule)
  {
   $tableau[$numligne][$entete[$numcol]]=
          htmlentities(substr($cellule,4));
  }
}
}
$req = "select * from table";
$res = odbc_do($id_conn, $req);
ob_start("callback");
odbc_result_all($res);
ob_end_flush();
ob_implicit_flush(0);


hwaarl

Being a bit more helpful, I did get to see all rows by using the function rather than just the method call.
Doesn't work:
  odbc_result_all($res)
Does work:
  $nr = odbc_result_all($res)


martin dot vgagern

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.

cchristianed

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.


zapthezaps dot schulze dot zap

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>&nbsp;</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


Change Language


Follow Navioo On Twitter
odbc_autocommit
odbc_binmode
odbc_close_all
odbc_close
odbc_columnprivileges
odbc_columns
odbc_commit
odbc_connect
odbc_cursor
odbc_data_source
odbc_do
odbc_error
odbc_errormsg
odbc_exec
odbc_execute
odbc_fetch_array
odbc_fetch_into
odbc_fetch_object
odbc_fetch_row
odbc_field_len
odbc_field_name
odbc_field_num
odbc_field_precision
odbc_field_scale
odbc_field_type
odbc_foreignkeys
odbc_free_result
odbc_gettypeinfo
odbc_longreadlen
odbc_next_result
odbc_num_fields
odbc_num_rows
odbc_pconnect
odbc_prepare
odbc_primarykeys
odbc_procedurecolumns
odbc_procedures
odbc_result_all
odbc_result
odbc_rollback
odbc_setoption
odbc_specialcolumns
odbc_statistics
odbc_tableprivileges
odbc_tables
eXTReMe Tracker