PHP - Problem Reading An Array
Hi
What I need to do is retrieve information from a web form, that contains a file id, and which options from check boxes have been ticked. The code in the web form is. Code: [Select] <td width=\"206\"><p>$filename1<br><img src=\"$filename1\" alt=\"$filename1\" /></p> <p> <label> <input type=\"checkbox\" name=\"image_id[$unique_id1][save]\" value=\"save\" id=\"CheckboxGroup1_1\" /> Save</label> <br /> <label> <input type=\"checkbox\" name=\"image_id[$unique_id1][delete]\" value=\"delete\" id=\"CheckboxGroup1_2\" /> Delete</label> <br><label> <input type=\"checkbox\" name=\"image_id[$unique_id1][rotate]\" value=\"rotate\" id=\"CheckboxGroup1_3\" /> Image needs rotating</label> <br /> </p></td> This returns the following when I do a Code: [Select] var_dump of $_POST['image_id'][/code] when all three boxes are ticked. Code: [Select] array(1) { [4600]=> array(3) { ["save"]=> string(4) "save" ["delete"]=> string(6) "delete" ["rotate"]=> string(6) "rotate" } } the format is as follows 4600 is the file ID, the 3 others are save, delete, and rotate It appears to work ok, but I can't get at the data easily I can get the key using key(), but I can't get the other bits of data out using a foreach loop. Code: [Select] if(isset($_POST['image_id'])) { $file_info = $_POST['image_id']; if (isset($file_info)) { var_dump($_POST['image_id']); while($element = current(file_info)) { echo "<br> Loop = " . key($file_info)."\n"; $index_key = key($file_info); foreach ($dog1 as $index_key => $value) { Echo "<br> foreach value = $value"; } next($file_info); } } } I'm wondering if the array that is being sent back is ok as I tried to creat an array that sent back the same and couldn't, so maybe my code in the form needs changing. Similar TutorialsHi there I am working on PHP form which has an array named: $productOptions. When I do: print_r($productOptions); it returns: Array ( [124] => Array ( [optionId] => 124 [optionName] => acer aspire [optionListId] => 28 [dateCreated] => 2010-11-04 12:48:53 [enabled] => 1 [optionQtyId] => 84 [productId] => 40 [quantity] =>7 ) [114] => Array ( [optionId] => 114 [optionName] => acer fast [optionListId] => 28 [dateCreated] => 2010-11-01 02:04:53 [enabled] => 1 [optionQtyId] => 83 [productId] => 40 [quantity] => 0 ) Now from this Array, I would like to check if the quantity if greater than Zero. so I tried: if (productOptions[quantity] > 0){ echo "blah blah..." } But for getting the quantity, the part: productOptions[quantity] returns nothing. Am I doing this correctly? Please reply. Thank you I've never been very good with arrays, and am totally new to them in PHP... If I have this array... Code: [Select] $concertDates = array('201105071'=>'May 7, 2011 (9:00am - 12:00pm)', '201105072'=>'May 7, 2011 (1:00pm - 4:00pm)', '201105141'=>'May 14, 2011 (9:00am - 12:00pm)'); ...and I know the key, e.g. Code: [Select] $concertDate = '201105072' Then how do I get the corresponding value, i.e. Code: [Select] May 7, 2011 (1:00pm - 4:00pm)' ...from the array?? Debbie Hello Everybody,
i have shopping-cart with session_product.
i add arrays per button to the session.
i want get the shipping1 and shipping2 fields from the array where the field qty great is or equal to 2 >= 2.
i did this manualy in my example to get shi1 and shi2 lines 15 and 16.
how can i get shipping1 and shipping2 automaticly?
thank you very much for your help.
here is my code
01.<?php 02.$maxshipping1=0; 03.foreach ($_SESSION['products'] as $pro1) { 04.$maxshipping1 = max($maxshipping1, $pro1['shipping1']); } 05.?> 06.<?php 07.$maxshipping2=0; 08.foreach ($_SESSION['products'] as $pro2) { 09.$maxshipping2 = max($maxshipping2, $pro2['shipping2']); } 10.?> 11.<?php 12.$maxqty=0; 13.foreach ($_SESSION['products'] as $quant) { 14.$maxqty = max($maxqty, $quant['qty']); } 15.$shi1 = $_SESSION["products"][0]["shipping1"]; 16.$shi2 = $_SESSION["products"][0]["shipping2"]; 17.?>the Arrays looks like the following: Array ( [0] => Array ( [product] => Orangensaft 0,3l [code] => 5 [qty] => 3 [price] => 2.99 [shipping1] => 5 [shipping2] => 7 ) [1] => Array ( [product] => Kuchen [code] => 3 [qty] => 1 [price] => 2.95 [shipping1] => 4 [shipping2] => 6 ) [2] => Array ( [product] => Burger 200g [code] => 4 [qty] => 1 [price] => 3.95 [shipping1] => 1 [shipping2] => 3 ) [3] => Array ( [product] => Pizza Pollo [code] => 2 [qty] => 1 [price] => 5.95 [shipping1] => 2 [shipping2] => 4 ) [4] => Array ( [product] => Sake Maki Lachs, 6 St�cke Pommes [code] => 4236134485469 [qty] => 1 [price] => 2 [shipping1] => 1 [shipping2] => 2 ) ) 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 am trying to print out rows of images and pieces them to form a bigger map but having a little trouble printing out correctly. I am doing the following... A numbered text file with rows of numbers like these: 33.txt Code: [Select] 48,48,49,49,48,47,48,49,48,50,50,48,50,49,48,49,49,49 49,11,4,8,50,11,4,4,8,48,11,4,4,8,48,11,8,50 ... The number represent different area and the number in the text file represent each individual pieces of that particular area. the number of rows and columns are arbitrary. Example: Here is my code at the moment but there is something wrong in it as I can't seems to correctly print everything out... Code: [Select] <?php $file = file_get_contents("33.txt"); // can be any numbered text files $entries = explode("\n", $file); echo "Entries <br /><hr />"; for($i=0;$i < sizeof($entries);$i++){ for($j=0;$j < sizeof($entries);$j++){ $data = explode(",", $entries[$j]); echo "<td align=\"center\" background=\"test/33_"; echo $data[$j]; echo ".gif\" width=\"65\" height=\"65\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"65\" height=\"65\"> <tbody><tr> <td> <center></center> </td> </tr></tbody> </table> </td>"; } } ?> I am creating a poll with a form using check boxes. The resulting associative array is evaluated and 1 is to be added to values selected. I have that part down. I want to write the associative array to a file and the next time someone uses the form the values are read from the file, values added and then write it back to a file. I thought it would be better to do it like this rather than query a db, add values, etc. Any ideas on how to do this? This is the array I want to start with: Code: [Select] $vetservice = array( "Korea"=>0, "Vietnam"=>0, "Grenada"=>0, "Cold War"=>0, "Panama"=>0, "Desert Storm"=>0, "Mogadishu"=>0, "OEF"=>0, "OIF"=>0 ); Values from the post array would be added to the starting value and wrote back to a text file. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=346993.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=325339.0 I have 4 websites http://www.mercurymagazines.com/pr1/101/101395 http://www.mercurymagazines.com/pr1/169/16000 http://www.mercurymagazines.com/pr1/101/101396 http://www.mercurymagazines.com/pr1/169/16001 I am trying to write a program that will open each webpage one at a time, look for a unique word such as 'FREE' and if it is found the write the URL to a file, if not then no output and the next webpage is opened. I know this word exists only on one of the pages above (http://www.mercurymagazines.com/pr1/101/101396). When http://www.mercurymagazines.com/pr1/101/101396 appears last in the list located in source.txt the programs WORKS. When http://www.mercurymagazines.com/pr1/101/101396 appears in any other position such as first, or second, the program does NOT work. My head is sore from banging against my desk. Any assistance would be appreciated. <?php $file_source = fopen("source.txt", "r"); $file_target = fopen("targets.txt", "w"); while (!feof($file_source) ) { $url = fgets($file_source); echo '<br>'.$url; $raw_text = file_get_contents($url); mb_regex_encoding( "utf-8" ); $words = mb_split( ' +', $raw_text ); foreach ($words as $uniques) { echo $uniques; if ($uniques == 'FREE') { fwrite($file_target, $url); } } } ?> OK, so I am trying to read exif data from images and have come up against a snag that I cannot see the answer to. I know that what I have at present is pretty basic, but I want to be sure that I know how to access the bits I want before tidying it up into something more sophisticated. The coide I have is this:- Code: [Select] $exif = exif_read_data('brass jaw.jpg', 'EXIF'); $name = $exif['FileName']; $height = $exif['ExifImageWidth']; $width = $exif['ExifImageLength']; $model = $exif['Model']; $exposuretime = $exif['ExposureTime']; $fnumber = $exif['FNumber']; $iso = $exif['ISOSpeedRatings']; $date = $exif['DateTime']; echo "File Name: $name<br />"; echo "Height: $height<br />"; echo "Width: $width<br />"; echo "Camera: $model<br />"; echo "Shutter Speed: $exposuretime<br />"; echo "F number: $fnumber<br />"; echo "ISO: $iso<br />"; echo "Date & Time: $date<br />"; var_dump($exif); This code produces the following:- File Name: brass jaw.jpg Height: 640 Width: 360 Camera: Canon EOS 550D Shutter Speed: 244/1000000 F number: 8000000/1000000 ISO: Array Date & Time: 2011:09:17 13:52:30 Which serves quite well apart from the ISO, which comes back as "Array". Now when I do a var_dump I see that ISOSpeedRatings returns as this:- 'ISOSpeedRatings' => array 0 => int 800 1 => int 800 What I can't work out is how to access the information from this - I know that the solution will probably be very simple, and that I will end up kicking myself, but I could use a little help. <league name="italy" id="1"> <match name="AC Milan v Palermo" time="15/02/2011 20:45"> <bettype name="Versus (with Draw)"> <bet outcome_name="AC Milan" odd="1.87"> <bet outcome_name="X" odd="3.40"> <bet outcome_name="Palermo" odd="4.00"> </bettype> </match> <match name="Juventus v Torino" time="15/02/2011 20:45"> <bettype name="Versus (with Draw)"> <bet outcome_name="Juventus" odd="2.00"> <bet outcome_name="X" odd="3.00"> <bet outcome_name="Torino" odd="2.00"> </bettype> <bettype name="Half Time"> <bet outcome_name="1" odd="2.40"> <bet outcome_name="X" odd="3.40"> <bet outcome_name="2" odd="1.40"> </bettype> </match> </league> <league name="Spain" id="2"> <match name="Barcelona v Real Madrid" time="15/03/2011 21:45"> <bettype name="Versus (with Draw)"> <bet outcome_name="Barcelona" odd="1.87"> <bet outcome_name="X" odd="3.40"> <bet outcome_name="Real Madrid" odd="4.00"> </bettype> </match> </league> im trying to parse attributes of above xml with using xpath functions. what i want to output is this: ( <bettype name="Half Time"> this will be ignored ) Italy AC Milan v Palermo 1.87 3.40 4.00 Juventus v Torino 2.00 3.00 2.00 spain Barcelona v Real Madrid 1.87 3.40 4.00 im trying do this with below xpath codes $xml=simplexml_load_file('http://xml.gamebookers.com/sports/football.xml_attr.xml'); $league=$xml->xpath("//league"); $matches=$xml->xpath('//bettype[@name="Versus (with Draw)"]/..'); $odds=$xml->xpath('//match/bettype[@name="Versus (with Draw)"]/bet'); i searched and tried lots of tutorials. i need help in writing the correct code thanks I am extracting an array from the database in sorted form with respect to it's parent_id. Now I have to make a sub tree of this array in such a way that related nodes would be inserted in 'pages' field. cleths->upper->shirts Hello All - I have the following array: Code: [Select] array 0 => array 'farmName' => string 'Hallinan' (length=8) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) 1 => array 'farmName' => string 'Holt' (length=4) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) 2 => array 'farmName' => string 'Holt' (length=4) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) 3 => array 'farmName' => string 'Holt' (length=4) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) 4 => array 'farmName' => string 'Holt' (length=4) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) 5 => array 'farmName' => string 'Holt' (length=4) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) 6 => array 'farmName' => string 'Home' (length=4) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) 7 => array 'farmName' => string 'Home' (length=4) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) 8 array 'farmName' => string 'Home' (length=4) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) The data comes from a flat file that has (as you can see) many of the same names like Home and Holt. Is there a way to extract the first Holt and Home from the array and put those values in a new array? So my new array would look something like: Code: [Select] array 0 => array 'farmName' => string 'Hallinan' (length=8) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) 1 => array 'farmName' => string 'Holt' (length=4) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) 2 => array 'farmName' => string 'Home' (length=4) 'farmInsNum' => string '' (length=0) 'farmFSA' => string '' (length=0) I look through php.net and really couldn't find a function that could handle what I was after. I'm sure I'd have to use a combination of each() and reset() or maybe not? Any help would be very welcome. Thanks! Hello mates, i've been googling about my problem but i couldn't fix it. Code: ###################################### $web = file_get_contents($tmpUrl); $explodedWeb = explode("<b>Somecode:</b> ",$web); print $explodedWeb [1]; ###################################### I'm just printing it for testing purposes, and the $web var works fine(since tried printing the hole source). Error: "Notice: Undefined offset: 1 in ..." I tried to create an empty array in explodedWeb ("$explodedWeb[]") but didn't work either. Greets. My array results keep displaying like this. I want it to just display the numbers in the quotations. any help? Code: [Select] array ( 0 => '4396', ) array ( 0 => '3934', ) array ( 0 => '5063', ) array ( 0 => '4394', ) array ( 0 => '3936', ) array ( 0 => '4393', ) array ( 0 => '4395', ) array ( 0 => '5064', ) array ( 0 => '5062', ) array ( 0 => '4224', ) array ( 0 => '3322', ) array ( 0 => '3321', ) array ( 0 => '3320', ) array ( 0 => '3725', ) Hey guys i have a table of pages set up with the possability of inserting pages inside pages. I am trying to make a delete button that would delete every child pages creating an array of page id's. page 1 L page 1.1 L page 1.2 L page 1.3 L page 1.4 page 2 my code looks like this so fare class delete_page { function page($cat_id, $x = ''){ $sql = mysql_query("SELECT * FROM pages WHERE parent='$cat_id' order by id asc"); while ($select = mysql_fetch_assoc($sql)) { $this->x[] = $select['id']; $this->x = $this->page($select['id'], $this->x); } return $this->x; } function get_page($cat_id){ return $this->page($cat_tid); } } $page = new delete_page; $get_array_page = $page->get_page(1); For some reason the above code sends me an array of all the pages in the database instead of returning only the child pages of the ID i inserted in the $get_array_page = $page->get_page(1) Code: [Select] Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) It should normaly return only page 1 L page 1.1 L page 1.2 L page 1.3 L page 1.4 with out page 2 like this Code: [Select] Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) What did i miss? Hello all, I think I have a simple question. I have several arrays that I need the output from but I need the output from each array to be together. I know WHAT?! I'll try to explain: I have a dynamic jQuery form that fills in a table with data. Each "field" or <td> has separate information in each. The way I output the data is in an input box so that I can capture the value of each. The name attribute is the array for each input. So for example the output for each would look like this: Code: [Select] <tr> <td> <input type="text" name="fullName[]" value="input_from_user"/> </td> <td> <input type="text" name="Address[]" value="input_from_user"/> </td> </tr> If you can visualizes this we could have several rows of data from each array (fullName[] and Address[]). How would I extract the data in such a way that I can clump them into their appropriate rows? I know how to extract them one by one using foreach loop on each array but that won't do what I want. I would like the output to be like this: John Doe - 22 S Main Street Jim Smith - 111 N Main Street and so on... This is what I have so far but I'm sure this isn't how to accomplish what I'm after. $name = $_POST['fullName']; $address = $_POST['Address']; $outputArry = array( "FullName" => $name, "Address" => $address ); foreach ( $outputArry as $output ) { foreach ( $output as $row ) { $rowFullName = $row['FullName']; $rowAddress = $row['Address']; $rowOutput .= 'Name: ' . $rowFullName . ' Address: ' . $rowAddress . '<br />'; } } echo $rowOutput; Thanks for any help on this issue. Damian I'm sure there must be a way to do whatI am after, as it seems like such an obvious thing to do, but I can't figure it out. 1. I have an array which contains a list of database's and their connections $slaveRes_array[0] = array('server' => 'localhost:3306', 'user' => $u, 'password' => $p, 'database' => 'MySQL01_5083', 'sendmail' => '0', 'repeat' => '0', 'dbID' => '1' ); and so on 10 times I then have a list of MySQL Queries: (at the moment there is only one, but there will be more later on). $query_array[] = array( 'query1' => "SHOW SLAVE STATUS"); The idea is that I take the first database from $slaveRes_array, connect to it, and run each query from the $query_array in turn against that database, and ultimately pass that resultset into an array that I can refer back to later on. Within $slaveRes_array I have a DB name (e.g. MySQL01_5083), I want this to be the first entry in my resultset array, so I can reference this. However, not all database's will return a result. So what I want to end up with is something like: => Array ( [name] => MySQL02_5083 ) ( [Slave_IO_State] => Waiting for master to send event)... (in this case the first server (MySQL01) didn't return a result, so the first item in the array is MySQL02. I have found lots of ways to achieve bits of this, but none that work together. I can get a list of database names that returned a result, but can't get the data to return to the array (or any array). I can get the data into an array, but not the database names. Surely this must be something straight forward that people do all the time, right? I want to store all the hours 0,1,2,3... in my $time array but it returns the last value only and I dont understand why... Code: [Select] <?php $time = array(); $hour = 0; for ( $i=0; $i<=7; $i++ ) { $time['hour'] = $hour; $hour++; } ?> |