On Tuesday, April 16, 2002, at 08:58  AM, Scott St. John wrote:

> I have been trying to organize my code better by using functions,

First of all, try organizing your code using whitespace.  Here is an 
example of the code, formatted to be a bit easier to read:

function chkFirstTime($userID)
        global $connection,$db,$userID;
        $sqlChkFirstTime = "    select  fk_userID,
                                                from            firstTime
                                                where   fk_userID = '$userID'";
        $resultFirstTime = mssql_query($sqlChkFirstTime, $connection);
        $rowFirstTime = mssql_fetch_array($resultFirstTime);
        $firstTime = $rowFirstTime["firstTime"];
        if ($firstTime == "") {
                include ('includes/incFirstTime.php');

Now, my first question, is why do you have $userID passed by parameter 
into the function, and also globalized in the function?  I am trying to 
understand this function but this seems like a mistake.  You should 
probably fix this.  Also, I'm not sure what the $db variable is 
globalized for -- why is it needed?  It isn't used in the function, as 
far as I can see.

> especially where I am repeating logic.  The problem seems to be when I 
> run
> a condition within the function, an if statement to check for results 
> of a
> variable.  As is the code seems to be bypasses, but if I put a die; in 
> the
> function after the line that was skipped before I get the desired 
> results.

Why don't you put "print($firstTime)" immediately after the $firstTime = 
$rowFirstTime["firstTime"] line.  It will tell you whether or not there 
is actually a value there.  If there is, then you know why your "if" 
test is failing.  If there is no variable, then you can check to see if 
your includefile is working correctly.



Erik Price
Web Developer Temp
Media Lab, H.H. Brown

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to