Please help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nathanleyton
Forum Newbie
Posts: 4
Joined: Tue Jun 24, 2003 9:59 am

Please help

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
nathanleyton
Forum Newbie
Posts: 4
Joined: Tue Jun 24, 2003 9:59 am

thanks

Post 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;
         
}

?>

?>
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
nathanleyton
Forum Newbie
Posts: 4
Joined: Tue Jun 24, 2003 9:59 am

thanks again for trying

Post by nathanleyton »

i got this

Fatal error: Call to undefined function: odbc_fetch_result()

Anything else you can think of..???


Thanks Again
nathanleyton
Forum Newbie
Posts: 4
Joined: Tue Jun 24, 2003 9:59 am

thanks this works ish

Post 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.
Post Reply