View Full Version : odbc_fetch_into: if no results then...

05-22-2004, 09:46 AM
I am trying to give a default value to a variable if the SQL query didn't give any results. I suspect the if-check to be wrong, but experimenting with == and === didn't give me any results...

$db_result2 = odbc_exec($db_conn, $db_squery) or die (odbc_errormsg());
$success = odbc_fetch_into($db_result2, $db_row2);

if ($success == false) {
$discipline = $i . 'e Discipline';
} else {
$discipline = $db_row2[0];

Thanks for reading :)

05-22-2004, 10:11 AM
I feel stupid.. I tried everything but spellchecking the variable where I echo'ed it.. :D

Nevertheless, can someone explain the difference of == and === to me? I don't understand the manual...

05-22-2004, 12:23 PM
== wil compiare the value.
=== will alos compaire if they are the same variabletype.

For instance,
0 == False can return True (--> meaning they are concidered to be equal)
0 === False will return False (--> meaning they are NOT equal)
Chech the manual, for strpos() to get an example of when this is important.
It gives a fairly comprehensive illustration:
From http://www.php.net/manual/en/function.strpos.php

$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);

// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";

If you woudl use a if ($pos == false), then you would get athe message that a is not found inside abc, because 0 is equal to False and to ''. But it's not identical to False.

05-22-2004, 02:58 PM
Thanks, this totally clears it up.. I had seen the example but didn't understand the difference from just looking at the example itself.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum