PHP - Multi-field Array
Hi people
I need a way to loop through an array where $imgid is some random number assigned to each array element and there are 4 fields id, url, tnurl, caption per array element. I need to extract these 4 fields in the same loop iteration. Thanks Code: [Select] $_SESSION['imagegallery'][$imgid]['id']; $_SESSION['imagegallery'][$imgid]['url']; $_SESSION['imagegallery'][$imgid]['tnurl']; $_SESSION['imagegallery'][$imgid]['caption']; example: Code: [Select] $_SESSION['imagegallery'][347]['id']; $_SESSION['imagegallery'][347]['url']; $_SESSION['imagegallery'][347]['tnurl']; $_SESSION['imagegallery'][347]['caption']; $_SESSION['imagegallery'][892]['id']; $_SESSION['imagegallery'][892]['url']; $_SESSION['imagegallery'][892]['tnurl']; $_SESSION['imagegallery'][892]['caption']; Similar Tutorialshi all i have a problem here, Iv got a form that uploads images to a folder and updates the db with the name of that image, that work ok but if one of the upload field are left blank then the script updates the db with empty values how can i get it to only update the db with only submitted form field data???? here is the form Code: [Select] <?php if (isset($_GET['id'])) { $id = $_GET['id']; } ?> <form action="ud_image.php?id=<? echo "$id"?>" method="post" enctype="multipart/form-data" name="form1" id="form1"> <table class="udp"> <tr> <th>Thumbnail:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 1:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 2:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 3:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 4:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </form> and here is the processing page <?php include("protect/password_protect.php"); error_reporting(E_ALL); include ("../includes/db_config.php"); $con = mysql_connect($db_hostname,$db_username,$db_password); @mysql_select_db($db_database) or die( "Unable to select database"); $path1= "../thumbnails/".$_FILES['ufile']['name'][0]; $path2= "../images/".$_FILES['ufile']['name'][1]; $path3= "../images/".$_FILES['ufile']['name'][2]; $path4= "../images/".$_FILES['ufile']['name'][3]; $path5= "../images/".$_FILES['ufile']['name'][4]; //copy file to where you want to store file copy($_FILES['ufile']['tmp_name'][0], $path1); copy($_FILES['ufile']['tmp_name'][1], $path2); copy($_FILES['ufile']['tmp_name'][2], $path3); copy($_FILES['ufile']['tmp_name'][3], $path4); copy($_FILES['ufile']['tmp_name'][4], $path5); ?> <html> <head> <title>Update Project Images</title> <link rel="stylesheet" type="text/css" href="../../project/backend/style.css" /> </head> <body> <table class="udip"> <tr> <th><? echo "<img src=\"$path1\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path2\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path3\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path4\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path5\" width=\"150\" height=\"150\">";?></th> </tr> <tr> <td><? echo "File Name :".$_FILES['ufile']['name'][0]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][1]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][2]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][3]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][4]."<BR/>";?></td> </tr> <tr> <td><?echo "File Size :".$_FILES['ufile']['size'][0]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][1]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][2]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][3]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][4]."<BR/>";?></td> </tr> <tr> <td><? echo "File Type :".$_FILES['ufile']['type'][0]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][1]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][2]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][3]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][4]."<BR/>";?></td> </tr> </table> </body> </html> <? $filesize1=$_FILES['ufile']['size'][0]; $filesize2=$_FILES['ufile']['size'][1]; $filesize3=$_FILES['ufile']['size'][2]; $filesize4=$_FILES['ufile']['size'][3]; $filesize5=$_FILES['ufile']['size'][4]; if($filesize1 && $filesize2 && $filesize3 && $filesize4 && $filesize5 != 0) { echo "We have recieved your files<p>"; } else { echo "Error in you images check and try again Database has been updated to blank images so no images will be shown on details page."; } $query = "UPDATE $db_table SET thumbnail = '".$_FILES['ufile']['name'][0]."', image1 = '".$_FILES['ufile']['name'][1]."', image2 = '".$_FILES['ufile']['name'][2]."', image3 = '".$_FILES['ufile']['name'][3]."', image4 = '".$_FILES['ufile']['name'][4]."' WHERE id = '".$_GET['id']."'"; if (!mysql_query($query,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> I have a for loop which extracts info from a MySQL table, chooses something then needs to push each bit into an array: for($i = 0 ; $i < $query_report_rows ; ++$i) { $row= mysql_fetch_row($query_names); if($row[6] == 0) { $sName = $row[1]; } elseif($row[6] == 1) { $sName = $row[2]; } $name = "$row[0], $sName"; $print = nl2br($row[7]); } What i need is a multidimensional array to hold $name and $print: $name_print = array( array('name'=>$name 'print'=>$print ) ) How do i array push into such an array from the above for loop? (multi-dimensional array are a very weak point at the moment, so any pointers here would be very much appreciated) Code: [Select] $new_array2=array_diff($my_array,$itemIds); $updatedb = mysql_query("UPDATE content_type_ads SET field_expire_value = '666' WHERE $new_array2 = field_item_id_value"); "$new_array2" has only 12 digit numbers for each item in the array, and I want to match them to the "field_item_id_value" field in the table, updating the "field_expire_value" field for the record where they match. I know I am close because the UPDATE code works before I add the WHERE statement (it of course adds '666' to EVERY field, but for a noobie it's a start!). 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. i want to edit a product and allocate industries to a product refer following link to view http://meriwebsite.net/envytech/admin/industryallocate.php?pageNum=1SELECT%20a.products_id,%20a.products_image,%20b.language_id,%20b.products_description,%20b.products_name%20%20%20FROM%20products%20a%20,%20products_description%20b%20WHERE%20a.products_id%20=%20b.products_id%20and%20language_id=1%20and%201%20order%20by%20%20b.products_id,%20%20b.products_description I can update prouct name and serial number but cannot get values for industries the do while loop for industry display is given below (displaying industry id before check box here) $iquery="SELECT * from industry "; mysql_select_db($database_DBconnect, $DBconnect); $iResult = mysql_query($iquery, $DBconnect) or die(mysql_error()); $irows = mysql_fetch_assoc($iResult); $itotalrows=mysql_num_rows($iResult); $j=-1; do { $j++; ?> <br /><?php echo "id=". $irows['id'];?><input name="ind[$i][$j]" type="checkbox" class="vardana12" id="ind[$i][$j]" value="<?php echo $irows['id'];?>" /> <?php echo $irows['name'];?> <?php } while ( $irows = mysql_fetch_assoc($iResult) ); ?> I am trying to display values using following code if ( (isset($_POST['sub'] )) or (isset($srno['sub'] ))) { echo "<br> count=".count($_POST['srno']); for($i=0; $i< count($_POST['srno']); $i++){ echo "on 'save' clicked <br>"; echo "<br> products ".$_POST['products_id'][$i]; echo "<br>srno ". $_POST['srno'][$i]; echo "<br>industry ".print_r($_POST['ind'][$i]); echo "<br>product name ". $_POST['products_name'][$i]; Updateindustry($_POST['products_id'][$i], $_POST['srno'][$i],$_POST['industry'][$i],$_POST['products_name'][$i]); } $update=1; $alert= "udation done"; } I am not getting correct values for $_POST['industry'][$i] please help Whats the most efficient way of searching within a multi dimensional array? My Array = Array ( => Array ( => Item 1 [title] => Item 1 [1] => 2012-03-21 [eventDate] => 2012-03-21 [2] => 21 [eventDay] => 21 ) [1] => Array ( => Item 2 [title] => Item 2 [1] => 2012-03-21 [eventDate] => 2012-03-21 [2] => 21 [eventDay] => 21 ) ) String to find = '21' If (MY ARRAY contains STRING TO FIND) {} Clearly in this case there are several '21' (s) so if I only wanted to search the [eventDay] keys...would there be a fast effective and efficient manner? Thoughts and help gratefully received. Will 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? How do I do this? It only does the first nine records and wont cycle through the many records in the second dimension. Thanks. // External Loop is 1 - 9 // Internal Loop is 0 - whatever it is //$muarray_s[0] = $facility_id; //$muarray_d[$external_loop][$interal_loop] = $objfields['139339_date']; //$muarray_t[$external_loop][$interal_loop] = $objfields['139339_time']; //$muarray_i[$external_loop][$interal_loop] = $objfields['139339_main_id']; //$array_of_mu[$external_loop][$interal_loop] = $checklist_item_disc; echo "Begin Draw Runway Image Function <br>"; echo "Establish Array Looping Procedure"; for ($j=0; $j<10; $j=$j+1) { // External Loop // This is actually the Condition not the mu for ($k=0; $k<count($array_of_mu); $k=$k+1) { // Internal Loop // This is the Mu Value; echo "Mu Value is ".$array_of_mu[$j][$k]."<br>"; } } Code: [Select] $i=1; $selected=0; $uservalue=20; $numCols = 3; $numPerCol = ceil(20 / $numCols); echo "<table class=tuble><tr>"; for($col = 1; $col <= $numCols; $col++) { echo "<td>"; for($row = 0; $row < $numPerCol; $row++) { $resultRow = 20; if ($i<=$uservalue) { if ($i == $selected) { $checked = 'checked'; }else{ $checked = ''; } $styles = array( 'Blue Essense' => array('#2B8EFF', '#63CBFF', '50 Forum Gold'), 'veggie' => array('carrot', 'collard', 'pea') ); echo '<input type="radio" value="'.$i.'" name="form[color]">Blue Essence <b><a style="color:#2B8EFF;text-shadow:#63CBFF 2px 1px 1px" href="u.php?id='.$pun_user['id'].'">'.$pun_user['username'].'</a></b><br>'; } else { echo '<label for="s'.$i.'"><input type="radio" value="'.$i.'" name="form[star]" disabled><b><a href="u.php?id='.$pun_user['id'].'">'.$pun_user['username'].'</a></b><br>'; } $i++; } echo "</td>"; } echo "</tr></table>"; Okay, see the $styles array? Code: [Select] $styles = array( 'Blue Essense' => array('#2B8EFF', '#63CBFF', '50 Forum Gold'), 'veggie' => array('carrot', 'collard', 'pea') ); The first is hex code, background, and 2nd is #63CBFF (Front color) and the 3rd is how much it costs I need those arrays to echo out correspondent with my Code: [Select] echo '<input type="radio" value="'.$i.'" name="form[color]">Blue Essense<b><a style="color:#2B8EFF;text-shadow:#63CBFF 2px 1px 1px" href="u.php?id='.$pun_user['id'].'">'.$pun_user['username'].'</a></b> (50 Forum Gold)<br>'; See how the style="color etc/etc" I need to grab the data from $styles to go into the correct spots, Is this feasable? Long story short, I need to explode those arrays out somehow, any idea? What am I missing here? The array: protected $form_bonus = array( "Attacker" => array( "Ashwin" => array( "normal" => 1.15, "rps" => 1.38), "Cordelon" => array( "normal" => 1.15, "rps" => 1.38), "Mersan" => array( "normal" => 1.15, "rps" => 1.38), "Phlanixian" => array( "normal" => 1.195, "rps" => 1.494), "Slythe" => array( "normal" => 1.15, "rps" => 1.38) ), "Defender" => array( "Ashwin" => array( "normal" => 1.15, "rps" => 1.38), "Cordelon" => array( "normal" => 1.15, "rps" => 1.38), "Mersan" => array( "normal" => 1.15, "rps" => 1.38), "Phlanixian" => array( "normal" => 1.15, "rps" => 1.38), "Slythe" => array( "normal" => 1.15, "rps" => 1.38) ) ); accessing it: $bonus *= form_bonus[$this->role][$this->race]['rps']; error: PHP Parse error: syntax error, unexpected '[' Hi can anybody help me out with the following problem I am having? I need to populate the key values in the multi-dimentional array structure shown below and the values will be used later in the following way: <tr> <td><?php echo $sm_array[1]['col_1']; ?></td> <td><?php echo $sm_array[1]['col_2']; ?></td> <td><?php echo $sm_array[1]['col_3']; ?></td> <td><?php echo $sm_array[1]['col_4']; ?></td> //and so on, up to 10 </tr> <tr> <td><?php echo $sm_array[2]['col_1']; ?></td> <td><?php echo $sm_array[2]['col_2']; ?></td> <td><?php echo $sm_array[2]['col_3']; ?></td> <td><?php echo $sm_array[2]['col_4']; ?></td> //and so on, up to 10 </tr> This is the array structure, $td->innertext is just a different value each time and is not important for this example, it could essentially be anything: sm_array[$row] = array( "col_1" => $td->innertext, "col_2" => $td->innertext, "col_3" => $td->innertext, "col_4" => $td->innertext, "col_5" => $td->innertext, "col_6" => $td->innertext, "col_7" => $td->innertext, "col_8" => $td->innertext, "col_9" => $td->innertext, "col_10" => $td->innertext, ); But I need to add the values inside a loop, like this: while($row=0; $row<=10; $row++) { $sm_array[$row] = array( "col_".$row => $td->innertext); } But this doesn't allow me to change the key name inside the loop, so for $sm_array[1] there will be 10 keys and their values, and the same for $sm_array[2], it will also have 10 keys and different values for each key and so on! But for some reason the key value will not work this way inside a loop, it doesn't allow "col_".$row and I even tried to echo the key name, like this: while($row=0; $row<=10; $row++) { $sm_array[$row] = array( "<?php echo $row; ?>" => $td->innertext); } It only seems to accept a fixed string or integer as the key, like this: while($row=0; $row<=10; $row++) { $sm_array[$row] = array( "col_1" => $td->innertext); // or like this $sm_array[$row] = array( 1 => $td->innertext); } But then I have a problem, I can't change the key name dynamically! I have tried doing this with conditional staments like this, but it only accepts the first key name and the 2nd, 3rd etc, etc all fail: while($row=0; $row<=10; $row++) { if($row==1){ $sm_array[$row] = array( "col_1" => $td->innertext); }else if($row==2){ $sm_array[$row] = array( "col_2" => $td->innertext); } //and so on } Can somebody please tell me what I am doing wrong or can't this be done or is their some other way of doing this? Thanks in advance Grant I want to have a multi level dropdown selection tool come out of an array (not database; almost all of available codes on the internet are based on mysql databse). I have an array as each element has this format: "Country | City | ID". Using explode, I want to make a dropdown to choose the country, then choosing the cities of the chosen country. Finally, in a simple search box make action="result.php" to lead to result.php?q=$id Thanks for your kind attention 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] => ) ) 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. 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
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! 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 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) I have four different arrays and I want to place them into a multi dimensional array and then I want to place it into a Session variable. This is what I have below.How do I do this? when I print_r($_Session) I don't get anything just option[](2); Code: [Select] $_SESSION ['option']['green'] = array('name '=>'jeff'); $_SESSION ['option']['red'] = array('name '=>'mary'); $_SESSION ['option']['blue'] = array('name '=>'joe'); $_SESSION ['option']['brown'] = array('name '=>'ash'); HI - Pulling my hair out .. I'm trying to extract from a 3 dimensional array the data for insert to MySql. It is looping correctly however, and it is inserting, however for some reason I am not getting values for price and quantity, just 0. The array is contained within Code: [Select] $prod_details = ($_SESSION['cart']); if you do a print_r on the the session, you get : Code: [Select] Array ( [22] => Array ( [name] => Turkey Jumbo Pack [price] => 155.25 [count] => 1 ) [20] => Array ( [name] => Chicken Variety Pack [price] => 120.35 [count] => 1 ) ) I am using a nested foreach loop to traverse the array: Code: [Select] $prod_details = ($_SESSION['cart']); foreach ($prod_details as $keyOne=> $value){ $prodID = $keyOne; foreach($value as $keytwo=>$row) { $price = $keytwo['price']; $quantity = $keytwo['count']; } But I all I get out of $price and $quantity when I do an insert is 0. What am I doing wrong ? MANY MANY thanks for all your help ! ! |