Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Values in arrays.

    I have an array that is processing values from a form. My array is being recieved correctly from the form.

    Array ( [answer] => Array ( [0] => 1 ) [TimeOfDay] => Morning [Topics] => Yes [filename] => questionnaire1 )
    I'm having some trouble with some codec while processing it. My code is like so:
    PHP Code:
    $e 1;
    $b count($array["answer"]);
    for (
    $i=0$i $b$i++)
    {
    if (
    $answer[$i]== $e) {
             
    $answer_sql[$e] = $e;

             echo 
    "<br>";
             echo 
    "The if value of answer_sql is $answer_sql[$e]" "<br>";

         }else {
               
    $answer_sql[$e] = 0;
               
    $i $i-1;               //HOLDS THE KEY TILL VALUE IS FOUND

               
    echo "<br>";
               echo 
    "The else value of answer_sql is $answer_sql[$e]" "<br>";

         }
         
    $e++;}

    I never get a response from the first "echo". It skips to the second "echo" in the "else". I've been looking at this forever and I'm pretty sure my problem is with "$answer[$i]== $e". The purpose is to pull the value from answer of the array and compare it, but I don't think I'm doing it the right way. With the received array like so it should never get to the "else".
    Last edited by geewhiz; 04-29-2006 at 02:01 AM.

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,852
    Thanks
    22
    Thanked 157 Times in 148 Posts
    Can you do a var_dump() for the $array and $answer arrays, and post the output?

    It's not clear what is in these arrays.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok,
    here is var_dump($array):

    array(4) { ["answer"]=> array(1) { [0]=> string(1) "1" } ["TimeOfDay"]=> string(7) "Morning" ["Topics"]=> string(3) "Yes" ["filename"]=> string(14) "questionnaire1" }
    and here is var_dump($array["answer"]):

    array(1) { [0]=> string(1) "1" }
    At other times there will be more values in the $answer array which I will increment through and compare with $e.
    Last edited by geewhiz; 04-29-2006 at 05:10 AM.

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,852
    Thanks
    22
    Thanked 157 Times in 148 Posts
    sorry if I wasn;t clear...also, what is in the array $answer from this line of code:

    PHP Code:
    $answer[$i]== $e 
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #5
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,852
    Thanks
    22
    Thanked 157 Times in 148 Posts
    Basically, it's like this...for this line of code:

    PHP Code:
    $b count($array["answer"]); 
    $b in this case is clearly equal to 1.

    so your code is really saying this:

    PHP Code:
    for ($i=0$i 1$i++)
    {
          if (
    $answer[$i]== $e
          {
                
    // do something
          
    }
          else 
          {
                
    // do something else
          
    }

    you;re going through your for loop ONLY one time. For the one time the loop is executed, your condition is this:

    $answer[0] == 1
    It is clear that $answer[0] is NOT equal to 1, since the code inside your else statement is being executed. there inlies your problem...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #6
    New Coder
    Join Date
    Feb 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry for being such a nub
    I just did this simple code:

    PHP Code:
    $i=0;
    echo 
    "The value in answer 0 is $answer[$i]" "<br>";
    echo 
    "<br>"
    And my result was:

    The value in answer 0 is
    I got no result back. So I have to be accessing the $answer part of $array incorrectly?
    In this case $answer[0] should be equal to 1 from my recieved array.

    Here is my recieved array:
    Array ( [answer] => Array ( [0] => 1 ) [TimeOfDay] => Morning [Topics] => Yes [filename] => questionnaire1 )
    Last edited by geewhiz; 04-29-2006 at 06:37 AM.

  • #7
    New Coder
    Join Date
    Feb 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just to clarify. The reason $answer is an array inside of $array is because it will contain more than one value like so:

    Array ( [answer] => Array ( [0] => 1 [1] => 3 [2] => 16 ) [TimeOfDay] => Afternoon [Topics] => Yes [filename] => questionnaire1 )

  • #8
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,852
    Thanks
    22
    Thanked 157 Times in 148 Posts
    Do a var_dump($answer) and then see what you get....
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #9
    New Coder
    Join Date
    Feb 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    chump,
    Just wanted to say thanks! Getting var_dump($answer)=NULL helped more than you can imagine. Everything working great now!
    Thanks again.

  • #10
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,852
    Thanks
    22
    Thanked 157 Times in 148 Posts
    you're welcome, glad you figured it all out and it's working for you now.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •