PHP - Looping Through Array And Printing Html Blocks
Hi all, I'm trying to set up a situation where a function loops through a multidimensional array and echos an html block for each item in the $skus['skunum'] array and also increments $i each time . ( Each is a product on the site)
The catch is that I'm trying to have a function within that one that goes through the $skus['sizes'] and echoes an option if the substring (shirt size) exists. The idea being that I can manage products by adding 4 elements, Skunum, name, price and size. And well, I'm failing miserably. At this point it won't even work because of the variable scope, I'm getting Notice: Undefined variable: skus from the functions, but am not sure of the right way to get that information. Am I going about doing this entirely wrong or am I on the right track? Code: [Select] <?php $BANDNAME="Apocalypse"; $BANDCAPS="APOCALYPSE"; $BANDLOWER="apocalypse"; $SKUCAPS="FGD"; $skus = array ( "skunum"=>array ( "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112" ), "name"=>array ( "RIDDICK /TSHIRT", "MAFIA / TSHIRT", "ORACLES / TSHIRT", "AGONY / TSHIRT", "BLOODY VIOLINIST / TSHIRT", "THE VIOLATION / TSHIRT", "AGONY-TOUR DATES / TSHIRT", "BAND PHOTO / TSHIRT", "SILVER AGONY LOGO / TSHIRT", "PHOENIX-TOUR DATES / TSHIRT", "PHOENIX / TSHIRT", "BLOODY VIOLINIST / ZIP HOOD" ), "price"=>array ( "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "42.95" ), "sizes"=>array ( "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X" ) ); function makeProducts() { //Products Sizes $sizes = $skus['sizes'][$i]; $S="S";$M="M";$L="L";$XL="1";$XXL="2";$XXXL="3";$XXXXL="4"; $small = strpos($sizes,$S); $medium = strpos($sizes,$M); $large = strpos($sizes,$L); $xlarge = strpos($sizes,$XL); $xxlarge = strpos($sizes,$XXL); $xxxlarge = strpos($sizes,$XXXL); $xxxxlarge = strpos($sizes,$XXXXL); function sizeOptions () { if($small === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'S">S</OPTION>'; } if($medium === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'M">M</OPTION>'; } if($large === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'L">L</OPTION>'; } if($xlarge === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'X">XL</OPTION>'; } if($xxlarge === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'XX">XXL</OPTION>'; } if($xxxlarge === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'XXX">XXXL</OPTION>'; } if($xxxxxlarge === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'XXXX">XXXXL</OPTION>'; } } foreach ( $skus['skunum'] as $value){ echo '<!-- PRODUCT BEGIN --> <li class="product" > <a href="product_files/large/'.$SKUCAPS.$skus['skunum'][$i].'jpg" rel="lightbox"><img src="product_files/'.$SKUCAPS.$skus['skunum'][$i].'.png"></a><br> <strong>'.$skus['name'][$i].'</strong><br>('.$SKUCAPS.$skus['skunum'][$i].')<br>$'.$skus['price'][$i].'<br> <form name="'.$SKUCAPS.$skus['skunum'][$i].'" method="GET" target="_blank" action="http://www.jsrdirect.com/cgi-bin/Make-a-Store.cgi"> <input type="hidden" name="band" value="'.$BANDCAPS.'"> <input type="hidden" name="back" value="http://www.jsrdirect.com/bands/'.$BANDLOWER.'/index.html"> <strong>Qty:</strong> <input type="text" name="quantity" size="1" value="1" > <strong>Size:</strong> <SELECT name="item">' .sizeOptions(); '</SELECT> <br><br> <input type="image" src="images/addtocart.png" value="Add To Cart"> </form> </li> <!-- Product End -->'; } } // End Function ?> Similar TutorialsHello all. How would I loop through this array and find each "DTM" value? I want to be able to loop thru this array so that I can determine when to add 123, 456, ... 789, 1012 ... 123, 456 to a database. Hope this makes some sense... Thanks for any help on this one. Code: [Select] <?php $aryValues = array('DTM', '123', '456', 'DTM', '789', '1012', 'DTM', '123', '456'); ?> I have a array as follows and I want to look by key where the key is 'ABCD', 'EFGH', etc.. I am using foreach but it is not working. How can I accomplish this? Code: [Select] Array ( [0] => Array ( [ABCD] => Array ( [venue_id] => 1003 [has_dining] => X [table_count] => 0 [serves_alcohol] => X ) ) [1] => Array ( [EFGH] => Array ( [venue_id] => 1003 [has_dining] => X [table_count] => 0 [serves_alcohol] => X ) ) ) <?php $_SESSION["cart_item"] = array( 'cart_item' => array( 'id' => $id, 'product_name' => $product_name )); } $cart_items = $_SESSION["cart_item"]; foreach ($cart_items as $cart_item) { echo $cart_item["id"] . $cart_item["product_name"]; } ?>
I have tried several variations of the foreach loop like the one above and I mostly get the error message: Notice: Array to string conversion. When I use: I get the following output: array(1) { ["cart_item"]=> array(2) { ["id"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) "3" } ["product_name"]=> array(2) { [0]=> string(19) "Adult Female Bike" [1]=> string(18) "Kids Unisex Bike" } } } Hi all,
I have a looping error in my PHP.
I am trying to add use a while statement to gather the users first and last name in to a string, add them to an array called $friendname, then check that the $friendname[] is only output/echoed once.
At the moment the code looks good to me but with multiple rows with the same name associated, the name is echoed the same amount of times as rows, instead of once as it is supposed to be.
Any ideas anyone?
while($row2 = mysqli_fetch_assoc($result2)) { $friendcode = $row2['Code']; $names = "SELECT FirstName, LastName from users WHERE Code = '$friendcode' AND Code != '$crewcode'"; $resultnames = mysqli_query($cxn,$names) or die ("Can't get friends names."); while($rownames = mysqli_fetch_assoc($resultnames)) { $friendname = array(); $newfriendname = ($rownames['FirstName'].' '.$rownames['LastName']); if (!in_array($newfriendname, $friendname)) { array_push($friendname, "$newfriendname"); echo $newfriendname; } } } I've got a data array that looks like this: $arraylist = ('00101001','10001010','00010100','01100101'); And another that looks like this: $arrayposition = (0,3); The idea is to loop through $arraylist and when the loop gets to the indexes/positions listed in the $arrayposition array, to change all of the 1's to 0's, then put the values back into a string variable. I have something like this at the moment: $chores = 1; $arraylist_new = ''; foreach ($arrayposition as $value) { if ($chores != '') { $oldvalnum = 0; foreach($arraylist as $string) { if ($value == $oldvalnum) { $string = str_replace("1", "0", $string); if ($arraylist_new == '') {$arraylist_new = $string;} else {$arraylist_new .= ', ' . $string;} } else { if ($arraylist_new == '') {$arraylist_new = $string;} else {$arraylist_new .= ', ' . $string;} } $oldvalnum++; } } } echo $arraylist_new; The idea is for the output to be: 00000000, 10001010, 00000000, 01100101. I know the code is hinda hectic, but could someone please help?? Thanks in advance! Hello, I'm taking values for various cities/areas my members live in. One member can be placed in many cities and on registering they are required to input one city but are allowed to enter a maximum of 6 cities. So, from my posted form I have; //member ID (numeric) $MemID; $City=$_Post['City']; $City2=$_Post['City2']; $City3=$_Post['City3']; $City4=$_Post['City4']; $City5=$_Post['City5']; $City6=$_Post['City6']; Where $City must be set, but any of the other $City'x' may or may not be empty. There are two tables, 1) Cities (CityID,City) 2) Mem-Cities (MemID,CityID). I have some SQL statements which check if the city exists and if it doesn't inserts it. Then adds the $MemID to that $CityID. The way im doing this now is not very efficient like this; if(!empty($City)) { $sql="SELECT COUNT(City) AS Count FROM Cities WHERE City='$City'"; $query=mysql_query($sql); $row=mysql_fetch_array($query); if($row['Count'] == 0) { $insert="INSERT INTO Cities (City) VALUES ('$City')"; mysql_query($insert) OR die('<h1>There was an error adding into Cities</h1>' .mysql_error()); //inserting additional City } $insert="INSERT INTO Mem-Cities (MemID,CityID) SELECT '$MemID',CityID FROM Cities WHERE City='$City' LIMIT 1"; mysql_query($insert) OR die('<h1>There was an adding additional City Cities to members</h1>' .mysql_error()); //inserting additional city into Cities to Members } And repeating the code above for each city. How can I loop through each city and optimise this code? Steps 1) if $City'x' is not empty and doesn't exist in DB insert it 2) add the $MemID to that CityID Thanks! hello freaks,
I have a four-element array, which is the result of a mysql query. The array is like below. (This is of course just a snippet to show the structure; the hours of course go up to 24, then repeat; there are about ten days' worth of data.)
Array ( [dayname] => day1 [hour] => 1 [widtype] => type1 [Output] => 20 ) Array ( [dayname] => day1 [hour] => 2 [widtype] => type1 [Output] => 9 ) Array ( [dayname] => day1 [hour] => 1 [widtype] => type2 [Output] => 450 ) Array ( [dayname] => day1 [hour] => 2 [widtype] => type2 [Output] => 650 ) I want to loop through this data and output each hour's data in a separate line, like below (I included the headings just for clarity): Day Hour Type1_total Type2_total day1 1 20 450 day1 2 9 650 ... and can't seem to make this happen. Here's the code I've written: $prevday = ''; while ( $row = mysql_fetch_assoc($result)) { extract($row); $currentday = $row['dayname']; $currenthour = $row['hour']; $currentwid = $row['widtype']; while($currentday !== $prevday){ for($currenthour = 1; $currenthour <=24; $currenthour++){ if($row['widtype'] == 'type1'){ $type1_total = $row['Output'];} if($row['fuel'] == 'type2'){$type2_total = $row['Output'];} print "<pre>"; echo "$currentday, $currenthour, $type1_total, $type2_total"; print "</pre>"; } $prevday = $currentday; } }... and here's what it outputs: day1, 1, 20, , day1, 2, 20, , Clearly I have written this loop wrong but have banged my head against it for a while and wonder if it's just not possible to do what I want. Any suggestions would be hugely appreciated! Here is my code...
<?php $to = "email@email.com"; //obviously not real $from = "noreply@domain.com"; //obviously not real $firstName = $_REQUEST['firstName']; $headers = "From: $from"; $subject = "Product Sheet Request"; /* $fields = array(); $fields{"firstName"} = "firstName"; $fields{"lastName"} = "lastName"; $fields{"email"} = "email"; $fields{"phone"} = "phone"; $fields{"affiliation"} = "affiliation"; $fields{"interest"} = "interest"; $fields{"productSheets"} = "productSheets"; $fields{"referredBy"} = "referredBy"; $fields{"additional"} = "additional"; */ $firstName = $_REQUEST['firstName']; $lastName = $_REQUEST['lastName']; $email = $_REQUEST['email']; $phone = $_REQUEST['phone']; $affiliation = $_REQUEST['affiliation']; $interest = $_REQUEST['interest']; if($interest == 'inclusion'){ $interest = 'Evaluating for inclusion in product'; } elseif($interest == 'general'){ $interest = 'Interested in the technology generally'; } elseif($interest == 'research'){ $interest = 'Performing market research'; } elseif($interest == 'solutions'){ $interest = 'Looking for competitive solutions'; } $referredBy = $_REQUEST['referredBy']; $additional = $_REQUEST['additional']; $productSheets[] = $_REQUEST['productSheets']; $sheets = print_r($productSheets); /* $body = "A user has requested product sheet(s). Please review their information and respond:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } */ $body = "A user has requested product sheet(s). Please review their information and respond:\n First Name: ".$firstName."\r Last Name: ".$lastName."\r Email: ".$email."\r Phone Number: ".$phone."\r Affiliation: ".$affiliation."\r Reason for Interest: ".$interest."\r Referred By: ".$referredBy."\r Additional Questions/Comments: ".$additional."\r Product Sheet(s) Requested: ".$sheets."\n "; $send = mail($to, $subject, $body, $headers); ?>I'm not quite sure how to display the values of the $productSheets array in the email message. Everytime it either outputs "Array" or "1". The $productSheets array is from a checkbox on a form. Everything else is working as expected. Hello all.. This one's sort of difficult to explain, but yet it should be a pretty simple solution.. What I'm trying to do is loop through an array that has either single event id's or a group of event id's, and run a condition on the change of id's while looping.. Sort of grouping each set if unique id's within a new event section.. Here's sort of a test code I put together: Code: [Select] <?php $result = array( array('event_id' => 70), array('event_id' => 70), array('event_id' => 70), array('event_id' => 95), array('event_id' => 96), array('event_id' => 97), array('event_id' => 98), array('event_id' => 99), array('event_id' => 145), array('event_id' => 145), array('event_id' => 145), array('event_id' => 145), array('event_id' => 166), array('event_id' => 166), array('event_id' => 177), array('event_id' => 200), array('event_id' => 200), array('event_id' => 200) ); $previous_id = ''; foreach($result as $row){ if ($row['event_id'] != $previous_id) { echo '<div style="background:#ccc;">New Event</div>'; } if ($previous_id > 0 && $row['event_id'] != $previous_id) { echo '<table border="1"><tr><td>'.$row['event_id'].'</td></tr></table>'; $previous_id = ''; } else { echo $row['event_id'].'<br />'; $previous_id = $row['event_id']; } } ?> It's about half way working, but there are issues when the ids change and they are either single event ids in a row, or multiple same event ids in a row.. I can't think how to set the $previous_id variable properly on each loop.. Well, figured I'd throw it out there and see what happens.. Thanks.. Hi everyone, I am very new to PHP and trying to learn so please bear with me. I have a simple form which passes fields to a PHP script: <form method="post" action="cartaction.php"> <p> <input type="submit" name="submit" value="Buy" /> <input type="hidden" name="cartaction" value="add" /> <input type="hidden" name="item" value="steelcasserole" /> </p> </form> I am trying to produce a shopping cart type page which will display the item(s) purchased. The problem is I have more than one submit button on the page for different products but with the same fields. I have tried to create the cartaction.php script to save the information from the form in a session variable which will allow me to output the item(s) purchased into this page prior to sending everything to a checkout page. I can get the information to appear for a single item but the problem is I want to output the details for each product added to the cart. At the moment, when I go back to the products page and try to add a new item to the shopping cart it just replaces the previous item that was there rather than retaining it and adding a new item underneath. I realise its probably really obvious but I am really new to this and getting myself confused! Any help on how to add an item then be able to go back to the products page (with the submit buttons for each product) and add a new item underneath the existing item in the shopping cart would be much appreciated! The code I have so far is: $submit = $_POST["submit"]; //If form is submitted, call the function and save all data into the array $_SESSION['form'] if($submit = "Buy"){setSessionVars();} function setSessionVars() { foreach($_POST as $fieldname => $fieldvalue) { $_SESSION['form'][$fieldname] = $fieldvalue; } echo "<table> <tr> <td>" .'<img src="images/'.$_SESSION['form']['item'].'.jpg"' . "<td/> <td>" . $_SESSION['form']['item'] . "</td> <td>" . '<input type="text(30)" name="value" value="1" /> <input type="submit" name="puchasednum" value="Update This One Item" />' . "</td> </tr> </table>"; }; ?> I have the session_start() function at the very top of every page. I have also attached the entire files for the two pages I talk about above. Thanks Graham Hi there, I have the following PHP code: <?php $books = array( array("title"=>"Book Title 1", "author"=>"Author 1", "publisher"=>"Publisher 1"), array("title"=>"Book Title 2", "author"=>"Author 2", "publisher"=>"Publisher 2"), array("title"=>"Book Title 3", "author"=>"Author 3", "publisher"=>"Publisher 3"), ); foreach ($books as $key => $value) { echo "$key : $value<br>"; } ?> I'm trying to loop through this code, but all it outputs is: 0: ARRAY 1: ARRAY 2: ARRAY -- It's not even pulling the proper $keys and $values. It works when there's just ONE array -- but not with this multidimensional array. Any ideas? Thanks! J Hi. I have the fokllowing xml response from an API and I am wanting to loop through the array(s) and get informaton for each of the rows below. For example I want to get the cells below for Consulting Income / 98e83040-fa3a-4185-9b9b-a49241e2bb76/150.32 then get each of the other items in the array. So the second iitem I want is Contract Income / 7d05a53d-613d-4eb2-a2fc-dcb6adb80b80 / 11748.96 and so on for each of the results returned
I am having a mental block about best way to get this information. Please advise best approach.
<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Id>20f0b472-a63d-4c1f-a8de-d0fc4e860983</Id> <Status>OK</Status> <ProviderName>Xero API Previewer</ProviderName> <DateTimeUTC>2020-10-12T21:34:33.5492839Z</DateTimeUTC> <Reports> <Report> <ReportID>ProfitAndLoss</ReportID> <ReportName>Profit and Loss</ReportName> <ReportType>ProfitAndLoss</ReportType> <ReportTitles> <ReportTitle>Profit & Loss</ReportTitle> <ReportTitle>Demo Company (NZ)</ReportTitle> <ReportTitle>1 October 2020 to 31 October 2020</ReportTitle> </ReportTitles> <ReportDate>12 October 2020</ReportDate> <UpdatedDateUTC>2020-10-12T21:34:33.5492839Z</UpdatedDateUTC> <Rows> <Row> <RowType>Header</RowType> <Cells> <Cell /> <Cell> <Value>31 Oct 20</Value> </Cell> </Cells> </Row> <Row> <RowType>Section</RowType> <Title>Income</Title> <Rows> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Consulting Income</Value> <Attributes> <Attribute> <Value>98e83040-fa3a-4185-9b9b-a49241e2bb76</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>150.32</Value> <Attributes> <Attribute> <Value>98e83040-fa3a-4185-9b9b-a49241e2bb76</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Contract Income</Value> <Attributes> <Attribute> <Value>7d05a53d-613d-4eb2-a2fc-dcb6adb80b80</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>11748.96</Value> <Attributes> <Attribute> <Value>7d05a53d-613d-4eb2-a2fc-dcb6adb80b80</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Engineering Income</Value> <Attributes> <Attribute> <Value>225d8c93-251d-4a0b-9093-201acf69fe50</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>7217.29</Value> <Attributes> <Attribute> <Value>225d8c93-251d-4a0b-9093-201acf69fe50</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Equipment Income</Value> <Attributes> <Attribute> <Value>43f518a6-558f-402a-b22d-317bd64b1566</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>7377.17</Value> <Attributes> <Attribute> <Value>43f518a6-558f-402a-b22d-317bd64b1566</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Licence Income</Value> <Attributes> <Attribute> <Value>1ff30343-7bb2-4402-bb8f-a0813a7fb59e</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>3047.68</Value> <Attributes> <Attribute> <Value>1ff30343-7bb2-4402-bb8f-a0813a7fb59e</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Other Income</Value> <Attributes> <Attribute> <Value>b447935a-4b37-4f38-a841-fb3ae3b491e0</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>331.06</Value> <Attributes> <Attribute> <Value>b447935a-4b37-4f38-a841-fb3ae3b491e0</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>SummaryRow</RowType> <Cells> <Cell> <Value>Total Income</Value> </Cell> <Cell> <Value>29872.48</Value> </Cell> </Cells> </Row> </Rows> </Row> <Row> <RowType>Section</RowType> <Title>Less Cost of Sales</Title> <Rows> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Other Direct Costs</Value> <Attributes> <Attribute> <Value>9e77a829-37ea-4976-a9a8-d754e0e62f44</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>333.72</Value> <Attributes> <Attribute> <Value>9e77a829-37ea-4976-a9a8-d754e0e62f44</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>SummaryRow</RowType> <Cells> <Cell> <Value>Total Cost of Sales</Value> </Cell> <Cell> <Value>333.72</Value> </Cell> </Cells> </Row> </Rows> </Row> <Row> <RowType>Section</RowType> <Rows> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Gross Profit</Value> </Cell> <Cell> <Value>29538.76</Value> </Cell> </Cells> </Row> </Rows> </Row> <Row> <RowType>Section</RowType> <Title>Less Operating Expenses</Title> <Rows> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Accounting</Value> <Attributes> <Attribute> <Value>5e312344-4123-4cac-bb69-ad2d72d2280b</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>60.00</Value> <Attributes> <Attribute> <Value>5e312344-4123-4cac-bb69-ad2d72d2280b</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Advertising & Promotional</Value> <Attributes> <Attribute> <Value>61835d79-5a1c-4ab3-af82-af6930b38492</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>1112.21</Value> <Attributes> <Attribute> <Value>61835d79-5a1c-4ab3-af82-af6930b38492</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Bank Fees</Value> <Attributes> <Attribute> <Value>19828003-cea7-4920-b0fa-9223a2cdb0dc</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>28.75</Value> <Attributes> <Attribute> <Value>19828003-cea7-4920-b0fa-9223a2cdb0dc</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Cellphones</Value> <Attributes> <Attribute> <Value>ba533632-ac64-45c8-874e-b5a5aa6829f0</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>155.00</Value> <Attributes> <Attribute> <Value>ba533632-ac64-45c8-874e-b5a5aa6829f0</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Courier</Value> <Attributes> <Attribute> <Value>b70cadef-d8aa-46e6-b128-79e2c997fd2c</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>232.02</Value> <Attributes> <Attribute> <Value>b70cadef-d8aa-46e6-b128-79e2c997fd2c</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>EFTPOS Charges</Value> <Attributes> <Attribute> <Value>a164d99b-308e-4b2e-b3b4-a0c502214c77</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>40.00</Value> <Attributes> <Attribute> <Value>a164d99b-308e-4b2e-b3b4-a0c502214c77</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Engineering Resources</Value> <Attributes> <Attribute> <Value>53fdcc86-32ee-4fcb-b053-f449405bc7a5</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>1303.31</Value> <Attributes> <Attribute> <Value>53fdcc86-32ee-4fcb-b053-f449405bc7a5</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Entertainment - Partly Deductible</Value> <Attributes> <Attribute> <Value>d27cb87b-a3d2-4275-8948-95871fec4929</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>15.00</Value> <Attributes> <Attribute> <Value>d27cb87b-a3d2-4275-8948-95871fec4929</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Equipment Costs</Value> <Attributes> <Attribute> <Value>573a170b-6792-4cfa-b8ce-6f8fd27f5458</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>13746.93</Value> <Attributes> <Attribute> <Value>573a170b-6792-4cfa-b8ce-6f8fd27f5458</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>General Expenses</Value> <Attributes> <Attribute> <Value>11f618a8-f17e-4757-8b4a-6f24841bdb93</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>323.23</Value> <Attributes> <Attribute> <Value>11f618a8-f17e-4757-8b4a-6f24841bdb93</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Insurance</Value> <Attributes> <Attribute> <Value>92c673af-b2bc-45be-a888-a7e2c4bcc7f9</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>119.00</Value> <Attributes> <Attribute> <Value>92c673af-b2bc-45be-a888-a7e2c4bcc7f9</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>KiwiSaver Employer Contributions</Value> <Attributes> <Attribute> <Value>ab57eabe-5fa8-49d4-87dc-d5e7428323af</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>519.53</Value> <Attributes> <Attribute> <Value>ab57eabe-5fa8-49d4-87dc-d5e7428323af</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Licence Costs</Value> <Attributes> <Attribute> <Value>02dbaa55-95b9-464e-999c-c68e203cd67f</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>2176.91</Value> <Attributes> <Attribute> <Value>02dbaa55-95b9-464e-999c-c68e203cd67f</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Motor Vehicle Expenses</Value> <Attributes> <Attribute> <Value>b149780d-69bc-4f7c-a3ce-bd48f7a37de5</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>619.63</Value> <Attributes> <Attribute> <Value>b149780d-69bc-4f7c-a3ce-bd48f7a37de5</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Office Consumables & Postage</Value> <Attributes> <Attribute> <Value>b1769b51-e98e-432c-9670-d5be3054b717</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>56.00</Value> <Attributes> <Attribute> <Value>b1769b51-e98e-432c-9670-d5be3054b717</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Office Expenses</Value> <Attributes> <Attribute> <Value>935e0fbe-6749-41c8-a024-11321e44dfac</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>113.23</Value> <Attributes> <Attribute> <Value>935e0fbe-6749-41c8-a024-11321e44dfac</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Payment Processing</Value> <Attributes> <Attribute> <Value>8cd42505-ad73-46e2-932f-67952fdc4e99</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>174.51</Value> <Attributes> <Attribute> <Value>8cd42505-ad73-46e2-932f-67952fdc4e99</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Rent</Value> <Attributes> <Attribute> <Value>28113b99-6df2-4123-a2d0-5f54dcf8017b</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>1935.00</Value> <Attributes> <Attribute> <Value>28113b99-6df2-4123-a2d0-5f54dcf8017b</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Salaries & Wages</Value> <Attributes> <Attribute> <Value>be2e984a-17e1-4bf7-809c-b03a69325c90</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>17317.58</Value> <Attributes> <Attribute> <Value>be2e984a-17e1-4bf7-809c-b03a69325c90</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Security</Value> <Attributes> <Attribute> <Value>c814b08e-6558-4ac4-adce-ba76848a3a9f</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>45.00</Value> <Attributes> <Attribute> <Value>c814b08e-6558-4ac4-adce-ba76848a3a9f</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Subscriptions</Value> <Attributes> <Attribute> <Value>5ba8d64a-5b98-4bfd-a35e-7d0569e3446f</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>102.96</Value> <Attributes> <Attribute> <Value>5ba8d64a-5b98-4bfd-a35e-7d0569e3446f</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Telephone & Internet</Value> <Attributes> <Attribute> <Value>230e4cfc-f4c4-4c15-aa0d-bab02b954622</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>89.95</Value> <Attributes> <Attribute> <Value>230e4cfc-f4c4-4c15-aa0d-bab02b954622</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Travel & Accommodation - National</Value> <Attributes> <Attribute> <Value>36d33c5d-7dea-4911-9ed0-7fccc16f2b5f</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>210.43</Value> <Attributes> <Attribute> <Value>36d33c5d-7dea-4911-9ed0-7fccc16f2b5f</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Utilities</Value> <Attributes> <Attribute> <Value>2e277847-022c-48f3-8467-0207230004d6</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> <Cell> <Value>348.14</Value> <Attributes> <Attribute> <Value>2e277847-022c-48f3-8467-0207230004d6</Value> <Id>account</Id> </Attribute> </Attributes> </Cell> </Cells> </Row> <Row> <RowType>SummaryRow</RowType> <Cells> <Cell> <Value>Total Operating Expenses</Value> </Cell> <Cell> <Value>40844.32</Value> </Cell> </Cells> </Row> </Rows> </Row> <Row> <RowType>Section</RowType> <Rows> <Row> <RowType>Row</RowType> <Cells> <Cell> <Value>Net Profit</Value> </Cell> <Cell> <Value>-11305.56</Value> </Cell> </Cells> </Row> </Rows> </Row> </Rows> </Report> </Reports> </Response> Edited October 13, 2020 by Barand code tags (XML) added I have an array which I contains multiple arrays, I would like to loop through and run a function on a certain key within the array I have the following code which works but I was wondering if there was a better method? $i = 0; foreach($Items as $Item) { $Items[$i]['key'] = custom_function($Item['key']); $i++; } The array $Items structure is as follows Code: [Select] array ( [0] => array ( [key] => 'blah' ) [1] => array ( [key] => 'blah' ) [2] => array ( [key] => 'blah' ) ) Hi, I'm a PHP novice and trying to print out elements of what appears to be a multi-dimensional array, but I can't figure it out. I'm able to use print_r() to dump the array. Array ( [0] => 18485 [1] => Array ( [1] => Array ( [isPublished] => 1 [dateAdded] => 2019-07-18T16:13:28+00:00 [dateModified] => 2020-01-29T18:37:45+00:00 [createdBy] => [createdByUser] => Support [modifiedBy] => [modifiedByUser] => [id] => 1 [points] => 0 [color] => [fields] => Array ( [core] => Array ( [points] => Array ( [id] => 9 [label] => Points [alias] => points [type] => number [group] => core [object] => lead [is_fixed] => 1 [default_value] => 0 [properties] => a:0:{} [value] => 0 [normalizedValue] => 0 ) [last_active] => Array ( [id] => 19 [label] => Date Last Active [alias] => last_active [type] => datetime [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => 2020-01-29 18:37:47 [normalizedValue] => 2020-01-29 18:37:47 ) [title] => Array ( [id] => 1 [label] => Title [alias] => title [type] => lookup [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:1:{s:4:"list";a:3:{i:0;s:2:"Mr";i:1;s:3:"Mrs";i:2;s:4:"Miss";}} [value] => [normalizedValue] => ) [firstname] => Array ( [id] => 2 [label] => First Name [alias] => firstname [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Andy [normalizedValue] => Andy ) [lastname] => Array ( [id] => 3 [label] => Last Name [alias] => lastname [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Towne [normalizedValue] => Towne ) [company] => Array ( [id] => 4 [label] => Primary company [alias] => company [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [position] => Array ( [id] => 5 [label] => Position [alias] => position [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [email] => Array ( [id] => 6 [label] => Email [alias] => email [type] => email [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => andy.towne@example.com [normalizedValue] => andy.towne@example.com ) [phone] => Array ( [id] => 8 [label] => Phone [alias] => phone [type] => tel [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [mobile] => Array ( [id] => 7 [label] => Mobile [alias] => mobile [type] => tel [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [address1] => Array ( [id] => 11 [label] => Address Line 1 [alias] => address1 [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [address2] => Array ( [id] => 12 [label] => Address Line 2 [alias] => address2 [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [city] => Array ( [id] => 13 [label] => City [alias] => city [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Boston [normalizedValue] => Boston ) [state] => Array ( [id] => 14 [label] => State [alias] => state [type] => region [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Massachusetts [normalizedValue] => Massachusetts ) [zipcode] => Array ( [id] => 15 [label] => Zip Code [alias] => zipcode [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [timezone] => Array ( [id] => 18 [label] => lead.field.timezone [alias] => timezone [type] => timezone [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => America/New_York [normalizedValue] => America/New_York ) [country] => Array ( [id] => 16 [label] => Country [alias] => country [type] => country [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => United States [normalizedValue] => United States ) [fax] => Array ( [id] => 10 [label] => Fax [alias] => fax [type] => tel [group] => core [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [preferred_locale] => Array ( [id] => 17 [label] => Preferred Locale [alias] => preferred_locale [type] => locale [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [attribution_date] => Array ( [id] => 20 [label] => Attribution Date [alias] => attribution_date [type] => datetime [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [attribution] => Array ( [id] => 21 [label] => Attribution [alias] => attribution [type] => number [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:2:{s:9:"roundmode";i:4;s:9:"precision";i:2;} [value] => [normalizedValue] => ) [website] => Array ( [id] => 22 [label] => Website [alias] => website [type] => url [group] => core [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [number_of_email_users] => Array ( [id] => 45 [label] => Number of Email Users [alias] => number_of_email_users [type] => number [group] => core [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:2:{s:9:"roundmode";s:1:"3";s:9:"precision";s:0:"";} [value] => [normalizedValue] => ) ) [social] => Array ( [facebook] => Array ( [id] => 23 [label] => Facebook [alias] => facebook [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [foursquare] => Array ( [id] => 24 [label] => Foursquare [alias] => foursquare [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [instagram] => Array ( [id] => 26 [label] => Instagram [alias] => instagram [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [linkedin] => Array ( [id] => 27 [label] => LinkedIn [alias] => linkedin [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [skype] => Array ( [id] => 28 [label] => Skype [alias] => skype [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [twitter] => Array ( [id] => 29 [label] => Twitter [alias] => twitter [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) ) [personal] => Array ( ) [professional] => Array ( ) [all] => Array ( [id] => 1 [points] => 0 [last_active] => 2020-01-29 18:37:47 [title] => [firstname] => Andy [lastname] => Towne [company] => [position] => [email] => andy.towne@example.com [phone] => [mobile] => [address1] => [address2] => [city] => Boston [state] => Massachusetts [zipcode] => [timezone] => America/New_York [country] => United States [fax] => [preferred_locale] => [attribution_date] => [attribution] => [website] => [number_of_email_users] => [facebook] => [foursquare] => [instagram] => [linkedin] => [skype] => [twitter] => ) ) [lastActive] => 2020-01-29T18:37:47+00:00 [owner] => [ipAddresses] => Array ( [0] => Array ( [ipAddress] => 104.247.39.34 [id] => 5043 [ipDetails] => Array ( [city] => Boston [region] => Massachusetts [zipcode] => [country] => United States [latitude] => 42.36 [longitude] => -71.0545 [isp] => [organization] => [timezone] => America/New_York [extra] => ) ) [1] => Array ( [ipAddress] => 74.125.210.26 [id] => 6162 [ipDetails] => Array ( [city] => Hayward [region] => California [zipcode] => [country] => United States [latitude] => 37.6736 [longitude] => -122.0944 [isp] => [organization] => [timezone] => America/Los_Angeles [extra] => ) ) [2] => Array ( [ipAddress] => 73.126.166.11 [id] => 3069 [ipDetails] => Array ( [city] => Everett [region] => Massachusetts [zipcode] => [country] => United States [latitude] => 42.415 [longitude] => -71.0527 [isp] => [organization] => [timezone] => America/New_York [extra] => ) ) ) [tags] => Array ( ) [utmtags] => Array ( ) [stage] => [dateIdentified] => 2019-07-18T16:13:28+00:00 [preferredProfileImage] => gravatar [doNotContact] => Array ( ) [frequencyRules] => Array ( ) ) ) ) This output was produced using print_r($array);
I'm trying to access our contacts using the vendor's PHP API, but I'm not much of a PHP programmer. The array is stored in $contacts, using the vendor's getList() function. I believe I'm able to download the whole list of contacts in an array, but I can't iterate through it. I'd like to print out the elements of the array in CSV format.
$contacts = $contactApi->getList($searchFilter, $start, $limit, $orderBy, $orderByDir, $publishedOnly, $minimal); I've also tried something like this:
foreach ($contacts as $contact) {
-First I want to say that I love this site and always check google before I submit questions but im lost. I'm into security and trying to learn a little Apache, Mysql, and PHP to understand the development cycle better. As practice im creating a notecard test review site. Create notecard Decks, add/delete questions etc. shuffle, then test yourself. I though I was doing good until I got to the page that shows the questions (test.php). Right now I pass the "deck_id" field in a GET to a "test.php?id=" page that runs a script that pulls out all the questions for that deck from my "questions" table and loops to show each question for that "deck". My loop works, (gets array from database and shows questions one by one), but it writes all the questions to the page at the same time. DUH. I want it to show one question with a "NEXT" button to show next question. This button clears the first question and writes the next one until they are all done. No grading or anything needed. Is there a way to do this gracefully? I dont know much javascript but looked up innerHTML and see i can update text that way but the PHP loop I have goes so fast it just end up showing the last question with no way to pause it between questions. Can anyone think of a way to do this? My problem is passing the data from page to page to page (I lose the array data) If this is impossible my other thoughts a 1) store current list of Q/A's in cookie (OR) 2) pass Q/A to another page with POSTS (OR) 3)store Q/A's to temporary sql table and use GETS in loop to show each one by one. "testing.php?question=1" 4) can i set a global variable that can pass the data to separate pages? 5)user iFrame so it looks like one page (dont know how) Im leaning to number 3 but want to hear your suggestions. (sorry very new) <?php $menu = array( '22' => array ( 'title'=>'Businesses' ,'busstype'=>array( 5=>'Printers' ,2=>'Bookshops' ,6=>'Publishers' ,8=>'Uniform Distributors' ) ) ,21 => array ( 'title'=>'Academic' ,'busstype'=>array ( 5=>'Academy' ,6=>'Primary' ,7=>'Polytechnic' ,11=>'University' ) ) ,'Events' => array ( 'title'=>'Events' ,'busstype'=>array ( 3=>'Music' ,4=>'Road shows' ,6=>'Sports' ,6=>'Yoga' ) ) ) ; I have a dynamically created menu as above. How would i sort on the 'busstype' homogenously and print it while maintaing the key. Results should be like <a href="search.php?listing=21&busstype=5">Academy</a> <a href="search.php?listing=22&busstype=2">Bookshops</a> ....... <a href="search.php?listing=Events&busstype=6">Yoga</a> ?> Hello, i retrieve an array from the database that looks something like this: $var=a:1:{s:2:"cc";a:1:{i:22;s:11:"TESTING";}}; I need to retrieve the number corresponding to the character i: and print it(11 in the first case). For example , If, $var=a:1:{s:2:"cc";a:1:{i:15;s:11:"TESTING";}}; I would need to print 15. $var=a:1:{s:2:"cc";a:1:{i:3;s:11:"TESTING";}}; I would need to print 3. Thanks in advance. I'm pulling a list of topics from my DB and they are structured hierarchally using the typical id | parent_id scheme The array I end up with from the DB is one large one with keys representing the unique id of each data result...The problem is getting past the 2d scope of the array. I know this will require a recursive function and I've been at it for hours but can't seem to wrap my hurting head around it! How do I get my orignal array in this form: Array ( [0] => Array ( [1] => top parent [2] => top parent [3] => top parent [9] => top parent ) [2] => Array ( [4] => #1 child of 2 [5] => #2 child of 2 ) [3] => Array ( [6] => #1 child of 3 ) [4] => Array ( [7] => #1 child(subsub) of 4 [8] => #2 child(subsub) of 4 ) ) To look something more like this? : Array ( [1] => top parent [2] => Array ( [4] => Array ( [7] => #1 child(subsub) of 4 [8] => #2 child(subsub) of 4 ) [5] => #2 child of 2 ) [3] => Array ( [6] => #1 child of 3 ) [9] => top parent ) notice how the 2nd array has all the proper dimensions according the the DB hierarchy. Thank you ps. or maybe I should work from a different array to start from...I'm open to suggestions Hello, I just wanted to run over some code i'm using to loop through for a page. And wanted people critique on it really. It is a bit messy i feel trying to include all the html tags inside the loop in order for me to achieve the page look i want and whilst maintaining to xhtml standards. Would any one please take a look at my code which works and tell me how they would do it or if its done badly as i'm interested to know $q = "SELECT title, content, get, link FROM content WHERE page='index'"; $r = mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<h2>'; // print for start of H-tag echo $row['title']; // print title inside H-tag echo '</h2><p>'; // close H-tag, line break, start of P-tag $get = $row['get']; $link = $row['link']; $content = $row['content']; $content = explode(' ', $content); $y = 90; $x = 0; while ($x < $y) { echo $content[$x].' '; // print content inside P-tag $x++; } // end of content echo '</p><a href="seo.php?x='; // close P-tag, start A-Tag print link echo "$get"; // $_GET[''] echo '">read more...&#187;&#187;</a>'; // close url start the anchor text and close off </a> } // End of while echo '</div>'; // End of left content echo '<div class="right">'; // Start of right div echo '<h2>News</h2>'; // News title I'd appreciate any feed back from more experienced users/coders Thank you in advance :-) |