The following function is written using the "odbc" syntax. It displays query results with column headings, as well as spaces them out when displaying on the page, I'm currently using it so I know it works.
What I want to do is convert this function to be able to work with MySQL. I tried by replacing the following:
odbc_num_fields >> mysql_num_fields
odbc_field_name >> mysql_field_name
odbc_fetch_row >> mysql_fetch_row
odbc_result >> mysql_result
When it runs, I get "Warning: supplied argument is not a valid MySQL result resource" with mysql_num_fields and mysql_fetch_row.
Any help is appreciated.
function odbc_results($res, $sTable)
{
$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>";
echo $strTable;
}
What I want to do is convert this function to be able to work with MySQL. I tried by replacing the following:
odbc_num_fields >> mysql_num_fields
odbc_field_name >> mysql_field_name
odbc_fetch_row >> mysql_fetch_row
odbc_result >> mysql_result
When it runs, I get "Warning: supplied argument is not a valid MySQL result resource" with mysql_num_fields and mysql_fetch_row.
Any help is appreciated.
function odbc_results($res, $sTable)
{
$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>";
echo $strTable;
}