PHP - Fun And Frolic With Multi-dimensional Arrays
This has been so much FUN for me that I couldn't wait to share!
I have a page on a Wordpress site using some special functions in the Theme I am running that displays custom fields in a List after a Form has been filled out for a Particular Post Category. On this page the User can see the results of the Form they just filled out and review them before finally submitting them. I have one function which gathers all of the Custom fields associated with that particular post they have made from the "holding table"--an interim saving instead of keeping them all in a session value exclusively. The form they have just filled out produces one string or value per field EXCEPT in the case of multi-value checkboxes. If on this review page any values are gathered whose $field_type is equal to 'checkbox' then it is guaranteed that those values are stored in an array. Right now the problem is that the existing function that gathers and displays all these custom fields simply shows "Array" everytime it handles the values of one of these checkboxes. In those cases where a row's $field_type = 'checkbox' then in every case there will be an associative array stored in brackets [] that I want when detected to be put into visible list of however many values are found. In the sql statement when it gathers the field $field_type values it will find either "text", "dropdown", "textarea", or "checkbox" in the same id row along with the $field_label, $field_name, $field_values for each record. I want to build more conditions and actions here to handle a situation where it runs into an associative array inside the first array of all of the custom fields. I include the whole function I want to modify further down: It starts out -- echo cp_formbuilder_review($results); and I guess I want something along the lines of-- if($results) {foreach ($results as $result) if (is_array($result) { loop through and put individual array elements in an unordered list with the $field_label associated with each checkbox array} else { continue the loop for all other types of custom fields which are not $field_type=checkbox because all of these custom fields will have values in just one string or one value} For testing purposes, so you know what the values look like underlying this page if I use this statement on the page echo '<br/><br/>("$postvals")-- $postvals PRINT<br/>'; print_r; I will get back this for $_POST echo '$_POST PRINT<br/>just the post and nothing more'; print_r($_POST); ( [post_title] => Stunning rental [cp_checkbox_days] => Array ( => Thursday [1] => Friday ) [cp_checkbox_amenities] => Array ( => Gardener [1] => Watchman ) [cp_checkbox_hello] => Array ( => Smoking Allowed: Outdoor areas only ) [cp_price] => 98888 [cp_street] => 888 Flange [cp_city] => Reynaldo [cp_state] => Virginia [cp_country] => Antartica [cp_zipcode] => 1080 [tags_input] => stunner [post_content] => Wow is all we can say about this one. Right now the visual display shows this for Arrays <ul> <li><label><strong>Category:</strong></label> <div id="review">Affordable Rentals</div> <div class="clr"></div> </li> <li> <label><strong>Title:</strong></label> <div id="review">Stunning stunner</div> <div class="clr"></div> </li> <li> <label><strong>help checkbox:</strong></label> <div id="review">Array</div> <div class="clr"></div> </li> <li> <label><strong>Staff Provided:</strong></label> <div id="review">Array</div> <div class="clr"></div> </li> <li> <label><strong>Suitability:</strong></label> <div id="review">Array</div> <div class="clr"></div> </li> <li> <label><strong>Price:</strong></label> <div id="review">98888</div> <div class="clr"></div> </li> <li> <label><strong>Street:</strong></label> <div id="review">888 Flange</div> <div class="clr"></div> </li> </ul> So, wherever a value shows up like this [cp_checkbox_days] => Array ( => Thursday [1] => Friday ) I need for this array to be iterated and broken up into <li>Thursday</li> <li>Friday</li> HERE IS THE CODE MORSEL that is UNDERPERFORMING! I am hoping a genius like DavidAM can soup this thing up! function cp_show_review($postvals) { global $wpdb; // if there's no form id it must mean the default form is being used so let's go grab those fields if(!($postvals['fid'])) { // use this if there's no custom form being used and give us the default form $sql = $wpdb->prepare("SELECT field_label, field_name, field_type, field_values, field_req " . "FROM ". $wpdb->prefix . "cp_ad_fields " . "WHERE field_core = '1' " . "ORDER BY field_id asc"); } else { // now we should have the formid so show the form layout based on the category selected $sql = $wpdb->prepare("SELECT f.field_label,f.field_name,f.field_type,f.field_values,f.field_perm,m.meta_id,m.field_pos,m.field_req,m.form_id " . "FROM ". $wpdb->prefix . "cp_ad_fields f " . "INNER JOIN ". $wpdb->prefix . "cp_ad_meta m " . "ON f.field_id = m.field_id " . "WHERE m.form_id = '". $postvals['fid'] ."'" . "ORDER BY m.field_pos asc"); } $results = $wpdb->get_results($sql); if($results) { // loop through the custom form fields and display them echo cp_formbuilder_review($results); //from here is where I have to switch to detecting the Arrays associated with checkboxes and explode them and loop them separately into something pretty with its own field_label //and when it has looped through all the Arrays and made them visible it continues looping through the rest of the single value strings and fields } else { echo sprintf(__('ERROR: The form template for form ID %s does not exist or the session variable is empty.', 'cp'), $postvals['fid'] . "\n\n"); } ?> Looks pretty darn easy doesn't it?? Similar TutorialsBasically what I want to do is create an array of inheritance. so here is the levels Owner->Admin->moderator->User->guest owner has all the abilities of admin, moderator, user and guest.. So I want to be able to sort through them and end with an array like this Code: [Select] $array['Owner'] = array('Admin', 'Moderator', 'User', 'Guest'); Currently my code works sort of. Basically Admin is only set to inherit Moderator. Moderator only inherits User. So this code works but only to 2 levels. I don't want to add a billion foeachs within each other for each level(currently 4) but I might add more roils so then I would have to add more foreachs. There must be a magic way to do this. Any feedback is appreciated! Code: [Select] <?PHP $sql = 'SELECT * FROM '.self::$Config['PERMISSIONS']['Database'].'.permissions_inheritance'; $result = DB::Query($sql); while($row = DB::fetch($result)){ if($row['type'] == '0'){ $group_i[$row['child']][] = $row['parent']; }elseif($row['type'] == '1'){ $user_i[$row['child']][] = $row['parent']; } } //echo count($group_i); print_r($group_i); $groups = array(); foreach($group_i as $Key=>$Value){ foreach($Value as $K=>$V){ $new_array[$Key][] = $V; if(isset($group_i[$V]) && is_array($group_i[$V])){ foreach($group_i[$V] as $Q=>$A){ if(is_array($A)){ foreach($A as $C=>$X){ $new_array[$Key][] = $X; } }else{ $new_array[$Key][] = $A; } } } } } Let me know if you have any questions! I hope you enjoy the challenge lolol Hello,
I've been struggling to get array_multisort to work...
If I have this array output...
I'd like to sort on the product sub-array.
The array is called orders and that number 15 is the specific order id.
Array ( [15] => Array ( [clientId] => 1 [clientName] => Bob [o_date] => 2014-01-02 [o_number] => 1 july-append [o_notes] => order on 1 july-append [i_date] => 2014-01-17 [i_number] => 18072014-append [i_notes] => invoiced on 18 july 14 -append [products] => Array ( [0] => Array ( [id] => 37 [prod_id] => 1 [product] => door [qty] => 2 [cost] => 12.121 ) [1] => Array ( [id] => 38 [prod_id] => 2 [product] => window [qty] => 3 [cost] => 22.5 ) [2] => Array ( [id] => 36 [prod_id] => 3 [product] => chair [qty] => 1 [cost] => 300 ) ) ) )So, I've tried a number of variations of this... array_multisort($orders[$theOrder]['products'], SORT_DESC, SORT_NUMERIC, $orders[$theOrder]['products'], SORT_ASC, SORT_STRING); array_multisort($orders[$theOrder]['products']['id'], SORT_DESC, SORT_NUMERIC);etc. etc. - but I seem to get no-where. Can some-one kindly point out my error, please? Thank you. Hello fellow coders! My brain is about to explode! Does anyone have some time to help me with a small problem? I have two multi-dimensional arrays similar to the below: Code: [Select] mysql_table_schedule [0] [firstname] = Roger [id] = xxx [1] [firstname] = Pamela [id] = xxy mysql_table_roster [0] [firstname] = Roger [id] = xxx [1] [firstname] = Pamela [id] = xxy [2] [firstname] = Orsen [id] = xyy I can build both arrays above after grabbing the data from the MySQL database by using a quick for function Code: [Select] for($i = 0; $array[$i] = mysql_fetch_assoc($mysql_roster); $i++) ;but after I have both arrays how do I keep only the records in mysql_table_roster that are in the schedule. Out of each daily schedule only a few people work. I'd like to keep all of the associated information from the roster like first name, last name, phone number, etcetera. If yesterday only Roger and Pamela worked how do I compare by [firstname] and trim the mysql_table_roster to inlclude only the arrays related to Roger and Pamela? I've looked into array_intersect, but have no clue how to specify a comparison by a specific array key within multi-dimensional arrays. Hi guys, I've done a bit of research into sorting a multi-dimensional array that contains the menu information (to be parsed and displayed). Everything that I've read has confused me more than I was when I started. I want it to be sorted by parent (ASC) then by it's sort number (ASC). Code: [Select] Array ( [0] => Array ( [0] => 2 [id] => 2 [1] => About Us [label] => About Us [2] => ?r=about [link] => ?r=about [3] => [relation] => [4] => 0 [parent] => 0 [5] => 10 [sort] => 10 [6] => 0 [active] => 0 ) [1] => Array ( [0] => 3 [id] => 3 [1] => Fleet [label] => Fleet [2] => ?r=about/fleet [link] => ?r=about/fleet [3] => [relation] => [4] => 2 [parent] => 2 [5] => 0 [sort] => 0 [6] => 0 [active] => 0 ) [2] => Array ( [0] => 4 [id] => 4 [1] => Test [label] => Test [2] => ?r=test [link] => ?r=test [3] => [relation] => [4] => 0 [parent] => 0 [5] => 5 [sort] => 5 [6] => 1 [active] => 1 )) Thank you in advance for any help Hello!
First of all, I'm new here. I've been working with PHP for a few months and am really enjoying its capabilities
A little background on the project I'm doing at the mo, I'm creating a small dashboard for grabbing Twitter stats via the API. The result will eventually output in a pretty table showing the daily followers, follower gains (or losses) etc. Here's an example of the table I eventually want to end up with.
So far I have two arrays of data:
$accounts_data is a list of all account names and their associated ID's
$followers_data is a list of all follower counts, for a specific time of day, with an associated account ID (which matches the ID found in $accounts_data, thus pairing the follower count to a specific account)
I'm now trying to combine these two arrays into something more sensible that can then be used to output the table as shown in the link above.
$accounts_data:
array(4) { [0]=> array(2) { ["id"]=> string(4) "1279" ["name"]=> string(13) "AccountName1" } [1]=> array(2) { ["id"]=> string(4) "1280" ["name"]=> string(10) "AccountName2" } [2]=> array(2) { ["id"]=> string(4) "1281" ["name"]=> string(12) "AccountName3" } [3]=> array(2) { ["id"]=> string(4) "1283" ["name"]=> string(11) "AccountName4" } }$followers_data (truncated this data) array(12) { [0]=> array(3) { ["account_id"]=> string(4) "1279" ["date_time"]=> string(19) "2014-11-14 09:00:03" ["followers"]=> string(4) "1567" } [1]=> array(3) { ["account_id"]=> string(4) "1280" ["date_time"]=> string(19) "2014-11-14 09:00:29" ["followers"]=> string(4) "7688" } [4]=> array(3) { ["account_id"]=> string(4) "1279" ["date_time"]=> string(19) "2014-11-14 16:30:35" ["followers"]=> string(4) "1566" } } Hello, here is the PHP situation I'm in. I'll type it out in pseudo-ish code first. <?php $multi_array = array( array("cats", "dogs", "sheep", "walruses"), array("jazz", "larva", "pencils", "derp"), array("to", "much") ); $string = array("the", "cats", "ate", "too", "many", "pencils"); $count = count($string); for($i = 0; $i < $count; ++$i) { if($string[$i] IN ARRAY $multi_array) { THEN replace $string[$i] with a random word in the sub array of the multi-array for example, if $string[$i] is cat, then it would replace it with any of the words in the sub array of multi-array, so it could be "cats", "dogs", "sheep", or "walruses" } } ?> I have no idea how to do this and tried thinking of ways for an hour and a half. I am having a hell of a time getting this to work. I need the keys in an array to be specific, not a sequential number or a row in my database. I need to add to the array through each loop of my while() statement. This code does it, but does not use the keys I specify, after the first entry, it starts assigning numbers to keys. Any guidance would be great. <?php require_once ('includes/config.php'); require_once ('includes/connect.php'); $echoarray = array(); $resultsql = mysql_query("SELECT * FROM clients")or die(mysql_error()); while($row = mysql_fetch_array($resultsql)){ if(empty($echoarray)){ $echoarray = array( 'id' => $row['ID'], 'name' => $row['First_Name'] . " " . $row['Last_Name'], 'price' => $row['Status'], 'number' => $row['Sex'], 'address' => $row['Phys_Street'], 'company' => $row['Agency'], 'desc' => $row['Notes'], 'age' => $row['Date_Birth'], 'title' => $row['Occupation'], 'phone' => $row['Phone'], 'email' => $row['Email'], 'zip' => $row['Phys_Zip'], 'country' => $row['Phys_City'] ); } else { array_push($echoarray, $echoarray['id'] = $row['ID'], $echoarray['name'] = $row['First_Name'] . " " . $row['Last_Name'], $echoarray['price'] = $row['Status'], $echoarray['number'] = $row['Sex'], $echoarray['address'] = $row['Phys_Street'], $echoarray['company'] = $row['Agency'], $echoarray['desc'] = $row['Notes'], $echoarray['age'] = $row['Date_Birth'], $echoarray['title'] = $row['Occupation'], $echoarray['phone'] = $row['Phone'], $echoarray['email'] = $row['Email'], $echoarray['zip'] = $row['Phys_Zip'], $echoarray['country'] = $row['Phys_City'] ); } Any Ideas? I have been trying to solve this problem for a few days now and can't seem to work it out. I'm sure i'm missing some simple point.. I am using a mysql PDO fetch to return 2 fields in each row and then put them into an array of their own: foreach ($st->fetchAll() as $row){ $subs[] = array($row['subscriber'],$row['plant']); Some of the rows share the same $row[0], which is the 'subscriber' field. What I want to do is make up another array with each smaller array having a single, unique $row[0] and any number of added 'plant' fields following (e.g $row[1],$row[2] etc). I've tried all sorts of ways to achieve this but am at a loss. Would someone be able to point me in the right direction ? Thanks. Hello , i am trying to sort a 2d dimensional array by the first column(id) and i havent find anything till now This is my code for the 2d array: $username = $_SESSION['username']; $c = 0; $row=1; $col=1; $users_array = array(); $get_from = mysql_query("SELECT id FROM my_activity WHERE from_user='$username'"); while($fetch1 = mysql_fetch_array($get_from)){ $id[$c] = $fetch1[0]; $get_from_user = mysql_query("SELECT * FROM my_activity WHERE id='$id[$c]'"); $get_user_rows = mysql_num_rows($get_from_user); while($guser = mysql_fetch_array($get_from_user)){ $user[$c] = $guser['to_user']; $users_array[$id[$c]][$user[$c]]= $id[$c].".".$user[$c]; $c++; } } $get_to = mysql_query("SELECT * FROM my_activity WHERE to_user='$username'"); while($fetch2 = mysql_fetch_array($get_to)){ $id[$c] = $fetch2[0]; $get_to_user = mysql_query("SELECT from_user FROM my_activity WHERE id='$id[$c]'"); while($tuser = mysql_fetch_array($get_to_user)){ $user[$c] = $tuser[0]; $users_array[$id[$c]][$user[$c]]= $id[$c].".".$user[$c]; $c++; } } This is what i get if i simply loop the array to get the result: Code: [Select] Array ( [6] => Array ( [checkdate] => 6.checkdate ) [25] => Array ( [asdsadsad] => 25.asdsadsad ) [7] => Array ( [webuser] => 7.webuser ) [9] => Array ( [newuser] => 9.newuser ) [10] => Array ( [bot77un] => 10.bot77un ) ) I am trying to sort it by the ids 6,25,7,9,10 in DESC I have an array which will be below. The array is being built from an XML file, the problem is I need to extrapolate data from it.
I am having trouble with looping through the array properly.
The output should be something like this:
Beth's state is 0 (Where Beth's is the name and 0 is the state)
Clint's state is 0
Array ( [0] => Array ( [did] => 216616014153767704 [known] => 1 [lock] => 0 [state] => 0 [level] => 100 [node] => 30 [port] => 0 [nodetype] => 16386 [name] => Beth's [desc] => LED [colorid] => 1 [type] => multilevel [rangemin] => 0 [rangemax] => 99 [power] => 0 [poweravg] => 0 [energy] => 0 [score] => 0 [productid] => 1 [prodbrand] => TCP [prodmodel] => LED A19 11W [prodtype] => LED [prodtypeid] => 78 [classid] => 2 [class] => [subclassid] => 1 [subclass] => [other] => ) [1] => Array ( [did] => 216616014154116936 [known] => 1 [lock] => 0 [state] => 0 [level] => 100 [node] => 30 [port] => 0 [nodetype] => 16386 [name] => Clint's [desc] => LED [colorid] => 1 [type] => multilevel [rangemin] => 0 [rangemax] => 99 [power] => 0 [poweravg] => 0 [energy] => 0 [score] => 0 [productid] => 1 [prodbrand] => TCP [prodmodel] => LED A19 11W [prodtype] => LED [prodtypeid] => 78 [classid] => 2 [class] => [subclassid] => 1 [subclass] => [other] => ) ) Hey everyone. I'm in the final stage of my thingeee (yay). The last thing I need is to prepare a report, but I'm slightly lost on how to do it. Essentially, I have a query that returns some financial records and need to aggregate the data manually (in PHP). I'm familiar with the foreach($assoc_array as $array) function, and I'd like to use it to manipulate the output as follows: For the first key (instType), this will mark the start of a new table element For a second key (paymentID), this will mark the start of a new table row element For a third key, (instrumentID), this will mark a new column (<td>) Then, I need to sort by two other keys - deptID, userID, accountID How do I accomplish this? Pseudo-code is acceptable (my array is called $data and contains all the keys I listed above) Hi - I have an array which is created from a session variable I must have constructed my array wrong, as for the life of me I can not extract the individual values. I have tried innumerable $key=>$value combinations. I must be doing something stupid, maybe it is obvious, but not to me. I'll be darn grateful if you can help me ! Many Thanks MY array looks like this: Code: [Select] Array ( [quantity] => Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => 1 ) [name] => Array ( [0] => Ribs Large pack 20 pieces [1] => 25 Piece Bag [2] => Sirloin Steak [3] => 50 piece bag of Scalops [4] => Sirloin Steak ) [prodid] => Array ( [0] => 17 [1] => 28 [2] => 27 [3] => 25 [4] => 27 ) ) The CodeIgniter form which generated this array looks like this: Code: [Select] <?php foreach ( $_SESSION['openorders'] as $key=>$value) { ?> <tr align="center"> <td width="30"><?php $data=array('name' =>'quantity[]','value'=>$value['quantity']); echo form_input($data); ?></td> <td><?php echo $value['prodid']; ?></td> <td><?php echo $value['name'];?></td> <td><?php echo $value['ordervalue']; ?></td> <td><?php echo $value['pricelb']; ?></td> <td align="right"><?php echo form_checkbox('delete','delete',FALSE); echo form_hidden('prodid[]', $value['prodid']); echo form_hidden('name[]', $value['name']); echo form_hidden('orderid', $value['orderid']); $totalordervalue += $value['ordervalue']; } ?> Hi guys, I'm still stuck on making this multi-level drop down menu, so I figure that I'll listen to how you guys would do it. I don't necessarily need any code, but just ideas on how to code it. Basically, I need it to store each item in a database. It needs to: be accessed, processed, and formatted with PHP end up returning either a multi-dimensional array, or the raw HTML. Examples: Code: [Select] <?php array( array( 'label'=>'Test', 'link'=>'index.php?r=test', 'sort'=>0, 'children'=>array(--blah blah blah--) ), array(--blah blah blah--) ); Code: [Select] <div id="menu"> <ul> <li><a href="index.php?r=test"><h2>Test</h2></a> <ul> <li><a href="blah">Blah</a> <ul> <li><a href="blah">Blah</a></li> </ul> </li> </ul> </li> </ul> </div> That's pretty much it. If you have any ideas or suggestions, please feel free to help me out. Thank you guys! I have an Array and I am attempting to figure out how I can sort it by date. Example of Said Array: Code: [Select] Array ( [0] => Array ( [userComments0] => Array ( [bodyType] => 0 [created] => 2011-02-01 23:51:43 [currentUserFromGroup] => MEMBER_ONE [body] => We should all wear wooden clogs on Fridays. Who's with me? Huh? Anyone? ) ) [1] => Array ( [userComments1] => Array ( [bodyType] => 0 [created] => 2011-02-09 18:20:51 [currentUserFromGroup] => MEMBER_ONE [body] => Test ) ) [2] => Array ( [userComments2] => Array ( [bodyType] => 0 [created] => 2011-02-11 21:02:23 [currentUserFromGroup] => MEMBER_ONE [body] => TEst ) ) [3] => Array ( [userComments3] => Array ( [bodyType] => 0 [created] => 2011-02-12 17:02:31 [currentUserFromGroup] => MEMBER_ONE [body] => Posting a new idea ) ) [4] => Array ( [userComments4] => Array ( [bodyType] => 0 [created] => 2011-02-13 23:32:19 [currentUserFromGroup] => MEMBER_ONE [body] => Test Idea ) ) [5] => Array ( [userComments5] => Array ( [bodyType] => 0 [created] => 2011-02-10 01:50:34 [currentUserFromGroup] => MEMBER_TWO [body] => Taco sauce is as good as French Toast! ) ) [6] => Array ( [userComments6] => Array ( [bodyType] => 0 [created] => 2011-02-10 01:51:03 [currentUserFromGroup] => MEMBER_TWO [body] => Need to hire more engineers! ) ) [7] => Array ( [userComments7] => Array ( [bodyType] => 0 [created] => 2011-02-10 01:51:42 [currentUserFromGroup] => MEMBER_TWO [body] => Golden Bears are all washed up ) ) [8] => Array ( [userComments8] => Array ( [bodyType] => 0 [created] => 2011-02-12 00:13:14 [currentUserFromGroup] => MEMBER_TWO [body] => The JETS are going to kick ass! ) ) [9] => Array ( [userComments9] => Array ( [bodyType] => 0 [created] => 2011-02-14 02:23:47 [currentUserFromGroup] => MEMBER_TWO [body] => We are getting there! ) ) ) But I have stumped myself on it, and cant wrap my mind around getting it sorted by datetime. I don't know where I should begin on this one fellas. Does anyone know of a way I can natsort a multi-dimension array by a value nested in the array 2 keys deep? I.e. array( 'test1' => array( 'location' => '123 fake street', 'time' => 120 ), 'test2' => array( 'location' => '123 elm street', 'time' => 34 ), 'test3' => array( 'location' => '123 php street', 'time' => 133 ) ); // would become array( 'test2' => array( 'location' => '123 elm street', 'time' => 34 ), 'test1' => array( 'location' => '123 fake street', 'time' => 120 ), 'test3' => array( 'location' => '123 php street', 'time' => 133 ) ); thanks for any help I'm not entirely sure how to phrase the title, so I hope it's appropriate... I have an array which looks like the following.. Code: [Select] Array ( [contact] => Array ( [0] => Array ( [name] => Someone Cool [number] => 1234567890 ) ) [messages] => Array ( [0] => Array ( [message] => A message that was recieved [date] => 1234567890 [type] => 1 ) [1] => Array ( [message] => A message which was sent [date] => 1322175702616 [type] => 2 ) ) [calls] => Array ( [0] => Array ( [datetime] => 1320674980836 [type] => 1 [duration] => 7 [number] => 1234567890 ) [1] => Array ( [datetime] => 1320675327541 [type] => 2 [duration] => 638 [number] => 1234567890 ) ) ) [messages] can have anywhere between 40 and 3000 children [calls] can have anywhere from 0 to 200ish children ** These are generals, but realistically, either can have any number. What I'm trying to do is dump all messages and calls. The catch is this: When dumping a call, a check needs to be run against datestamps and only dump the next call coming out where the datestamp of the call is NEWER than the LAST message dumped, AND OLDER than the message that is to be dump in this cycle of the loop. What I have so far is the following... Code: [Select] foreach($vardump['messages'] as $message) { // So we have a reference point for the first call we're going to dump if(!is_numeric($last_message_stamp)) { $last_message_stamp = $message['date']; } if( trim($vardump['calls'][$calls_counter]['datetime']) > trim($last_message_stamp) && trim($vardump['calls'][$calls_counter]['datetime']) < trim($message['date'])) { // Dump the calls row! echo(" <div class=\"chatbubble-call\"> <div class=\"chatbubble-person\">".$vardump['contact'][0]['name']."</div> <p>".$vardump['calls'][$calls_counter]['number']."</p> <p>".date("h:i:s", $vardump['calls'][$calls_counter]['number'])."</p> <div class=\"chatbubble-datetime\">".date("l, j F, Y -- h:i:s", $vardump['calls'][$calls_counter]['datetime'] / 1000)."</div> </div> "); // Increase our calls index $calls_counter++; } // Begin dumping Texts out :D // Let's see which style type we're dumping out... if($message['type'] == 2) { // Message Sent echo(" <div class=\"chatbubble-sent\"> <div class=\"chatbubble-person\">Pat Litke</div> <p>".$message['message']."</p> <div class=\"chatbubble-datetime\">".date("l, j F, Y -- h:i:s", $message['date'] / 1000)."</div> </div> "); } else { // Message Recieved echo(" <div class=\"chatbubble-recieved\"> <div class=\"chatbubble-person\">".$vardump['contact'][0]['name']."</div> <p>".$message['message']."</p> <div class=\"chatbubble-datetime\">".date("l, j F, Y -- h:i:s", $message['date'] / 1000)."</div> </div> "); } // Reset our $last_messge_stamp variable $last_message_stamp = $message['date']; } I should also add that I am using the following queries to pull this date out of my database... Code: [Select] $sql_get_messages = "SELECT * FROM messages WHERE thread_number LIKE '%$the_thread%' ORDER BY epoch_date ASC"; $sql_get_calls = "SELECT * FROM calls WHERE number LIKE '%$the_thread%' ORDER BY datetime ASC"; $sql_get_contact = "SELECT * FROM contacts WHERE number LIKE '%$the_thread%' LIMIT 1"; But, I feel that this is horribly inefficient, and it doesn't work right... I only ever get a single call dumped. What am I doing wrong? I am validating a form, and if there are errors in the input, the error array is filled with appropriate mssg and the "sticky" form with right values is shown back, and errors on top. Example: first name, last name, email, date of birth. each field is validated,and if for example first name does not pass,i will nullify the value and populate error array like below: $_SESSSION['error']['fname']="Please check the format of the name,can contain only alphabets!" $_SESSSION['error']['email']="Please check the format of email!" When I slap back the form, last name has passed, and so will have the previously entered value, but first name and email will be empty, and i need to know how to display the 2 errors on top of the form. It uses post method, and posts to itself. The code below is showing "undefined" and "OBJECT" errors
What am I doing wrong to build this multi-dimensional array?
And why can't I paste it to this page???????????????????????
I'm using a PHP framework someone built that allows for easier use of the Autotask ticketing/CRM system API. I have been able to navigate querying the database, but cannot seem to read through the data it returns. A var_dump of the results shows the following: object(ATWS\AutotaskObjects\QueryResponse)[9] public 'queryResult' => object(ATWS\AutotaskObjects\ATWSResponse)[10] public 'EntityResults' => object(ATWS\AutotaskObjects\ArrayOfEntity)[11] public 'Entity' => array (size=500) ... public 'EntityResultType' => string 'contact' (length=7) public 'EntityReturnInfoResults' => object(ATWS\AutotaskObjects\ArrayOfEntityReturnInfo)[1028] public 'EntityReturnInfo' => array (size=500) ... public 'Fields' => null public 'UserDefinedFields' => null public 'Errors' => object(ATWS\AutotaskObjects\ArrayOfATWSError)[1027] public 'ATWSError' => null public 'Fields' => null public 'UserDefinedFields' => null public 'ReturnCode' => int 1 Can someone please give me guidance on how I can get to the data in this result. I'm trying to get my hands on the "EntityReturnInfo" data. A sample is as follows
Here is what a print_r returns ATWS\AutotaskObjects\QueryResponse Object ( [queryResult] => ATWS\AutotaskObjects\ATWSResponse Object ( [EntityResults] => ATWS\AutotaskObjects\ArrayOfEntity Object ( **THIS IS WHERE THE GOOD DATA STARTS*** [Entity] => Array ( [0] => ATWS\AutotaskObjects\Contact Object ( [AccountID] => 174 [Active] => 1 [FirstName] => John [LastName] => Doe [AccountPhysicalLocationID] => [AdditionalAddressInformation] => [AddressLine] => 123 Fake Street [AddressLine1] => Suite 2 [AlternatePhone] => [BulkEmailOptOut] => [BulkEmailOptOutTime] => [City] => Fake City [Country] => United States [CountryID] => 237 [CreateDate] => 2016-09-28T10:17:57.34 [EMailAddress] => Fake@email.com [EMailAddress2] => [EMailAddress3] => [Extension] => [ExternalID] => [FacebookUrl] => [FaxNumber] => [LastActivityDate] => 2016-09-28T11:17:24 [LastModifiedDate] => 2016-09-28T11:17:24.68 [LinkedInUrl] => [MiddleInitial] => [MobilePhone] => [NamePrefix] => [NameSuffix] => [Note] => [Notification] => 1 [Phone] => 123-456-7890 [PrimaryContact] => [RoomNumber] => [SolicitationOptOut] => [SolicitationOptOutTime] => [State] => NY [SurveyOptOut] => [Title] => [TwitterUrl] => [ZipCode] => 12345 [Fields] => [UserDefinedFields] => ATWS\AutotaskObjects\ArrayOfUserDefinedField Object ( [UserDefinedField] => ) [id] => 30682885 ) ***AND THE DATA CONTINUES WITH*** [1] => ATWS\AutotaskObjects\Contact Object ( [AccountID] => etc etc etc etc
I have a pipe delimited file with this sample content: INV8004199|01/26/2012|Next door|648.00 SPT803487|01/25/2012|This and That|3360.00 INV8004193|01/25/2012|Where is it|756.00 INV8004133|01/05/2012|snowy winter|6750.00 I open the file to read it: Code: [Select] $CPfile = "sample.DEL"; $ft = fopen( $CPfile, "r"); $content1 = fread($ft, filesize($CPfile)); fclose($ft); Then I loop thru it: Code: [Select] $out = explode("\n", $content1); $total = 0; foreach($out as $var) { $tmp = explode("|", $var); for($i=0;$i<count($tmp);$i++){ echo $tmp[$i] . "<BR>"; } } What I would like to get is the total of all prices (last column) in all lines of the file. Can someone help please?. Thanks! |