Results 1 to 10 of 10
  1. #1

    Function only returns one value

    PHP Code:
    function daySelect() { 
    $sql="SELECT distinct A.submission_id FROM fp_forms_submitted A, fp_fields_submitted B ";
    $sql.="WHERE A.form_id='10117' AND A.submission_id=B.submission_id AND ";
    $sql.="B.form_field_name='broker_code' AND B.form_field_value='388008'";
    $rsTest rsMySqlDw($sql);
    $rsTest->MoveFirst();
        while (!
    $rsTest->EOF)
            {
                
    $sub_id $rsTest->fields[0];
                
    $sql="SELECT form_field_value FROM fp_fields_submitted ";
                
    $sql.="WHERE submission_id=$sub_id AND ";
                
    $sql.="form_field_name='fp_timestamp'";
                
    $rsTimestamp rsMySqlDw($sql);
                
    $intDays date("j"$rsTimestamp->fields[0]);
                
    $rsTimestamp->MoveFirst();
                while (!
    $rsTimestamp->EOF)
                {
                return 
    $intDays;
                
    $rsTimestamp->MoveNext();
                }
    $rsTest->MoveNext();
            }
    }

    $days = array(daySelect()=>array('else'),); 
    daySelect() is only returning the first value. There are 10 all together. If I "echo" instead of "return" in the function, I get all the values, but echo obviously doesn't work for the variable.

    Any help appreciated.

  2. #2
    Join Date
    Feb 2003
    Posts
    70
    Return kills the function and returns the value.

    Have you tried to create the array inside the function and then return the array?

  3. #3

    Like this?

    PHP Code:
    function daySelect() { 
    $sql="SELECT distinct A.submission_id FROM fp_forms_submitted A, fp_fields_submitted B ";
    $sql.="WHERE A.form_id='10117' AND A.submission_id=B.submission_id AND ";
    $sql.="B.form_field_name='broker_code' AND B.form_field_value='388008'";
    $rsTest rsMySqlDw($sql);
    $rsTest->MoveFirst();
        while (!
    $rsTest->EOF)
            {
                
    $sub_id $rsTest->fields[0];
                
    $sql="SELECT form_field_value FROM fp_fields_submitted ";
                
    $sql.="WHERE submission_id=$sub_id AND ";
                
    $sql.="form_field_name='fp_timestamp'";
                
    $rsTimestamp rsMySqlDw($sql);
                
    $rsTimestamp->MoveFirst();
                while (!
    $rsTimestamp->EOF)
                {
                
    $intDays[] = array(date("j"$rsTimestamp->fields[0]));
                
    $rsTimestamp->MoveNext();
                }
    $rsTest->MoveNext();
            }
            return 
    $intDays;


  4. #4

    Wrong values

    Okay, "return $intDays;" is returning an array, but not the "date("j", $rsTimestamp->fields[0]" as the key of the array like I want it to.

    Any help appreciated.

    PHP Code:
    function daySelect() { 
    $sql="SELECT distinct A.submission_id FROM fp_forms_submitted A, fp_fields_submitted B ";
    $sql.="WHERE A.form_id='10116' AND A.submission_id=B.submission_id AND ";
    $sql.="B.form_field_name='broker_code' AND B.form_field_value='388008'";
    $rsTest rsMySqlDw($sql);
    $rsTest->MoveFirst();
        while (!
    $rsTest->EOF)
            {
                
    $sub_id $rsTest->fields[0];
                
    $sql="SELECT form_field_value FROM fp_fields_submitted ";
                
    $sql.="WHERE submission_id=$sub_id AND ";
                
    $sql.="form_field_name='fp_timestamp'";
                
    $rsTimestamp rsMySqlDw($sql);
                
    $rsTimestamp->MoveFirst();
                while (!
    $rsTimestamp->EOF)
                {
                
    $intDays[] = array(date("j"$rsTimestamp->fields[0])=>array('something else'));
                
    $rsTimestamp->MoveNext();
                }
    $rsTest->MoveNext();
            }
            return 
    $intDays;


  5. #5
    Join Date
    Feb 2003
    Posts
    70
    What is the array printing?

    If you had

    PHP Code:
    $intDays[] = array(date("j"$rsTimestamp->fields[0]) => 'something else'); 
    echo 
    '<pre>';
    print_r($intDays);

    /*
    Array
    (
        [0] => Array
            (
                [31] => something else
            )

    )
    */

    // or if you leave it like you had it

    $intDays[] = array(date("j"$rsTimestamp->fields[0]) => array('something else')); 
    echo 
    '<pre>';
    print_r($intDays);

    /*
    Array
    (
        [0] => Array
            (
                [31] => Array
                    (
                        [0] => something else
                    )

            )

    )
    */ 
    Last edited by keithslater; 07-11-2005 at 01:35 PM.

  6. #6

    Array is supposed to be printing...

    Array should be printing this.

    PHP Code:
    [dynamic key from $rsTimestamp->fields[0]] => array('something'
    so that I can populate the $days variable.

    I'm clearly on the wrong track.

    Where am I going wrong?

  7. #7
    Join Date
    Feb 2003
    Posts
    70
    So then you either want:

    PHP Code:
    $intDays[date("j"$rsTimestamp->fields[0])] = 'something else'
    echo 
    '<pre>';
    print_r($intDays);

    /*
    Array
    (
        [31] => something else
    )
    */

    // or

    $intDays[date("j"$rsTimestamp->fields[0])] = array('something else'); 
    echo 
    '<pre>';
    print_r($intDays);

    /*
    Array
    (
        [31] => Array
            (
                [0] => something else
            )

    )
    */ 

  8. #8
    If I do a "return $intDays[0]" at the end of the function, it gives me what I need for one record obviously. I need them all though.

  9. #9
    Got it. Thanks a lot for your help.

  10. #10
    cool..learn something new

Posting Permissions

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