Search the Community
Showing results for tags 'array'.
-
I have a html form in which the dropdown box is an array element now I have created a javascript function that get form as parameter . 1)I need to maniulate the values of the array present in the form in the below code sendmail is the form sname is the field array function addit(sendmail) { var x=document.sendmail.sname.length; //alert(x); while( x>0 ) { var skill=document.getElementById("sname[x]").value; //alert(skill); var anOption = document.createElement("OPTION"); anOption.innerText = skill; anOption.Value = skill; document.form.snames.options.add(anOption); x--; } }
-
- javascript
- html
-
(and 3 more)
Tagged with:
-
The Joomla ZOO extension places information within a multi-dimensional array named $elements. I display the array structure with: $arr = json_decode($elements,true);echo <pre>",print_r($arr,true),"</pre>"; The resulting array is below. Array ( [a3f9a1ba-85a2-4142-b0d6-6a85bef30cb5] => Array ( [0] => Array ( [value] => Telephone Number ) ) [e3145090-5017-44a9-bfaa-64602bacf96f] => Array ( [0] => Array ( [value] => Fax Number ) ) ) I need to be able to replace the value associated with a specific identifier ie. replace the ‘Telephone Number’ with another string $newdata, as this is associated with the identifier ‘a3f9a1ba-85a2-4142-b0d6-6a85bef30cb5’. I am new to this, but my initial attempt was as follows. $newdata = “ABCD”; foreach($elements as &$value) { $value['a3f9a1ba-85a2-4142-b0d6-6a85bef30cb5'] = $newdata; } This seems to have absolutely no effect. Can someone point me in the right direction. Thanks, Alec
-
can you one of the php master can help me out with this this is my array output Array ( [0] => WI BLACK CHERRY BASE [1] => 1 [2] => WI STRAWBERRY BASE [3] => 1 ) this is the buttom I am using to past the value <form id="form1" name="form1" method="post" action="/storescripts/mailcart.php"> <input type="hidden" name="message" id="message" value="<?php echo $mail_id_array; ?>" /> <input type="submit" name="button" id="button" value="Send Order" /> </form> this is the mailcart.php <?php $message = ''; $name = "wesrt"; $email = "abc@hotmail.com"; $message .= $_POST[message]; $formcontent=" From: $name \n Message: $message"; $recipient = "info@xsn.com"; $subject = "Order Form"; $mailheader = "From: $email \r\n"; //mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); mail($recipient, $subject, $message, $mailheader) or die("Error!"); print_r($message); //header( 'Location: http://www.xsn.com/index.php' ) ; //echo "Thank You!"; ?> I am getting this: WI BLACK CHERRY BASE .--->.1<br>WI STRAWBERRY BASE .--->.1<br> and I would like to have the following result: WI BLACK CHERRY BASE .--->.1 WI STRAWBERRY BASE .--->.1
-
I have assigned values for a multidimensional array as following (in opencart): $this->data['price_list'][0]['115']['296']= "8.99"; $this->data['price_list'][1]['115']['396']= "8.99"; $this->data['price_list'][2]['115']['446']= "8.99"; $this->data['price_list'][3]['115']['496']= "8.99"; $this->data['price_list'][4]['115']['596']= "12.99"; $this->data['price_list'][5]['115']['796']= ""; $this->data['price_list'][6]['115']['996']= ""; $this->data['price_list'][7]['115']['1196']= ""; $this->data['price_list'][8]['140']['296']= "12.99"; $this->data['price_list'][9]['140']['396']= "12.99"; $this->data['price_list'][10]['140']['446']= "12.99"; I have two variables: $height and $width. I want to check in the above array as following: let, $height= 140, $ width= 396. I want the value 12.99. How I'll check this?
-
HI, I am a newbie using Dreamweaver to create a form that has a checbox next to students's names. Once you select the student's you wish to see, you hit submit and it sends you to anther page where it displays the profiles for each of these students so they can be printed. My form looks like this: <form id="form1" name="form1" method="post" action="test4.php"> <?php do { ?> <p> <input name="UID[]" type="checkbox" id="UID" value="<?php echo $row_applicants['UID']; ?>" /> <label for="UID"></label> <?php echo $row_applicants['FNAME']; ?> <?php echo $row_applicants['LNAME']; ?> </p> <?php } while ($row_applicants = mysql_fetch_assoc($applicants)); ?> <p> <input type="submit" name="button" id="button" value="Submit" /> </p> </form> My test results page looks like this: mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $UID = $_POST['UID']; $query = "SELECT * FROM users WHERE UID = ('$UID')"; $results = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($results)==1){ // If there is only one row that was returned $results = mysql_fetch_array($results); echo $results['UID']; // If the column name is incorrect, just change it to match }elseif(mysql_num_rows($results)>1){ // If there is more than one row that was returned while($result=mysql_fetch_array($results)){ // Loop through each row that was returned and display it echo $result['UID']." "; } }else{ //If there were no rows returned, this is just to account for every option and is entirely optional echo "No matched!"; } I want the end result page to look like the attached file with multiple profiles. Thanks in advance
-
Hello the community, i have create a fonction wich check via a "class validate" if the email & password are well formated i didnt include the validate class & the code here is not full the main problem is i have this error $validEmail = new ValidateEmail( array( $_POST['email'], $_POST['email'] ) ); $validpass = new ValidatePassword( array( $_POST['password'], $_POST['password'] ) ); if ( $validEmail->isValid( ) && $validpass->isValid( ) ) i have tried with "" but it not work $validEmail = new ValidateEmail( array( $_POST["email"], $_POST["email"] ) ); $validpass = new ValidatePassword( array( $_POST["password"], $_POST["password"] ) ); if ( $validEmail->isValid( ) && $validpass->isValid( ) ) could you help me to correct the syntax please ? thx you very much
-
I've never taken a logic class, or a CS class. This is likely very easy to anyone with any background in either topic. I have an array, $_SESSION['thresholds'], where I've given the array keys values such as "thresholdA", "thresholdB", "thresholdC", "thresholdD", etc. with corresponding elements that increase in value (5,15,50,75,etc.). They array is currently mapped in ascending order. I have a variable, $_SESSION['compare'], that I want to compare against all the elements in the $_SESSION['thresholds'] and, ultimately, I want to be able to echo/print the key of the largest array element that is less than the value of $_SESSION['compare']. Using the above values, if $_SESSION['compare'] == 21, then I would love to echo/print "thresholdB". What's the best method to accomplish this? Array_Walk? A switch statement? I first tried while() and was trying to use the pointer in the array, but I found that if I used next() to see if the next array element was larger, the actual use of next() within the while() statement caused the pointer to advance anyways. That seemed like the wrong path to take. The switch statement I've tried is failing, and I don't know how to use a comparison within an array_walk when I want to break out once the largest value is determined. This seems like such a basic function of array and variables but I'm struggling with this. Any advice would be much appreciated. Here's some of my tests that failed: reset($_SESSION['thresholds']); while( (current($_SESSION['compare']) < $_SESSION['thresholds']) and (key($_SESSION['thresholds']) <> 'thresholdMAX')) next($_SESSION['compare']); That final next() statement advances me one step too far. Should I use this and then backup one step? That might create problems of its own. Next I tried switch: switch ($_SESSION['compare']) { case ($_SESSION['compare'] >= $_SESSION['thresholds']['thresholdMAX']): $output = key($_SESSION['thresholds']['thresholdMAX']); break; case ($_SESSION['compare'] >= $_SESSION['thresholds']['thresholdD']): $output = key($_SESSION['thresholds']['thresholdD']); break; But that wasn't working and seems like the wrong way to go about this. Can anyone point me in the right direction? Thanks so much in advance!
- 3 replies
-
- beginner
- best practices
-
(and 3 more)
Tagged with:
-
what sort of php array enumeration must I use to get from this: Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 42 [5] => 42 [6] => 42 [7] => 42 [8] => 36 [9] => 36 [10] => 0 [11] => 36 [12] => 36 [13] => 36 [14] => 36 [15] => 36 [16] => 42 [17] => 42 [18] => 42 [19] => 42 [20] => 42 [21] => 42 [22] => 42 [23] => 0 ) to this description of the array: index 0 to index 4 = 0 index 4 to index 8 = 42 index 8 to index 16 = 36 index 16 to index 23 = 42 index 23 = 0 my head is swirling with conditionals and loops ... getting dizzy ... can't crack it. thanks in advance for any assistance.
-
I'm having trouble adding text at the end of the latest array chunk, when he has less than 9 elements + counter. Below is my actual code. I use the $txtcontent as text input from a webform. function hexToStr($hex) { $string=''; for ($i=0; $i < strlen($hex)-1; $i+=2) { $string .= chr(hexdec($hex[$i].$hex[$i+1])); } return $string; }[/font][/color] $commas = hexToStr('22'); $format = $_POST['format']; $titre= strtoupper($_POST['titre']); $txtcontent = $_POST['texte']; $txtcontent = wordwrap($txtcontent,20,hexToStr('0D0A'),true); $txtcontent = explode("\n", $txtcontent); $input = array_chunk($txtcontent, 9, false); $i = 1; foreach($input as $key => $array){ $j = 1; $input[$key][0] = "\If S=".$i."\n"; foreach($array as $k => $v){ $input[$key][$k+1] = '\text '.($k*6+1).',1,'.$commas.str_replace(hexToStr('0D'), "", $v).$commas.hexToStr('0D0A'); $j++; } if ($j == 10) $input[$key][10] = "\IfEnd\n"; $i++; } function array_flatten($array) { if (!is_array($array)) { return FALSE; } $result = array(); foreach ($array as $key => $value) { if (is_array($value)) { $result = array_merge($result, array_flatten($value)); } else { $result[$key] = $value; } } return $result; } $array = array_flatten($input); $filecontent = implode($array); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment;filename='.$_POST['titre'].'.'.$format.''); header('Cache-Control: max-age=0'); //$fh = fopen($filename, 'wb'); $fh = fopen('php://output', 'wb'); fwrite($fh, $filecontent); fclose($fh); Exemple: if i sumbit this content as input in the webform: line1 line2 line3 line4 line5 line6 line7 line8 line9 line10 line11 line12 line13 line14 line15 line16 line17 line18 line19 line20 I will have a file with this content: \If S=1 \text 1,1,"line1" \text 7,1,"line2" \text 13,1,"line3" \text 19,1,"line4" \text 25,1,"line5" \text 31,1,"line6" \text 37,1,"line7" \text 43,1,"line8" \text 49,1,"line9" \IfEnd \If S=2 \text 1,1,"line10" \text 7,1,"line11" \text 13,1,"line12" \text 19,1,"line13" \text 25,1,"line14" \text 31,1,"line15" \text 37,1,"line16" \text 43,1,"line17" \text 49,1,"line18" \IfEnd \If S=3 \text 1,1,"line19" \text 7,1,"line20" But i also need that the latest array chunk contain the text "\ifEnd" at the end, even when he has less than 9 elements + counter (S= X). \If S=1 \text 1,1,"line1" \text 7,1,"line2" \text 13,1,"line3" \text 19,1,"line4" \text 25,1,"line5" \text 31,1,"line6" \text 37,1,"line7" \text 43,1,"line8" \text 49,1,"line9" \IfEnd \If S=2 \text 1,1,"line10" \text 7,1,"line11" \text 13,1,"line12" \text 19,1,"line13" \text 25,1,"line14" \text 31,1,"line15" \text 37,1,"line16" \text 43,1,"line17" \text 49,1,"line18" \IfEnd \If S=3 \text 1,1,"line19" \text 7,1,"line20" \IfEnd Anyone have any suggestions on how to do it?
-
Hi, I'm using a preg_replace to change [menu] into Menu::makeMenu(); , but when it executes the replace, for some reason it's sending my code to the first line after the <body> tag rather than where the [menu] was in the first place. Preg Replace: function formatPage($transform){ $a = array( "/\[element=\"(.*?)\"\]/ise", "/\ /ise", "/\[menu]/ise", "/\[login-button]/ise", ); $b = array( "elementCreate(\"$1\");", "pageCreate();", "Menu::makeMenu();", "loginBtn();", ); $transform = preg_replace($a, $b, $transform); return $transform; } I can copy out the whole function and stuff for the Menu:: but I don't think it'll matter. Please help! Cheers.
-
I'm trying to access the variables in the array below outside of the function. I've tried everything The variables I'm trying to access are bold and in red in the code below. These variables are just not accessible outside the function. function GenerateSitemap($params = array()) { // default parameters extract(shortcode_atts(array( 'title' => 'Site map', 'id' => 'sitemap', 'depth' => 2 ), $params)); // create sitemap $sitemap = wp_list_pages("title_li=&depth=$depth&sort_column=menu_order&echo=0"); if ($sitemap != '') { $sitemap = ($title == '' ? '' : "<h2>$title</h2>") . '<ul' . ($id == '' ? '' : " id=\"$id\"") . ">$sitemap</ul>"; } return $sitemap; } add_shortcode('sitemap', 'GenerateSitemap'); Thanks!!
-
Hi Guys, Just want to run past an idea I am having, I want to make sure the logic is sound. Basically, I am making a website statistics feature for my Content Management System. I want to create a function that will work out the most visited pages on the website. I currently collect a multitude of data, which is stored in a table in my database. Each time a person loads a page the data is added to the table. Some of that data includes the page id. My plan is call this data from the database and add the data to an array. As the rows of the table are being looped through, the script would check to see if the pageid is already in the array, and increment the count, and if not add it to the array until it has collected all of the logs. The array would then be sorted and the top 10 pages would be shown in a graph on the website. Does that logic make sense? Is there a simpler way of doing it? Any input would be great. Thanks!
-
all, can someone give me a push here (no pun intended)? Once again I can't figure out incredibly elementary issues because PHP is smart and has more than one option for many coding techniques. I'm trying to print all the elements in an array that are filled dynamically, but apparently I'm missing a line of code. the base 0 index is being overwritten instead of being pushed to the next int. here are 2 small scripts I've tried but both output the same thing, which is below the code blocks: <?php $arr = array(1,4,17,-9); test_arrayKeys_function($arr); function test_arrayKeys_function($inArray) { $Indicies = array(); $Indicies[] = array_keys($inArray, $inArray[0]); $Indicies[] = array_keys($inArray, $inArray[1]); $Indicies[] = array_keys($inArray, $inArray[2]); $Indicies[] = array_keys($inArray, $inArray[3]); print_r($Indicies); } ?> <?php $arr = array(1,4,17,-9); test_arrayKeys_function($arr); function test_arrayKeys_function($inArray) { $Indicies = array(); $Indicies[] = array_keys($inArray, $inArray[0]); array_push($Indicies, array_keys($inArray, $inArray[1])); array_push($Indicies, array_keys($inArray, $inArray[2])); array_push($Indicies, array_keys($inArray, $inArray[3])); print_r($Indicies); } ?> the output is always: Array ( [0] => Array ( [0] => 0 ) [1] => Array ( [0] => 1 ) [2] => Array ( [0] => 2 ) [3] => Array ( [0] => 3 ) ) Crutch anyone? thanks.
-
Sorry for the stupid question folks, but here's some code of mine I'm testing with: function test_getIndex_Of_Array() { $temp = array(); for ($i = 1; $i < 11; $i++) { $temp[$i - 1] = $i; } $count = sizeof($temp); for ($i = 0; $i < $count; $i++) { echo $i . ' ' . $temp[$i] . '<br>'; } } ////////////////////////////////////////////////////////////////////////////////// function test_ArraySum() { $temp = array(); for ($i = 1; $i < 11; $i++) { $temp[$i - 1] = $i; } $sum = array_sum($temp); echo $sum; } the 2 functions are called *in order* from a separate <php> script above that. that script just has the calls in it. I'm getting the echo from the 1st but nothing for the second. What rule about PHP am I missing here? There really needs to be a place on the web where rules about any IDE should be listed in the forms of enumerations so learning like this doesn't have to take place. After all, coding is nothing more than a bunch of rules... thanks guys.
-
hi all, here's some code for combinations of array values: $words = array(1,2,3,4); $num = count($words); //The total number of possible combinations $total = pow(2, $num); //Loop through each possible combination for ($i = 0; $i < $total; $i++) { //For each combination check if each bit is set for ($j = 0; $j < $total; $j++) { //Is bit $j set in $i? if (pow(2, $j) & $i) echo $words[$j] . ' '; } echo '<br />'; } I understand everything about this except the fact that the array indicies can only be 0-3 for an array with 4 elements like this one. What I'm not understanding is the nested loop for $J. Isn't it obvious that the bitwise outcome will never be = 1 everytime $J rises above 3 (which is the element count) and finishes it's loop? If the outcome was ever = 1 in that scenario, $words[$j] would be undefined and couldn't echo out, right? So the question is, why is this code written the way it is which renders most of the nested loop iterations for $J useless? If this is supposed to be in the math section, please let me know. thanks.
-
Hi there! I wish to output an array. In my PHP Script, I wrote this: function synchrouser($user,$pass) { $user = trim($user); $pass = md5(trim($pass)); $table = '_a_users'; $query ="SELECT * FROM $table WHERE userName='$user' AND userPassword='$pass'"; $myresult =mysql_query($query); $mydata = ""; while ($row =mysql_fetch_array($myresult)) { $lastName = $row["lastName"]; $firstName = $row["firstName"]; $school = $row["school"]; $promoYear = $row["promo"]; $exitYear = $row["promoOut"]; $promoNumber = $row["promoNum"]; $email = $row["email"]; //insertion of a "|" delimiter $mydata .= "|".$lastName."|".$firstName."|".$school."|".$promoYear."|".$exitYear."|".$promoNumber."|".$email; print "&mydata=".$mydata; } } What's wrong in this coding? Many thanks in advance for your help!
-
I have the folllowing loop which only displays the last part of the array: $i = 0; // create a varible that will tell us how many items we looped over foreach ($listprint as $key => $value) { $i++; $content2 = " <tr> <th>Qty</th> <th>Description</th> <th>ProductNumber</th> <th>Issue</th> </tr> <tr > <td>" . $value['Quantity'] . "</td></a> <td>" . $value['Description'] . "</td></a> <td>" . $value['ProductNumber'] . "</td></a> <td>" . $value['Issue'] . "</td></a> </tr> </table> "; } The array Array ( [0] => Array ( [ReferenceNumber] => 4543/2323/ [CustomerNumber] => CHU15 [CustomerName] => AngeloJoseph [Description] => Tewksbury [ProductNumber] => 2323/3232 [Quantity] => 5 [issue] => Holes in lining ) [1] => Array ( [ReferenceNumber] => 4543/2323/ [CustomerNumber] => CHU15 [CustomerName] => AngeloJoseph [Description] => Ryder Sahara Boots [ProductNumber] => 34343/232 [Quantity] => 2 [issue] => Ripped Lining ) [2] => Array ( [ReferenceNumber] => 4543/2323/ [CustomerNumber] => CHU15 [CustomerName] => AngeloJoseph [Description] => Oxford Brogues [ProductNumber] => 23232/323 [Quantity] => 1 [issue] => Broken Last ) )
-
Hi, this is the first time I have used arrays in php. I have searched around many other posts but can't seem to get my head around it. I am trying to process multiple arrays entered on a form. The number of entries could be different each time. This is the code I have so far: <?php function submitResults($fixture_id, $ht_goals, $at_goals, $et, $h_pens, $a_pens, $postponed) { //Put group selections into arry in MySQL INSERT value format $valuesAry = array(); foreach(array_keys($fixture_id) as $n) { $valuesAry[] = "($fixture_id[$n], $ht_goals[$n], $at_goals[$n], $et[$n], $h_pens[$n], $postponed[$n])"; } $query = "INSERT INTO test_results (fixture_id, ht_goals, at_goals, et, pens, postponed) VALUES ".implode(', ', $valuesAry); $result = mysql_query($query) or die("Query: {$query}<br>Error: ".mysql_error()); return $result; } ?> It currently displays an error: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' , , , ), (109, , , , , ), (162, , , , , ), (316, , , , , ), (563, , , , , ), (6' at line 2 Any help anyone can give me would be greatly appreciated.
- 11 replies
-
- array
- multiple arrays
-
(and 1 more)
Tagged with:
-
Hello all! I've posted here in the past and had great success, hoping for the same today. I have a wordpress site and I'm trying to pull the members into a page and sort them by results. It's a Musicians site and I need to be able to sort the members by the instruments they play. This code will pull the members into the page and you can see the results at: http://afm1.org/wp/?page_id=677 <?php $args = array( 'fields' => 'all', 'role' => 'Subscriber', 'meta_query' => array( array( 'key'=>'instrument' )) ); $members = get_users($args); //custom function for comparing the data we want to sort by function cmp($a, $B){ if ($a->instrument == $b->instrument) { return 0; } return ($a->instrument > $b->instrument) ? 1 : -1; } usort($members, 'cmp'); foreach ($members as $member ) { // get all the user's data $member_info = get_userdata($member->ID); echo '<div id="membox">'; echo $member_info->first_name. ' ' .$member_info->last_name.'<br />'; echo $member_info->address_1.'<br />'; echo $member_info->city.', '.$member_info->state.', '.$member_info->zip.'<br />'; echo $member_info->phone.'<br />'; echo '<a href="mailto:'.$member_info->email.'">'.$member_info->email.'</a><br />'; foreach ($member_info->instrument as $inst) { echo '<b>'.$inst.'</b>, '; } echo '</div>'; } ?> What I want to do is have the Instrument as a title and have all of the members that play that instrument listed like this: <h1>Accordian</h1> Arpi Anderson 1234 Whitfield Avenue Cincinnati, OH, 45220 513-111-1111 arpianderson@hotmail.com Accordion, David Abbott 123 N. Ft. Thomas Ave. Ft. Thomas, KY, 41075 859-111-1111 davejanet@acninc.net Accordion, Acoustic, <h1>Violin</h1> Ann Baer 123 Cabinridge Batavia, OH, 45103 513-111-1111 violin@cinci.rr.com Violin, Any help would be GREATLY appreciated! Thanks
-
Good afternoon everyone, and happy holidays! Although my membership might not qualify as "new" to this forum, I've never used my account here before but today I think I finally found a reason to! I'm trying to exclude four (4) values from array, which will then echo the remaining values into a drop-down box on a form. Here is the contents of the array: Array ( [0] => stdClass Object ( [id] => 22 [icao] => CYQM [name] => Greater Moncton International Airport - CHARTER [country] => Canada [lat] => 46.1122 [lng] => -64.6786 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [1] => stdClass Object ( [id] => 19 [icao] => EINN [name] => Shannon International Airport - CHARTER [country] => Ireland [lat] => 52.702 [lng] => -8.92482 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [2] => stdClass Object ( [id] => 16 [icao] => KAUS [name] => Austin-Bergstrom International Airport [country] => United States [lat] => 30.1945 [lng] => -97.6699 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [3] => stdClass Object ( [id] => 9 [icao] => KDEN [name] => Denver International Airport [country] => United States [lat] => 39.8583 [lng] => -104.667 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [4] => stdClass Object ( [id] => 2 [icao] => KLAS [name] => McCarran International Airport [country] => United States [lat] => 36.0827 [lng] => -115.154 [hub] => 1 [fuelprice] => 0 [chartlink] => ) [5] => stdClass Object ( [id] => 5 [icao] => KLGB [name] => Long Beach Airport [country] => United States [lat] => 33.8175 [lng] => -118.152 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [6] => stdClass Object ( [id] => 14 [icao] => KOAK [name] => Metropolitan Oakland International Airport [country] => United States [lat] => 37.721 [lng] => -122.222 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [7] => stdClass Object ( [id] => 10 [icao] => KPDX [name] => Portland International Airport [country] => United States [lat] => 45.5887 [lng] => -122.598 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [8] => stdClass Object ( [id] => 3 [icao] => KPHX [name] => Phoenix Sky Harbor International Airport [country] => United States [lat] => 33.4359 [lng] => -112.01 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [9] => stdClass Object ( [id] => 12 [icao] => KRNO [name] => Reno/Tahoe International Airport [country] => United States [lat] => 39.4991 [lng] => -119.768 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [10] => stdClass Object ( [id] => 4 [icao] => KSAN [name] => San Diego International Airport [country] => United States [lat] => 32.7334 [lng] => -117.188 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [11] => stdClass Object ( [id] => 17 [icao] => KSAT [name] => San Antonio International Airport [country] => United States [lat] => 29.5338 [lng] => -98.47 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [12] => stdClass Object ( [id] => 6 [icao] => KSEA [name] => Seattle-Tacoma International Airport [country] => United States [lat] => 47.449 [lng] => -122.309 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [13] => stdClass Object ( [id] => 8 [icao] => KSFO [name] => San Francisco International Airport [country] => United States [lat] => 37.6188 [lng] => -122.376 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [14] => stdClass Object ( [id] => 15 [icao] => KSJC [name] => San Jose International Airport [country] => United States [lat] => 37.3619 [lng] => -121.929 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [15] => stdClass Object ( [id] => 11 [icao] => KSLC [name] => Salt Lake City International Airport [country] => United States [lat] => 40.7884 [lng] => -111.978 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [16] => stdClass Object ( [id] => 7 [icao] => KSMF [name] => Sacramento International Airport [country] => United States [lat] => 38.6952 [lng] => -121.592 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [17] => stdClass Object ( [id] => 13 [icao] => KTNT [name] => Dade-Collier Training Airport - CHARTER [country] => United States [lat] => 25.862 [lng] => -80.8967 [hub] => 0 [fuelprice] => 0 [chartlink] => ) [18] => stdClass Object ( [id] => 18 [icao] => LTAI [name] => Antalya International Airport - CHARTER [country] => Turkey [lat] => 36.8987 [lng] => 30.8005 [hub] => 0 [fuelprice] => 0 [chartlink] => ) ) 1 As you can see, it's one (1) array that's broken up into a separate stdClass Object() array of some sort. My goal here is to exclude the following [id] values from the set of arrays above: 13, 18, 19, 22 The problem is that each array key (ex. [1], [2], [3]) from the first array will change when the contents of the array is increased over time. Therefore, I cannot simply exclude array keys [1], [2], [17], [18] Here's the code I'm working with now: <div id="depapttab"> <p>Select your departure airport:</p> <select id="depicao" name="depicao"> <option value="">Select All</option> <?php if(!$depairports) $depairports = array(); foreach($depairports as $airport) { if($depairports->id != array(13,18,19,22)) { echo '<option value="'.$airport->icao.'">'.$airport->icao.' - '.$airport->name.'</option>'; } } ?> </select> <input type="submit" name="submit" value="Find Flights" /> </div> I just don't know how to include that darn stdClass Object() in my if() statement. If someone could lend a hand, it'd be much appreciated! Thanks in advance!
-
Hi all I have a function below that searches an array and assigns it to $totalmonthlycost. I need to know how I get the array key of the chosen array value ($m12 - $m60) How do I return the array key in the below code? $monthvalues = array($m12,$m18,$m24,$m30,$m36,$m42,$m48,$m54,$m60); function closest($monthvalues, $number){ #does the array already contain the number? if($i = array_search( $number, $monthvalues)) return $i; #add the number to the array $monthvalues[] = $number; #sort and refind the number sort($monthvalues); $i = array_search($number, $monthvalues); #check if there is a number above it if($i && isset($monthvalues[$i-1])) return $monthvalues[$i-1]; //alternatively you could return the number itself here, or below it depending on your requirements } $totalmonthlycost = closest($monthvalues, $idealcostpermonth); Thanks for your help. Pete
-
This one is a doozy for me. My brain is fried after spending a couple days trying to figure this out. None of my formulas have seemed to work out enough. So I'm waiving my white flag and asking for some help. Below is a simplified version of my code. The purpose of this page is an estimate calculator. It is for a window cleaning service, and they have pricing for doing the insides of windows and the outsides. Each style of window has different pricing for each inside and outside. What is supposed to happen in the form is this: If they want an estimate for say basic window cleaning for both inside and outside, they will check the chechboxes for both inside and outside. Then enter a number for the amount of windows to clean. The formula for this would look something like this: Amount = Inside Price x Outside Price (if inside price and outside price checkboxes are ticked). And for each entry, it needs to add up the total. But none of the foreach or while loops i try to create seem to do the trick. Basic Form Setup: $query = "SELECT * FROM estimates WHERE 1 ORDER BY id ASC"; $result = mysql_query($query); while ($estimates = mysql_fetch_object($result)) { $style = $estimates->style; $insidePrice = $estimates->price; $outsidePrice = $estimates->out; echo $style.' <input type="checkbox" name="insidePrice[]" value ="'.$insidePrice,'" /> $'.$insidePrice.' <input type="checkbox" name="outsidePrice[]" value ="'.$outsidePrice,'" /> $'.$outsidePrice.' <input type="text" name="amount[]" />'; } And an idea of how i want this to work: foreach ($_POST['amount'] as $key => $a){ if ($a != "" or $a !="0"){ //Now to llustrate what Im trying to do, I know this is wrong though foreach ($_POST['insideAmount'] as $i){ $i = $i*$a; } foreach ($_POST['outsideAmount'] as $o){ $o = $o*$a; } $a = $i+$o; } //Trying to add each row as they build to make the estimate total $prev = $a[$key-1]; $a = $a+$prev; $total = $a; } echo "$total";
-
The website I am working on is a HRIS project for a popular fast food franchise chain. The login for one restaurant allows one user to modify all actions for all restaurants owned by the same franchisee. These are organized by multiple databases calling the same id's. Below is the code used for selecting all restaurants where the same franchise id is used as the restaurant login. $result = mysql_query("SELECT id, name FROM restaurants WHERE franchise = $_SESSION[sESS_RESTAURANT_FRANCHISE]"); $_SESSION['franchise_arr'] = array(); while($row = mysql_fetch_array($result)){ $_SESSION['franchise_arr'][$row['id']] = $row['name']; } So lets say for one login the SESSION array is populated like this: $_SESSION[sESS_RESTAURANT_FRANCHISE][1] = "Restaurant One"; $_SESSION[sESS_RESTAURANT_FRANCHISE][15] = "Restaurant Two"; $_SESSION[sESS_RESTAURANT_FRANCHISE][29] = "Restaurant Three"; I need a way to check to see if the KEY value is in an array as oppose to the value itself. For example I have: if (!in_array($rest, $_SESSION['franchise_arr'])){ $rest = $_SESSION['SESS_RESTAURANT_ID']; } However that checks for the values "Restaurant One", "Restaurant Two", "Restaurant Three". Where I would like it to look for "1", "15", or "29". I hope someone understands what I mean :\ I've been strugging with this for quite a while.
-
Hi there mates, I've got a question from a friend of mine. And I could not solve it and I am ashamed of myself haha . The code is not yet complete, but what it has to do, is post the array, whick contains the names of the files uploaded ( pictures in this case ) The first post works, but thats it, it doesnt show the array on the last past it only shows "array". Please help me fix problem, I translated a bit of the code from dutch to english, so it's a bit more clear Thanks in advance David fotoinvoerpagina2.php
-
Hi, I'm hoping this is something quite basic. I'm trying to group values from a MySQL query into an array. I have a Wordpress set-up but I'm presuming this is more of a PHP rather than a Wordpress concern. I just want to know basically what is the best way of doing this. Essentially I currently have the following data: Artist Name #1 - Event Date #1 Artist Name #2 - Event Date #2 Artist Name #1 - Event Date #3 Artist Name #1 - Event Date #4 And I want to find a way that I can group the Artist Names so that the data would output like this: Artist Name #1 Event Date #1 Event Date #3 Event Date #4 Artist Name #2 Event Date #2 This is the code I have at the moment. How would I integrate an array and an extra Foreach loop to get the data organised like this. I'm still learning Arrays at the moment and would appreciate any assistance with this. global $post; $args = array( 'post_type' => 'event', 'orderby' => 'meta_value', 'meta_key' => 'event_date', 'meta_compare' => '>', 'meta_value' => $todaysDate, 'numberposts' => 6, 'order' => 'ASC' ); $whatson = get_posts( $args ); foreach( $whatson as $post ) : echo get_the_title(get_post_meta($post->ID, '2artist', true)) . " - "; echo get_post_meta($whatson_query->ID, 'event_date', true); endforeach; Thanks! Russ