Results 1 to 10 of 10
Thread: Function only returns one value
-
07-11-2005, 11:56 AM #1Newbie
- Join Date
- Apr 2005
- Posts
- 16
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'),);
Any help appreciated.
-
07-11-2005, 12:10 PM #2Junior Guru Wannabe
- 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?
-
07-11-2005, 12:26 PM #3Newbie
- Join Date
- Apr 2005
- Posts
- 16
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;
}
-
07-11-2005, 12:52 PM #4Newbie
- Join Date
- Apr 2005
- Posts
- 16
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;
}
-
07-11-2005, 01:27 PM #5Junior Guru Wannabe
- 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.
-
07-11-2005, 01:43 PM #6Newbie
- Join Date
- Apr 2005
- Posts
- 16
Array is supposed to be printing...
Array should be printing this.
PHP Code:[dynamic key from $rsTimestamp->fields[0]] => array('something')
I'm clearly on the wrong track.
Where am I going wrong?
-
07-11-2005, 01:48 PM #7Junior Guru Wannabe
- 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
)
)
*/
-
07-11-2005, 01:50 PM #8Newbie
- Join Date
- Apr 2005
- Posts
- 16
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.
-
07-11-2005, 01:55 PM #9Newbie
- Join Date
- Apr 2005
- Posts
- 16
Got it. Thanks a lot for your help.
-
07-12-2005, 09:14 PM #10Newbie
- Join Date
- Jul 2005
- Location
- Pa
- Posts
- 9
cool..learn something new