Re: Check if Record was Entered Today.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I believe you need a "while" instead of an "if".  The "if" will only run
until the first occurance is true.   Whereas a "while" will run to find
all
results that are true until it goes thru all of the result rows..

No, I think he's checking to make sure that $db contains a resource id and
not a boolean false (meaning the file did not load or contains no data).

Maybe a more descriptive way may be to say:

<code>
if ($db !== false && is_resource($db)) {
   doStuff();
}
</code>

To the next problem:

'exit' terminates the script.  You should not be using exit there.

When you want a loop structure to stop and goto what flows next in the code,
use break:

<code>
for ($i = 0; $i < count($items); $i++) {
   if ($items[$i] == $arbitraryCondition) {
       echo 'I do not need to doStuff() anymore.';
       break;
   }
   doStuff();
}
</code>

When you want a loop structure to skip over something but still continue to
loop, use continue:

<code>
for ($i = 0; $i < count($items); $i++) {
   if ($items[$i] == $arbitraryCondition) {
       echo 'I do not need to doStuff() on this item.';
       continue;
   }
   doStuff();
}
</code>

When reading through values in an array or other structure, you can while or
do/while loop:

<code>
$db = getDb('location/db.dbf');
while($row = db_fetch_array($result)) {
   if ($row['AcctActivation'] != $date) {
       continue;
   } elseif ($row['AcctActivation'] == $date) {
       break;
   }
   doStuff();
}
</code>

Isn't there a way to search for and select only the rows with the account
number though? If you're looking for needles in a (potentially large)
haystack, this sounds like an expensive process for something SQL or other
could do better/faster.

========

Incidentally, does this mean you solved the file access problems from this
thread:

http://news.php.net/php.general/255542

--
Jared Farrish
Intermediate Web Developer
Denton, Tx

Abraham Maslow: "If the only tool you have is a hammer, you tend to see
every problem as a nail." $$

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux