Page 1 of 1

Please help

Posted: Tue Jun 24, 2003 9:59 am
by nathanleyton
I am using ODBC in PHP and am trying to for loop through my data..

But the command
odbc_result ($query, $i);

in my for loop it is looking to loop through columns rather than rows..

can anyone help me.. I want to loop my results into an array..

I have tried so many variations.

Thanks all
NAthan

Posted: Tue Jun 24, 2003 10:12 am
by volka
right,
odbc_result ( resource result_id, mixed field) fetches a field from the current row.
You're looking for something like odbc_fetch_row ( resource result_id [, int row_number])

http://www.php.net/manual/en/ref.odbc.php
http://www.php.net/manual/en/function.odbc-result.php
http://www.php.net/manual/en/function.o ... ch-row.php

thanks

Posted: Tue Jun 24, 2003 10:20 am
by nathanleyton
I have tried that...

Just tried again thuogh

That retrives the number 1 for every time round the loop.. The correct number of times...

I know my query is OK becuase if i do

odbc_result_all.. it returns all my query fine......

heres my code at the minute..

Code: Select all

$myServer = "MYSERVER";
$DSN = "MYDSN";
$myUser = "MYUSERNAME";
$myPass = "MYPASSWORD";
$myDB = "MYDATABASE";


$ser = odbc_connect ($DSN, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");

$query  = odbc_do($ser, "SELECT DISTINCT Description FROM ActionCodes"); 
$row = odbc_num_rows ($query);
$Fields = odbc_num_fields($query); 



for ($i = 1; $i <= $row; $i++) {
   $path = odbc_fetch_row ($query, $i);
   print $path;
         
}

?>

?>
?>

Posted: Tue Jun 24, 2003 11:08 am
by volka
try

Code: Select all

for ($i = 1; $i <= $row; $i++) {
   odbc_fetch_row ($query, $i);
   $path = odbc_fetch_result($query, 1);
   print $path;
}
instead

thanks again for trying

Posted: Tue Jun 24, 2003 11:12 am
by nathanleyton
i got this

Fatal error: Call to undefined function: odbc_fetch_result()

Anything else you can think of..???


Thanks Again

thanks this works ish

Posted: Tue Jun 24, 2003 11:31 am
by nathanleyton

Code: Select all

while (odbc_fetch_row($result)) {
        
       for($i=1; $i<=$Fields; $i++){
       echo "Message ";
       echo $i;
       echo " = ";
       echo odbc_result($result,$i);
       
   }

}
Only problem now is that it tells me that the $i is not increasing in the For Loop.

Constantly = 1

Thanks Again.