I want to echo some values of a query
while(odbc_fetch_row($tableX))
{
for($i=1;$i<=odbc_num_fields($tableX);$i++)
{
if ($i==1)
{
echo odbc_result($tableX,1); //echoed
echo odbc_result($tableX,2); //echoed
echo odbc_result($tableX,21); //echoed
echo odbc_result($tableX,22); //echoed
var_dump(odbc_result($tableX,22)); //returns values
}
else if($i==2)
{
echo odbc_result($tableX,$i).'++';
var_dump(odbc_result($tableX,22)); //returns bool(false) and empty rows
}
else if($i==3)
{
echo odbc_result($tableX,$i).'+';
}
else
{
echo odbc_result($tableX,$i); //($tableX,1) ($tableX,2) ($tableX,3) echoed ($tableX,21) ($tableX,22) not echoed
}
}
}
As I indicated in the comments, some of the odbc_result's raises an error:
cannot get data of column #21 cannot get data of column #22
I (am not sure but) think the issue is:
An error occurs if a column number parameter for a field is less than one or exceeds the number of columns (or fields) in the current record. Similarly, an error occurs if a field with a name that is not one of the fieldnames of the table(s) that is(are) being queried.
Yet, I couldn't see the reason. Thanks in advance.
Edit: Else works if I delete the echoes under if ($i==1)
Both 21 & 22's data type is NCLOB
Fixed it by converting NCLOBs (odbc_result($tableX,21) and odbc_result($tableX,22))
to nvarchar
CAST(BINTOSTR(CAST("COLUMNNAME" AS binary)) as nvarchar)