PHP - Creating Neat Little Sub-array From Big Array
My longest post of the year..... (thank you in advance for scrolling 😀) Array ( [newQuantity77777] => 3 [newPrice77777] => 5.00 [usedQuantity77777] => 1 [usedPrice77777] => 3.99 [total77777] => 18.99 [newQuantity88888] => // sometimes empty [newPrice88888] => [usedQuantity88888] => 4 [usedPrice88888] => 12.00 [total88888] => 48.00 [newQuantity44444] => 2 [newPrice44444] => 4.00 [usedQuantity44444] => 0 [usedPrice44444] => 3.99 [total44444] => 8.00 // these values I don't need [date] => July 25 2021 // these values below I don't need [address] => 123 Anystreet Avenue [address2] => [zipcode] => 90210 [city] => Beverly Hills [state] => CA [planet] => Mars ) I've been trying to use that array to create a special "sub-array" for only the SKU numbers and just their new and used quantities and prices. DESIRED RESULT: Array ( [77777] => Array ( [newQuantity] => 3 [newPrice] => 5.00 [usedQuantity] => 1 [usedPrice] => 3.99 ) [88888] => Array ( [newQuantity] => 0 [newPrice] => 0 [usedQuantity] => 4 [usedPrice] => 12.00 ) [44444] => Array ( [newQuantity] => 2 [newPrice] => 4.00 [usedQuantity] => 0 [usedPrice] => 3.99 ) ) Knowing that my SKU numbers are always exactly 5 digits, and no other $_POST keys will ever have 5 digits, I've been able to accomplish this with horribly convoluted and unsatisfactory code like this: $sku = array(); foreach($_POST as $var => $val) { $number = substr($var,-5); if (preg_match("/\d{5}/",$sku)) { $sku[$number] = // the array keys will be the SKU numbers // then I keep looping to look for the string "newQuantity" // capture that value... and create little mini arrays // for my big multidimensional array..... Is there a better way to go about this? Thank you. Similar TutorialsI am retrieving values in form of array from a database table and out of the I have to build multidimensional array depending upon the parent->child relationship in the same array. The result is as => Array ( => Array ( [label] => Shirt [uri] => # ) [1] => Array ( [label] => Jeans [uri] => # ) [2] => Array ( [label] => Lowers [uri] => # ) [3] => Array ( [label] => T-Shirts [uri] => # ) [4] => Array ( [label] => cotton shirt [uri] => # ) [5] => Array ( [label] => Trousers [uri] => # ) ) each is related to some parent-id. Can any body me any idea. All I am not the best at PHP and have been trying to work out how to make a treeview from an array. I managed to get as afar as populating my array as i would like and I can get those values back but now im really stuck What id love to be able to do is use my area field as the parent and my title field as the child and have a counter on the parent with no of child nodes. If someone can help me out with that bit id be really greatful, as I ve already sorted my javascript etc this is my last problem and its driving me nuts Many Thanks for looking and i really do appreciate any help Gibbo <?php $row = 0; $myarray = array(); foreach ($view->result as $result) { $arg = $view->render_field('field_decision_type_value', $row); $arg2 = $view->render_field('title', $row); $myarray[$row]["area"]=$arg; $myarray[$row]["title"]=$arg2; $row++; } asort($myarray); $last = count($myarray) - 1; $rowcount=0; while ($rowcount <= $last) { print $myarray[$rowcount]["area"]; print $myarray[$rowcount]["title"].'|<br />'; $rowcount++; } ?> Hi. I need some help working something out. I have an array that has all the numbers from, 0 to 9. What I want to do is loop through the array to make all the combinations possible up to a string thats 255 chars long. $array = array( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ); Should be looped through to create strings like this: Code: [Select] 0 1 2 3 4 5 6 7 8 9 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 etc.. Just as if it's counting. I have a array for example: Code: [Select] $item = array( "Great <em>Bittern</em>"=>"Botaurus stellaris", "Little <em>Grebe</em>"=>"Tachybaptus ruficollis", "Black-necked Grebe"=>"Podiceps nigricollis"); which will output Code: [Select] Array ( [Great Bittern] => Botaurus stellaris [Little Grebe] => Tachybaptus ruficollis [Black-necked Grebe] => Podiceps nigricollis ) how can I input data from a database so it comes out as the array assuming I have $row[3] and $row[0] as the data? for example Code: [Select] while($row=mysql_fetch_array($result)){ //$item.=array($row[3],$row[0]); //array_push($item,array($row[3]=>$row[0])); //$item.=array($row[3]=>$row[0]); $item.="[".$row[3]."]=>".$row[0]; } which of course doesnt work?? Alright, this has been puzzling me for a while now and I think it's time I seek help before my brain turns to mush. I've been modifying a PHP text based game called Legend of the Green Dragon to add more functionality, etc. One of the things I want to add is the ability to add levels higher then 15. The original array looks like this: $exparray = array(1=>100,2=>400,3=>1002,4=>1912,5=>3140,6=>4707, 7=>6641,8=>8985, 9=>11795,10=>15143,11=>19121,12=>23840, 13=>29437,14=>36071,15=>43930, ); Now, I could just hardcode each level, but noo, I want to be able to do it from a module type thing from the admin panel (which I've already gotten that working gratefully) so I've tried writing a few different scripts to take the information from the MySQL database and turn it into an array like above but I've gotten completely lost. This is what I currently have: $expsql = "SELECT * FROM " . db_prefix("myolevels"); $numrows = mysql_num_rows($expsql); for ($i = 1; $i <= $numrows; $i++) { $expresult = mysql_query($expsql); while ($rows = mysql_fetch_assoc($expresult)) { $exparray = array($i=>$rows['myoexpreq']); } } Although when I call the array, it always returns null for the myoexpreq causing your master to look for you all the time (forcing level up when it shouldn't be). Is there any way to create an array like the first with SQL? Thought this might help as well: PHP Warning: "Variable passed to each() is not an array or object" in /home/ileetcom/public_html/logd/lib/experience.php at 35. Call Stack: 2: each(NULL) called from /home/ileetcom/public_html/logd/lib/experience.php on line 35 3: exp_for_next_level(16, "0") called from /home/ileetcom/public_html/logd/village.php on line 131 Hello I was trying from days to create an array from a txt file by i can't make it happen. I am so desperate now and i want your help guys The code create a txt file from a textarea feild after it's submited each on a line. After that the php code need collect these data from the txt file and create an array from them. Example: if i type in the textarea: test test1 test2 I want these usernames to be inserted in the array so it would be like this: $names = array('test','test1','test2'); Anyone can help me This is the code <html> <head> <title></title> <style type="text/css"> body{ background-color:#1166aa; } #mainbox{ width:inherit; background-color:#FFFFFF; padding:14px; border:solid 3px #000000; float:left; } #mainbox2{ background-color:#CCCCCC; border:solid 2px #000000; padding:11px; } #contaner{ border:solid 0px #00FF00; } h1:hover{ color:#0000CC; cursor:pointer; } #msg{ cursor:pointer; } table td{ border-top:outset 1px #999999; } #amount{ color:#FF0000; cursor:crosshair; } #to{ color:#3300FF; } #from{ color:#3300FF; } #subject{ color:#3300FF; } </style> </head> <body alink="#003399" vlink="#003399"> <?php ///////////////////////////////////////////////// function create_list(){ $list= ($_GET ['name_list']); $file= "list.txt"; $file_pointer = fopen($file ,'w'); fwrite($file_pointer , $list); fclose($file_pointer); } ////////////////////////////////////////////////// $list= ""; create_list(); ////////////////////////////////////////////////// function explodeRows($data) { $rowsArr = explode("\n", $data); return $rowsArr; } $filename = "list.txt"; $handle = fopen($filename, 'r'); $data = fread($handle, filesize($filename)); $rowsArr = explodeRows($data); for($i=0;$i<count($rowsArr);$i++) { $name = explodeRows($rowsArr[$i]); function name(){ $names = array('the usernames submited to be inserted here','the usernames submited to be inserted here',.......); } } //////////////////////////////////////////////////// if ($_GET ['submit'] == "submit"){ create_list(); name(); } ?> <script type="text/javascript"> function foo(textarea,limit){ var val=textarea.value.replace(/\r/g,'').split('\n'); if(val.length>limit){ alert('You can not enter\nmore than '+limit+' lines'); textarea.value=val.slice(0,-1).join('\n') } } </script> <table align="center" id="contaner"> <tr><td> <form action="<?php $_SERVER [SERVER_NAME]; ?>" method="get"> <div id="mainbox"> <div id="mainbox2"> <table> <tr> <td>name List :</td> </tr> </table> <textarea id="name_list" name="name_list" cols="60" rows="9" onkeyup="foo(this,50)"></textarea> </div> <tr> <td><center><input name="submit" type="submit" value="submit"/></center></td> </tr> </div> </form> </tr></td> </table> </body> </html> Hi, I want to develop array like following Code: [Select] $BCD=array('type' =>'TYPE1', array( 0=>array('column1'=>'value1','column2'=>'value1','column3'=>'value1','column4'=>'value1','column5'=>'value1','column6'=>'value1','column7'=>0), 1=>array('column1'=>'value1','column2'=>'value1','column3'=>'value1','column4'=>'value1','column5'=>'value1','column6'=>'value1','column7'=>0), 2=>array('column1'=>'value1','column2'=>'value1','column3'=>'value1','column4'=>'value1','column5'=>'value1','column6'=>'value1','column7'=>0), 3=>array('column1'=>'value1','column2'=>'value1','column3'=>'value1','column4'=>'value1','column5'=>'value1','column6'=>'value1','column7'=>0), ) )); I have written following code to achieve the same but not getting result. Code: [Select] $sql = "select * from tablename "; $result = mysql_query($sql); $k=0; while ($row = $db->mysql_fetch_array($result)) { // array_push($BCD['type'],$row['type']); $BCD1=array('type' =>$row['type'], array( $k=>array('column1'=>$row['column1'],'column2'=>$row['column2'],'column3'=>$row['column3'],'column4'=>$row['column4'], 'column5'=>$row['column5'],'column6'=>$row['column6'],'column7'=>$row['column7']) )); $k++; } I need to extract shopping cart transaction information from a database, convert it to json format and send to another DB. Because the fields are not a direct match the calculated values are first bing put into variables. I'm extracting the line items from the database into an array and looping through the array to get each line item which I want to then insert into another array as a sub array. By the way, I'm new at PHP so be gentle. The first step I've coded as: Code: [Select] foreach ($oit_array as $inner1) { // Check type if (!is_array($inner1)) {$inner1 = array($inner1);} $lineprice+=$inner1[orderitem_price]; //calculate amounts required in variables $linepriceinc=$inner1[orderitem_price]+($inner1[orderitem_tax]/$inner1[orderitem_quantity]); if($inner1[orderitem_tax]==0){$linetaxrate+=0;} else $linetaxrate=($inner1[orderitem_final_price]-$inner1[orderitem_tax])/$inner1[orderitem_tax]; $linetaxtotal+=$inner1[orderitem_tax]; $orderqty+=$inner1[orderitem_quantity]; $productname=$inner1[orderitem_name]; $qtyshipped+=$inner1[orderitem_quantity]; $totallineamount+=$inner1[orderitem_final_price]-$inner1[orderitem_tax]; $totallineamountinc+=$inner1[orderitem_final_price]; $unitofmeasure="Units"; $linearray[] = array("LinePrice"=>$lineprice, "LinePriceInc"=>$linepriceinc, "LineTaxCode"=>"GST", "LineTaxRate"=> $linetaxrate, "LineTaxTotal"=> $linetaxtotal, "OrderQty"=> $orderqty, "ProductName"=> $productname, "QtyShipped"=> $orderqty, "TotalLineAmount"=> $totallineamount, "TotalLineAmountInc"=>$totallineamountinc, "UnitOfMeasure"=>"Units"); I then reference the array as $linearray as follows: Code: [Select] //Create Array $salesarray= array ("type"=> "TCashSale", "fields"=>array ("CustomerName"=>$customername, "ShipToDesc"=>$shiptodesc, "Lines"=> array("type"=> "TCashSaleLine", "fields"=> $linearray)), "SalesPayments"=>array("type"=>"TSalesPayments", "fields"=>array("Amount"=> $amount, "PayMethod"=> $paymentmethod))); The problem that I have is that the resulting array contains square brackets around the "linearray" data like so: Code: [Select] {"type":"TCashSale","fields":{"CustomerName":"Cash Customer","ShipToDesc":"Rod Farrell\n\r1234 Short St\n\r\n\rSlackville Queensland 4001","Lines":{"type":"TCashSaleLine","fields":[{"LinePrice":54.54545,"LinePriceInc":54.54545, What am I doing wrong?? 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! Hi guys, Is there an html code that allows you to array a form input? and once you passed the form, how do you extract the data then insert it to the database? Thanks 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'); I have a simple detection for mobile devices and it works fine but it has gotten a bit bloated so I tried to put the list in an array. I don't get errors but it doesn't work. Here is what I tried $useragents = array("iPhone","iPod","incognito","webmate","Android","dream","CUPCAKE","blackberry9500","blackberry9530","blackberry9520","blackberry9550","blackberry 9800","webOS","s8000","bada","Googlebot-Mobile"); if (in_array(1, $useragents)) { $phones = strpos($_SERVER['HTTP_USER_AGENT'], $useragents); } if ($phones == true) { include_once './template/phones.php';} Please assist I'm trying to create a website, that echo's out a bunch of groups, where each group contains a group of checkboxes, containing A value, and a label for the checkbox, the way it is created right now, is foreach that echo's out a bunch of php arrays, which was easier than the static way before - But still, it's static in some way, or not very user friendly at the moment.. My problem is that I really want to write it in a database when I have the option. Is there anyone that can give some tips how to do? At the moment, my foreach looks like this: Code: [Select] echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">'; /* NEXT WE CREATE OUR FOREACH LOOPS TO ECHO THE HTML FOR LOOKS AND CHECKBOXES */ $totalID=0; // this is a counter we use to build our check box names foreach ($items as $list){ $totalID++; // add one to the checkbox name counter echo "<h2>{$list['title']}</h2>\n"; // and echo out our section header foreach ($list['items'] as $cbox){ // now for each item in the list, call it $cbox // $cbox now holds the item name, and point value echo "<label class='checkbox'><input type='checkbox' name='totals[$totalID][]' value='{$cbox[1]}'> {$cbox[0]}</label>\n"; } } echo "</form>"; And my array is something like this: Code: [Select] $items['computers']['title']='Computer Brand'; $items['computers']['items'][]=array('Apple iMac',1); $items['computers']['items'][]=array('Apple Macbook',.5); $items['phones']['title']='Phone Brand'; $items['phones']['items'][]=array('iPhone',1); $items['phones']['items'][]=array('HTC',1); As said, I can write this, but takes time. I want to get it into a database, that data above, but I'm having problems about echo'ing it out, I really can't see how I should do. My current database looks like this: Thank you! I have the following code: Code: [Select] private function buildJSResponse(){ $data = ""; $i = 0; $arr = array(); while($this->db->row()){ $arr[] = (int)$this->db->field("average"); } $this->max = max($arr); $this->min = min($arr); $this->mid = round(($this->max + $this->min) / 2); foreach($arr as $val){ $nTime = ($val / $this->max) * 100; $data .= "data[$i] = ".$nTime.";"; $i++; } return $data; } It takes an array, finds the max/min and number halfway between the min/max. The next part I am not sure what to do. I am making a line graph using the canvas, so I am building a javascript array, which will contain the point on the chart. The problem I am having, is location. Lets say $max = 110, and $min = 95. the y position on the graph should be 0 for $max, and 100 for $min, then all the other points need to fall into their place as well. $nTime is supposed to do that, but it doesn't any suggestions? The attachment is the result I am getting from my above code. As you can see the lowest number is 49, so the value with 49 should touch the bottom, which it doesn't. How can one create an array for the set,A={x:1<=x<=100, x is perfect square}, using php programming? I suck with arrays, there I said it . With that said, hopefully someone can help me here. I have two multi-dimensional arrays called $allteams and $chosenteams (the contents of which are listed below). I simply want to compare them and make a new array of the items that are in the first array ($allteams) but NOT in the second array ($chosenteams). NOTE: I tried to use array_diff() but couldn't get it to work since they are multidimensional... FYI, I'm also confused why the info appears to be listed twice but I think that just has to do with associative vs. numeric arrays (i.e. I think I just need to specify one and the amount info would be cut in half), but I'll research this more on my own as it seems like it has to be easy to find $allteams Array ( => Array ( => 1 [teamid] => 1 [1] => Philadelphia [teamcity] => Philadelphia [2] => Eagles [teamname] => Eagles ) [1] => Array ( => 2 [teamid] => 2 [1] => Dallas [teamcity] => Dallas [2] => Cowboys [teamname] => Cowboys ) [2] => Array ( => 3 [teamid] => 3 [1] => New York [teamcity] => New York [2] => Giants [teamname] => Giants ) [3] => Array ( => 4 [teamid] => 4 [1] => Washington [teamcity] => Washington [2] => Redskins [teamname] => Redskins ) [4] => Array ( => 5 [teamid] => 5 [1] => Detroit [teamcity] => Detroit [2] => Lions [teamname] => Lions ) [5] => Array ( => 6 [teamid] => 6 [1] => Minnesota [teamcity] => Minnesota [2] => Vikings [teamname] => Vikings ) [6] => Array ( => 7 [teamid] => 7 [1] => Green Bay [teamcity] => Green Bay [2] => Packers [teamname] => Packers ) [7] => Array ( => 8 [teamid] => 8 [1] => Chicago [teamcity] => Chicago [2] => Bears [teamname] => Bears ) [8] => Array ( => 9 [teamid] => 9 [1] => Tampa Bay [teamcity] => Tampa Bay [2] => Buccs [teamname] => Buccs ) [9] => Array ( => 10 [teamid] => 10 [1] => New Orleans [teamcity] => New Orleans [2] => Saints [teamname] => Saints ) [10] => Array ( => 11 [teamid] => 11 [1] => Carolina [teamcity] => Carolina [2] => Panthers [teamname] => Panthers ) [11] => Array ( => 12 [teamid] => 12 [1] => Atlanta [teamcity] => Atlanta [2] => Falcons [teamname] => Falcons ) [12] => Array ( => 13 [teamid] => 13 [1] => Seattle [teamcity] => Seattle [2] => Seahawks [teamname] => Seahawks ) [13] => Array ( => 14 [teamid] => 14 [1] => San Francisco [teamcity] => San Francisco [2] => 49ers [teamname] => 49ers ) [14] => Array ( => 15 [teamid] => 15 [1] => St. Louis [teamcity] => St. Louis [2] => Rams [teamname] => Rams ) [15] => Array ( => 16 [teamid] => 16 [1] => Arizona [teamcity] => Arizona [2] => Cardinals [teamname] => Cardinals ) [16] => Array ( => 17 [teamid] => 17 [1] => New York [teamcity] => New York [2] => Jets [teamname] => Jets ) [17] => Array ( => 18 [teamid] => 18 [1] => Miami [teamcity] => Miami [2] => Dolphins [teamname] => Dolphins ) [18] => Array ( => 19 [teamid] => 19 [1] => Buffalo [teamcity] => Buffalo [2] => Bills [teamname] => Bills ) [19] => Array ( => 20 [teamid] => 20 [1] => New England [teamcity] => New England [2] => Patriots [teamname] => Patriots ) [20] => Array ( => 21 [teamid] => 21 [1] => Baltimore [teamcity] => Baltimore [2] => Ravens [teamname] => Ravens ) [21] => Array ( => 22 [teamid] => 22 [1] => Cincinnati [teamcity] => Cincinnati [2] => Bengals [teamname] => Bengals ) [22] => Array ( => 23 [teamid] => 23 [1] => Pittsburgh [teamcity] => Pittsburgh [2] => Steelers [teamname] => Steelers ) [23] => Array ( => 24 [teamid] => 24 [1] => Cleveland [teamcity] => Cleveland [2] => Browns [teamname] => Browns ) [24] => Array ( => 25 [teamid] => 25 [1] => Houston [teamcity] => Houston [2] => Texans [teamname] => Texans ) [25] => Array ( => 26 [teamid] => 26 [1] => Tennessee [teamcity] => Tennessee [2] => Titans [teamname] => Titans ) [26] => Array ( => 27 [teamid] => 27 [1] => Jacksonville [teamcity] => Jacksonville [2] => Jaguars [teamname] => Jaguars ) [27] => Array ( => 28 [teamid] => 28 [1] => Indianapolis [teamcity] => Indianapolis [2] => Colts [teamname] => Colts ) [28] => Array ( => 29 [teamid] => 29 [1] => Denver [teamcity] => Denver [2] => Broncos [teamname] => Broncos ) [29] => Array ( => 30 [teamid] => 30 [1] => Kansas City [teamcity] => Kansas City [2] => Chiefs [teamname] => Chiefs ) [30] => Array ( => 31 [teamid] => 31 [1] => Oakland [teamcity] => Oakland [2] => Raiders [teamname] => Raiders ) [31] => Array ( => 32 [teamid] => 32 [1] => San Diego [teamcity] => San Diego [2] => Chargers [teamname] => Chargers ) ) $chosenteams Array ( => Array ( => 2 [teamid] => 2 [1] => Dallas [teamcity] => Dallas [2] => Cowboys [teamname] => Cowboys ) [1] => Array ( => 3 [teamid] => 3 [1] => New York [teamcity] => New York [2] => Giants [teamname] => Giants ) ) Again, I just want to compare those two multi-dimensional arrays and end up with another array that only has the items that are in the first but NOT in the second. So now I'm trying to do it the way below using simply "array_push" Code: [Select] $remainingteams = array(); foreach($allteams as $teamname=> $value) { if (in_array($teamname, $chosenteams)) { } else { array_push($remainingteams,$teamname); } } My end result based on the way the arrays are in this example should be... $remainingteams (really the only difference is that the Cowboys and Giants info is gone) Array ( => Array ( => 1 [teamid] => 1 [1] => Philadelphia [teamcity] => Philadelphia [2] => Eagles [teamname] => Eagles ) [3] => Array ( => 4 [teamid] => 4 [1] => Washington [teamcity] => Washington [2] => Redskins [teamname] => Redskins ) [4] => Array ( => 5 [teamid] => 5 [1] => Detroit [teamcity] => Detroit [2] => Lions [teamname] => Lions ) [5] => Array ( => 6 [teamid] => 6 [1] => Minnesota [teamcity] => Minnesota [2] => Vikings [teamname] => Vikings ) [6] => Array ( => 7 [teamid] => 7 [1] => Green Bay [teamcity] => Green Bay [2] => Packers [teamname] => Packers ) [7] => Array ( => 8 [teamid] => 8 [1] => Chicago [teamcity] => Chicago [2] => Bears [teamname] => Bears ) [8] => Array ( => 9 [teamid] => 9 [1] => Tampa Bay [teamcity] => Tampa Bay [2] => Buccs [teamname] => Buccs ) [9] => Array ( => 10 [teamid] => 10 [1] => New Orleans [teamcity] => New Orleans [2] => Saints [teamname] => Saints ) [10] => Array ( => 11 [teamid] => 11 [1] => Carolina [teamcity] => Carolina [2] => Panthers [teamname] => Panthers ) [11] => Array ( => 12 [teamid] => 12 [1] => Atlanta [teamcity] => Atlanta [2] => Falcons [teamname] => Falcons ) [12] => Array ( => 13 [teamid] => 13 [1] => Seattle [teamcity] => Seattle [2] => Seahawks [teamname] => Seahawks ) [13] => Array ( => 14 [teamid] => 14 [1] => San Francisco [teamcity] => San Francisco [2] => 49ers [teamname] => 49ers ) [14] => Array ( => 15 [teamid] => 15 [1] => St. Louis [teamcity] => St. Louis [2] => Rams [teamname] => Rams ) [15] => Array ( => 16 [teamid] => 16 [1] => Arizona [teamcity] => Arizona [2] => Cardinals [teamname] => Cardinals ) [16] => Array ( => 17 [teamid] => 17 [1] => New York [teamcity] => New York [2] => Jets [teamname] => Jets ) [17] => Array ( => 18 [teamid] => 18 [1] => Miami [teamcity] => Miami [2] => Dolphins [teamname] => Dolphins ) [18] => Array ( => 19 [teamid] => 19 [1] => Buffalo [teamcity] => Buffalo [2] => Bills [teamname] => Bills ) [19] => Array ( => 20 [teamid] => 20 [1] => New England [teamcity] => New England [2] => Patriots [teamname] => Patriots ) [20] => Array ( => 21 [teamid] => 21 [1] => Baltimore [teamcity] => Baltimore [2] => Ravens [teamname] => Ravens ) [21] => Array ( => 22 [teamid] => 22 [1] => Cincinnati [teamcity] => Cincinnati [2] => Bengals [teamname] => Bengals ) [22] => Array ( => 23 [teamid] => 23 [1] => Pittsburgh [teamcity] => Pittsburgh [2] => Steelers [teamname] => Steelers ) [23] => Array ( => 24 [teamid] => 24 [1] => Cleveland [teamcity] => Cleveland [2] => Browns [teamname] => Browns ) [24] => Array ( => 25 [teamid] => 25 [1] => Houston [teamcity] => Houston [2] => Texans [teamname] => Texans ) [25] => Array ( => 26 [teamid] => 26 [1] => Tennessee [teamcity] => Tennessee [2] => Titans [teamname] => Titans ) [26] => Array ( => 27 [teamid] => 27 [1] => Jacksonville [teamcity] => Jacksonville [2] => Jaguars [teamname] => Jaguars ) [27] => Array ( => 28 [teamid] => 28 [1] => Indianapolis [teamcity] => Indianapolis [2] => Colts [teamname] => Colts ) [28] => Array ( => 29 [teamid] => 29 [1] => Denver [teamcity] => Denver [2] => Broncos [teamname] => Broncos ) [29] => Array ( => 30 [teamid] => 30 [1] => Kansas City [teamcity] => Kansas City [2] => Chiefs [teamname] => Chiefs ) [30] => Array ( => 31 [teamid] => 31 [1] => Oakland [teamcity] => Oakland [2] => Raiders [teamname] => Raiders ) [31] => Array ( => 32 [teamid] => 32 [1] => San Diego [teamcity] => San Diego [2] => Chargers [teamname] => Chargers ) ) Can anyone help me figure this out? i've been trying for hours (I know, that's pathetic ) I have whiled my way through any number of forums and help pages so far. However, since I am not quite comfortable yet with PHP, I am not sure which option I have been given would be the right one. What I am trying to do: Create the source for a set of drop-down menus. The dropdown menu has columns, and then a H2 and P that go in each column, in varied numbers, so you have column1, h2 p; h2 p; h2 p column2, h2 p; h2 p etc....make sense? I am using an MySQL table as source so I can have a little CMS dashboard where I can change these and other values on the fly. So I have a MySQL table where I have a field that identifies the column (page name), and then values to fill the h2 and p tags. I.E.: page_name, content_title, content_text The idea, therefore, is to use PHP to figure out what the column names (that are repeated) in the mysql table and then create the dropdown based on the value in the subsidiary fields. Output is as a string in a variable value that is output via return (); My best estimation of how to do this is to use php to create a multidimensional array from the query result, where the first column is the page_name, followed by an array, the array being the remainder of the information. Based on information scrounged from other sources, I have come up with this so far: $query = "SELECT * FROM tbl_mainmenu WHERE mainmenu_type = '$mmtype'"; // what the query is $result = mysql_query ($query, $dbc); // connect to database and run query, setting the the result to dummy array variable '$result' // establish the multidimensional array $mmcontent_array = array (); //create the array where the values are content page and associated values in an array per each content page while ($result = mysql_fetch_assoc ()) { $page_name = $result['content_page']; $mmcontent_array['content_page'] = $result; } foreach ($mmContent_array[] as $key=>$value) { foreach () { $tmpelements[] = '<div class="col_2"><h2>' . $element[content_title] . "</h2>\n<p>" . $element[content_text] . "</p>\n</div>"; $elements = implode("\n",$tmpelements) . "\n" } $tmp[] = '<li><a href="#" class="drop">Products</a><!-- Begin Products Item -->\n<div class="dropdown_2columns"><!-- Begin 2 columns container -->' . $elements . 'whatever tags will close this') } Am I even in the ballpark? I am not sure which way to nest the foreach ()'s. The example I was working from used echo ()'s, and I am not sure if using $variable = implode () makes the task different. As a start, I am just wondering if I am creating the multidimensional array correctly? NOTE - Please read the information first as it contains important information to understand the problem. Rules → • There are 9 Columns(C1,C2,C3,C4,C5,C6,C7,C8,C9) [ Max columns will be 9] • The number of Rows can vary from 3,6,9,12,15,18 (Max). In this case Number of Rows shall be 12 Number of Rows = No of Tickets (Max Allowed 6) x Rows Per Ticket (Max Allowed 3). Thus, Max Rows can be 18 • Each Row is required to have 4 Blank Spaces and 5 Filled with Numbers • All numbers available in the Column Array have to be utilized • This configuration of an shall create a matrix of 9 Columns & 12 Rows (3 x 4 Tickets), which is 108 MATRIX BLOCKS where only a maximum of 60 numbers can be filled out of 108 available blocksrandomly with the above conditions being met 100%. • The numbers in column must be arranged / sorted in ASCENDING ORDER (For coding logic purpose, as soon as the number is assigned to the new MATRIX MAP use array_shift() or unset() the number so as to avoid repetition Example - Row 1 and Column 1 shall generate a MATRIX BLOCK - R1C1 Row 3 and Column 7 shall generate a MATRIX BLOCK - R3C7 Matrix Block can also be termed as Matrix Cell for your ease (if needed) MASTER SET OF ARRAY WITH NUMBERS array( "C1"=> array( 1, 2, 3, 5, 6, 7, 9 ), //7 Numbers "C2"=> array( 13, 14, 15, 17, 18, 19 ), //6 Numbers "C3"=> array( 21, 22, 23, 24, 25, 26, 30 ), //7 Numbers "C4"=> array( 31, 33, 34, 36, 37, 38, 39 ), //7 Numbers "C5"=> array( 41, 42, 46, 47, 48, 49, 50 ), //7 Numbers "C6"=> array( 51, 52, 53, 54, 55, 57, 58 ), //7 Numbers "C7"=> array( 61, 62, 64, 65, 69, 70 ), //6 Numbers "C8"=> array( 71, 74, 75, 76, 77, 78 ), //6 Numbers "C9"=> array( 82, 83, 85, 87, 88, 89, 90 ) //7 Numbers ); The above array has 60 Numbers to be filled out of 108 MATRIX BLOCK / CELL which meets the condition that for a FULL BLOCK containing 4 MINI BLOCKS WITH 3 ROWS (max. allowed) EACH I have been able to generate this without any issue meeting all the conditions of the Columns My Allocation Matrix Array will look like array( "R1"=> array( "C1"=> true, // Means that MATRIX BLOCK R1C1 will be NOT EMPTY "C2"=> false, // Means that MATRIX BLOCK R1C2 will be EMPTY "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> false ), "R2"=> array( "C1"=> false, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> true, "C8"=> true, "C9"=> false ), "R3"=> array( "C1"=> true, "C2"=> true, "C3"=> true, "C4"=> true, "C5"=> false, "C6"=> false, "C7"=> false, "C8"=> false, "C9"=> true ), "R4"=> array( "C1"=> true, "C2"=> true, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> false ), "R5"=> array( "C1"=> false, "C2"=> false, "C3"=> false, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> true, "C8"=> true, "C9"=> true ), "R6"=> array( "C1"=> true, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ), "R7"=> array( "C1"=> false, "C2"=> false, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> true ), "R8"=> array( "C1"=> true, "C2"=> false, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> true ), "R9"=> array( "C1"=> true, "C2"=> false, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ), "R10"=> array( "C1"=> false, "C2"=> true, "C3"=> true, "C4"=> true, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> false, "C9"=> false ), "R11"=> array( "C1"=> false, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> true, "C9"=> false ), "R12"=> array( "C1"=> true, "C2"=> false, "C3"=> true, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ) ); In the above array R stands for Row, C for Column, TRUE/FALSE (Boolean) means that if TRUE a Number can be filled in the resulting MATRIX BLOCK / CELL ( Row[Number]Column[Number] ) else if FALSE the MATRIX BLOCK / CELL shall be EMPTY The result for the above shall be
PROBLEM : I am unable to understand what should possibly be the logic & loop used here for creating a MATRIX ALLOCATION MAP as shown above I have tried while, foreach & for but unable determine the perfect combination which would meet the conditions. (Tried all of the above with Nested Loops also) Edited May 1, 2020 by AlphaMikeTags hi i am trying to make a payroll calculator script that takes employee info, calculates pay, displays submitted info in a table, stores info in an array, and updates the array when new info is submitted. i have most of these accomplished, i am having trouble with the "store into an array, and update the array when new info is submitted" parts of the project. i am still not very fluent in php so there may be easier ways to achieve what i have so far. any pointers would be a great help, this part has got me stumped. I am having some problems getting a query correct. Basically I have two tables, one with listings and another with categories. In the listings table I have a column called shortdescription. I am trying to pull the shortdescription from the listings table with the query $shortdesc = array_shift(mysql_fetch_row(mysql_query("select shortdescription from links where category = '".$scat->id."' "))); The shortdecription display properly on the pages display the listings, however I am getting the following error on any pages that only display the parent categories Warning: array_shift() [function.array-shift]: The argument should be an array in /home/...path/file.php on line 1462 The listings id numbers begin at 75+ because the initial parent category id ends at 74. The query seems to be searching for listing ids below 75 and spitting out an error because it is not finding them. Any ideas on how to eliminate this error and/or stop the query from looking for non-existant data? |