Jump to content

3 Days Of Head Scraching And Still Cant Get This?


hopbop

Recommended Posts

Ok so what I am trying to do is pull infromation form a DB got that bart done and stor it into a a way were i can take information and run reports like how many people are between the ages or 10-20 witch i can get to one i can get this in a way were all 4 test input datas are not in one big array but seprit arrys hres the code

 

 

the code right now {

<?php
require_once('../../inc/globals.php');
$connection = mysql_connect( $DB_HOST, $DB_USER, $DB_PASS ) or die( mysql_error() );
mysql_select_db( $DB_NAME ) or die( mysql_error() );



 $result = mysql_query( "SELECT * FROM form_data WHERE last_update >= 2012-10-01 AND form_template_id >= 14;" ) or die( mysql_error() );

 while($row = mysql_fetch_array( $result, MYSQL_ASSOC ))
 {
  $jsonIterator = new RecursiveArrayIterator(json_decode(trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $KEY, $row{'data'}, MCRYPT_MODE_ECB)), true));


   foreach ($jsonIterator as $key => $val)
   {

    $items[] = $val;
   }
  }



   print_r($items);
  echo"<br><br/>";
?>

 

 

it outputs {

Array ( [0] => jesse [1] => I [2] => cooper [3] => 372-08-2716 [4] => Howard M.S. [5] => Graduated H.S. [6] => 3.8 [7] => jessecooper832@gmail.com [8] => (239) 887-7714 [9] => (239) 887-7714 [10] => Yes [11] => Both [12] => 3640 n goldenrod rd [13] => winter park [14] => FL [15] => 32792 [16] => 25 [17] => 03/09/1987 [18] => Male [19] => United States Citizen [20] => No [21] => Both [22] => No [23] => No [24] => White [25] => Non-Military [26] => No [27] => No [28] => No [29] => 3 [30] => $ 44,986 - 50,715 [31] => Employment [32] => Masters Degree [33] => i dont know [34] => i dont know [35] => Yes [36] => 7th [37] => 10th [38] => No [39] => Knowledgable [40] => Knowledgable [41] => Knowledgable [42] => Knowledgable [43] => Knowledgable [44] => Knowledgable [45] => Knowledgable [46] => Knowledgable [47] => Knowledgable [48] => Knowledgable [49] => Knowledgable [50] => Knowledgable [51] => Knowledgable [52] => Knowledgable [53] => Knowledgable [54] => Financial Aid Application Assistance,Referral to Support Agencies [55] => I Agree [56] => Jesse [57] => I [58] => Cooper [59] => 372-08-2711 [60] => Carver M.S. [61] => Graduated H.S. [62] => 3.8 [63] => jessecooper832@gmail.com [64] => (239) 887-7714 [65] => (239) 887-7714 [66] => Yes [67] => Both [68] => 3640 N. Goldenrod .Rd [69] => Winter Park [70] => FL [71] => 32792 [72] => 25 [73] => 03/09/1987 [74] => Male [75] => United States Citizen [76] => No [77] => * [78] => self [79] => No [80] => No [81] => White [82] => Non-Military [83] => No [84] => No [85] => No [86] => 3 [87] => $ 44,986 - 50,715 [88] => Employment [89] => Masters Degree [90] => UCF [91] => dont know [92] => Yes [93] => 7th [94] => 10th [95] => No [96] => Knowledgable [97] => Knowledgable [98] => Knowledgable [99] => Knowledgable [100] => Knowledgable [101] => Knowledgable [102] => Knowledgable [103] => Knowledgable [104] => Knowledgable [105] => Knowledgable [106] => Knowledgable [107] => Knowledgable [108] => Knowledgable [109] => Knowledgable [110] => Knowledgable [111] => Knowledgable [112] => I Agree [113] => jesse [114] => I Agree [115] => Tutoring,Academic Advising [116] => what [117] => T [118] => heck [119] => 789-45-6132 [120] => Carver M.S. [121] => 8th grade [122] => 4.0 [123] => shakethatthing@club.com [124] => (798) 456-1230 [125] => (789) 456-1231 [126] => Yes [127] => Both [128] => 435345 test vill [129] => here [130] => FL [131] => 12345 [132] => 20 [133] => 03/12/1992 [134] => Female [135] => United States Citizen [136] => No [137] => Both [138] => No [139] => No [140] => whatwhat_club [141] => Asian [142] => Vision/Hearing [143] => Non-Military [144] => Free [145] => No [146] => No [147] => 4 [148] => $ 16,336 - 22,065 [149] => Employment [150] => Student Financial Aid [151] => GED [152] => Yes [153] => None [154] => None - But I DO plan to take it before graduating [155] => No [156] => No Knowledge [157] => Little Knowledge [158] => No Knowledge [159] => Little Knowledge [160] => No Knowledge [161] => No Knowledge [162] => No Knowledge [163] => No Knowledge [164] => No Knowledge [165] => Little Knowledge [166] => Little Knowledge [167] => No Knowledge [168] => No Knowledge [169] => Little Knowledge [170] => No Knowledge [171] => Some Knowledge [172] => Financial Aid Application Assistance,Academic Advising/Counseling,Referral to GED Program [173] => I Agree )

 

the problum is all 4 are in one array and me being new to arrays dont understand how to make them all have the same [key] for each time it loops?

 

if that makes any sence?

Link to comment
Share on other sites

I have o clue which array index is the age and you didn't tell us that. But, my understanding is that you want the records grouped by age ranges. You also didn't state what those ranges are - which could change the best logic to use. Instead of putting them in different arrays, put them into separate keys in the same array. Example:

 

$query = "SELECT * FROM form_data WHERE last_update >= 2012-10-01 AND form_template_id >= 14;";
$result = mysql_query($query) or die( mysql_error() );

while($row = mysql_fetch_array( $result, MYSQL_ASSOC ))
{
   $jsonIterator = new RecursiveArrayIterator(json_decode(trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $KEY, $row{'data'}, MCRYPT_MODE_ECB)), true));
   foreach ($jsonIterator as $key => $val)
   {
    //Set AGE_KEY to the appropriate key for the age
    $age = $jsonIterator[AGE_KEY];
    if($age<10)
    {
	    $primaryKey = '0-9';
    }
    elseif($age<=20)
    {
	    $primaryKey = '10-20';
    }
    elseif($age<=30)
    {
	    $primaryKey = '21-30';
    }
    elseif($age<=40)
    {
	    $primaryKey = '31-40';
    }
    elseif($age<=50)
    {
	    $primaryKey = '41-50';
    }
    else
    {
	    $primaryKey = '51+';
    }
    $items[$primaryKey][] = $val;
   }
}

Link to comment
Share on other sites

I have o clue which array index is the age and you didn't tell us that. But, my understanding is that you want the records grouped by age ranges. You also didn't state what those ranges are - which could change the best logic to use. Instead of putting them in different arrays, put them into separate keys in the same array. Example:

 

age is just one of them each item in the array needs it?

 

all im trying to findo out is how do i get the now 1 lage array with 4 sepret people into sepret arrays ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.