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
Please help
Moderator: General Moderators
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
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
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..
?>
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;
}
?>
?>tryinstead
Code: Select all
for ($i = 1; $i <= $row; $i++) {
odbc_fetch_row ($query, $i);
$path = odbc_fetch_result($query, 1);
print $path;
}-
nathanleyton
- Forum Newbie
- Posts: 4
- Joined: Tue Jun 24, 2003 9:59 am
thanks again for trying
i got this
Fatal error: Call to undefined function: odbc_fetch_result()
Anything else you can think of..???
Thanks Again
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
Code: Select all
while (odbc_fetch_row($result)) {
for($i=1; $i<=$Fields; $i++){
echo "Message ";
echo $i;
echo " = ";
echo odbc_result($result,$i);
}
}Constantly = 1
Thanks Again.