Hi I hope I am in the right place, sorry if I am not- please let me know where I might find some help.
Someone else has created a function that queries a database and loops through behaviours and answers for upto 17 questions, this can be for each 'behaviour' or 'response class'. Questions 1 to 16 are matched whether the behaviour or response class is likely to occur or always happens, once this has been ascertained it is checked against a range of constants and that text is added to an array. The problem arises if question 17 is answered and I need to pull out the typed in response, it is not to be matched to a constant. If question 17 is likely to occur or always happens then the answer to 17-b needs to be added to the array.
I have tried several ways of trying this but have found that either I get nothing returned or just the questions 1 to 16 or as thea ttached doc just the numbers of all the questions.
I have tried to attach a document with more details and some of the code but it keeps failing to upload. I could email it if any one is kind enough to help.
I am really stuck.
:cursing:
php nested multidimentional arrays
Started by auroraswim, Feb 09 2010 01:25 PM
10 replies to this topic
#1
Posted 09 February 2010 - 01:25 PM
|
|
|
#2
Posted 09 February 2010 - 01:28 PM
sorry, but I really don't understand what you need help with. can you try to explain it a little bit easier/better?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#3
Posted 09 February 2010 - 01:48 PM
can I email you more info I have an attachement that has more details but could not upload it?
#4
Posted 09 February 2010 - 02:00 PM
first, try to explain what it is about so I understand better what you are trying to do.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#5
Posted 09 February 2010 - 02:20 PM
Thank you for giving me your time.
I have a query that pulls information and puts this in a multidimentional array:
Each behaviour or response class has a question no i.e. F1 and an answer e.g.Behaviour sometimes occurs (See array below).
If the question number is F1 to F16 then it is matched to a defined value and the original question(defined value) is added to an array if the behaviour or response class is likely to occur or always occurs. The array is used to add the answers to a report.
When the question no is F17 e.g. [F17] => Response Class sometimes occurs [F17-b] => Availability to other people ) then the answer in this case Availability to other people is the value that needs to be added to the array not a lookup for a defined variable. Hope this makes more sense.
This is the code I have for response classes.
I have a query that pulls information and puts this in a multidimentional array:
Each behaviour or response class has a question no i.e. F1 and an answer e.g.Behaviour sometimes occurs (See array below).
If the question number is F1 to F16 then it is matched to a defined value and the original question(defined value) is added to an array if the behaviour or response class is likely to occur or always occurs. The array is used to add the answers to a report.
When the question no is F17 e.g. [F17] => Response Class sometimes occurs [F17-b] => Availability to other people ) then the answer in this case Availability to other people is the value that needs to be added to the array not a lookup for a defined variable. Hope this makes more sense.
This is the code I have for response classes.
$result = $Database->Query_ret_Result("SELECT c.clusterbatchid,clusname, questionid as question, value FROM ".TBLEXT.FASTTRIGGERS." f inner join ".TBLEXT.CLUSTERNAMES." c on c.clusterbatchid = f.behaviourid AND c.formid = f.formid WHERE f.formid = '".$FormID."' AND trigtype ='cluster'");
While($row = mysql_fetch_array($result)){
$masterarray[$row['clusname']][$row['question']] = $row['value'];
}
foreach($this->behaviours as $key1 => $array){
if(isset($array['type']) && $array["type"] == "cluster"){
foreach($array as $key => $value){
if($key != "type"){
$this->fulldetails[$this->names[$key1]][$key] = ucfirst(constant($key)).".";
}
}
(sorry it is so long I should have selected a smaller one.)Array ( [Maddy is angry] => Array ( [F1] => Behaviour sometimes occurs [F2] => Behaviour never occurs [F3] => Behaviour sometimes occurs [F4] => Behaviour sometimes occurs [F5] => Behaviour sometimes occurs [F6] => Behaviour never occurs [F7] => Behaviour sometimes occurs [F8] => Behaviour sometimes occurs [F9] => Behaviour sometimes occurs [F10] => Behaviour sometimes occurs [F11] => Behaviour sometimes occurs [F12] => Behaviour sometimes occurs [F13] => Behaviour never occurs [F14] => Behaviour sometimes occurs [F15] => Behaviour sometimes occurs [F16] => Behaviour sometimes occurs [F17] => Select... ) [Maddy is tired] => Array ( [F1] => Behaviour sometimes occurs [F2] => Behaviour never occurs [F3] => Behaviour sometimes occurs [F4] => Behaviour sometimes occurs [F5] => Behaviour never occurs [F6] => Behaviour never occurs [F7] => Behaviour sometimes occurs [F8] => Behaviour never occurs [F9] => Behaviour sometimes occurs [F10] => Behaviour sometimes occurs [F11] => Behaviour never occurs [F12] => Behaviour never occurs [F13] => Behaviour sometimes occurs [F14] => Behaviour sometimes occurs [F15] => Behaviour sometimes occurs [F16] => Behaviour sometimes occurs [F17] => Select... ) [Response Class 1] => Array ( [F3] => Response Class sometimes occurs [F2] => Response Class sometimes occurs [F1] => Response Class sometimes occurs [F8] => Response Class sometimes occurs [F7] => Response Class sometimes occurs [F6] => Response Class sometimes occurs [F5] => Response Class sometimes occurs [F11] => Response Class never occurs [F10] => Response Class sometimes occurs [F9] => Response Class is very likely to occur [F16] => Response Class sometimes occurs [F15] => Response Class sometimes occurs [F14] => Response Class sometimes occurs [F13] => Response Class sometimes occurs [F4] => Response Class never occurs [F12] => Response Class sometimes occurs [F17] => Select... ) [Response Class 2] => Array ( [F1] => Response Class never occurs [F2] => Response Class never occurs [F3] => Response Class never occurs [F4] => Response Class never occurs [F5] => Response Class sometimes occurs [F6] => Response Class sometimes occurs [F7] => Response Class sometimes occurs [F8] => Response Class never occurs [F9] => Response Class never occurs [F10] => Response Class sometimes occurs [F11] => Response Class sometimes occurs [F12] => Response Class sometimes occurs [F13] => Response Class is very likely to occur [F14] => Response Class sometimes occurs [F15] => Response Class sometimes occurs [F16] => Response Class is very likely to occur [F17] => Select... ) [Response Class 3] => Array ( [F1] => Response Class never occurs [F2] => Response Class never occurs [F3] => Response Class sometimes occurs [F4] => Response Class never occurs [F5] => Response Class sometimes occurs [F6] => Response Class is very likely to occur [F7] => Response Class sometimes occurs [F8] => Response Class never occurs [F9] => Response Class sometimes occurs [F10] => Response Class sometimes occurs [F11] => Response Class never occurs [F12] => Response Class never occurs [F13] => Response Class is very likely to occur [F14] => Response Class sometimes occurs [F15] => Response Class sometimes occurs [F16] => Response Class is very likely to [F17] => Response Class sometimes occurs [F17-b] => Availability to other people ) )
#6
Posted 10 February 2010 - 12:27 AM
Hi did you have time to look at my problem? There is a little more information if you need it.
:)
:)
#7
Posted 10 February 2010 - 12:33 AM
ok, so you have questions and different possible answers in your db. what will you do with this then?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#8
Posted 10 February 2010 - 12:45 AM
Each behaviour/response class has 17 questions. Questions 1 to 16 are checked to see if they are likey to happen or always happen, if so the answer is compared to a range of definitions that return the original question. This is then added to the $this->fulldetails[$this->names[$key1]][$key] = ucfirst(constant($key))."."; array. I can get these questions back and added to the array with the code above. The issue is with question 17. Question 17 has the same format with question number and answer so I need to check that the behaviour is likey to happen or always happens(this is in the array) the next step is instead of checking against definitions I need to add the answer to 17-b to the array.
Hope this makes sense.
Thanks for your time
Hope this makes sense.
Thanks for your time
#9
Posted 10 February 2010 - 01:14 AM
I might be over simplifying this but isn't the easiest thing to do check to see if your on question f17 then simply define the answer to f17-b using an if/else statement?
#10
Posted 10 February 2010 - 02:07 AM
I have thought of this and tried a solution but I couldn't get the 17-b value to add to the array.Will look at it again and see if I can get it to work.
#11
Posted 10 February 2010 - 02:22 AM
I have tried the following code as a test but I do not get any results returned for the 17-b value. Sorry can't see the wood for the trees how would I get the value for 17-b?.
$result = mysql_query("SELECT c.clusterbatchid,clusname, questionid as question, value FROM bai_assess_fasttriggers f inner join bai_assess_clusternames c on c.clusterbatchid = f.behaviourid AND c.formid = f.formid WHERE f.formid = 11 AND trigtype ='cluster' order by clusterbatchid");
While($row = mysql_fetch_array($result, MYSQL_ASSOC)){
//debugging
//echo $row['clusname']," ", $row['question']," ",$row['value'] ."<br>";
switch ($row['question']){
case "F1":
If ($row['value'] == FTRIGLIKELY2){
$fulldetails = F1."<br>";
}else {
If ($row['value'] == FTRIGALWAYS2){
$fulldetails = F1."<br>";
}
}
break;
case "F2":
If ($row['value'] ==FTRIGLIKELY2){
$fulldetails .= F2."<br>";
}else {
If ($row['value'] ==FTRIGALWAYS2){
$fulldetails .= F2."<br>";
}
}
break;
case "F17":
If ($row['value'] ==FTRIGLIKELY2){
$fulldetails .= $row['value']."<br>";
}else {
If ($row['value'] ==FTRIGALWAYS2){
$fulldetails .= $row['value']."<br>";
}
}
break;
$result = mysql_query("SELECT c.clusterbatchid,clusname, questionid as question, value FROM bai_assess_fasttriggers f inner join bai_assess_clusternames c on c.clusterbatchid = f.behaviourid AND c.formid = f.formid WHERE f.formid = 11 AND trigtype ='cluster' order by clusterbatchid");
While($row = mysql_fetch_array($result, MYSQL_ASSOC)){
//debugging
//echo $row['clusname']," ", $row['question']," ",$row['value'] ."<br>";
switch ($row['question']){
case "F1":
If ($row['value'] == FTRIGLIKELY2){
$fulldetails = F1."<br>";
}else {
If ($row['value'] == FTRIGALWAYS2){
$fulldetails = F1."<br>";
}
}
break;
case "F2":
If ($row['value'] ==FTRIGLIKELY2){
$fulldetails .= F2."<br>";
}else {
If ($row['value'] ==FTRIGALWAYS2){
$fulldetails .= F2."<br>";
}
}
break;
case "F17":
If ($row['value'] ==FTRIGLIKELY2){
$fulldetails .= $row['value']."<br>";
}else {
If ($row['value'] ==FTRIGALWAYS2){
$fulldetails .= $row['value']."<br>";
}
}
break;


Sign In
Create Account


Back to top









