Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert this function to work with MySQL syntax?

Status
Not open for further replies.

Apollo6

Technical User
Joined
Jan 27, 2000
Messages
418
Location
US
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 = &quot;<table $sTable>&quot;;
$strTable .= &quot;<tr>&quot;;
for ($n=1; $n<=$cFields; $n++)
{
$strTable .= &quot;<td $sRow><b>&quot;. str_replace(&quot;_&quot;, &quot; &quot;, odbc_field_name($res, $n)) . &quot;</b></td>&quot;;
}
$strTable .= &quot;</tr>&quot;;
while(odbc_fetch_row($res))
{
$strTable .= &quot;<tr>&quot;;
for ($n=1; $n<=$cFields; $n++)
{
if (odbc_result($res, $n)=='')
{
$strTable .= &quot;<td $sRow>&nbsp;</td>&quot;;
}
else
{
$strTable .= &quot;<td $sRow>&quot;. odbc_result($res, $n) . &quot;</td>&quot;;
}
}
$strTable .= &quot;</tr>&quot;;
}
$strTable .= &quot;</table>&quot;;
echo $strTable;
}
 
The error you are getting is because your invocation of mysql_query() is returning FALSE rather than a resource handle.

This can be caused, with the use of a SELECT statement, by an invalid SQL query.

Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top