PHP - Nested Subcategory
Similar TutorialsHello: I would like to create a little CMS that will allow me to create a new Category (a State - one text field), then a Subcategory (A Town - one text field) that can be assigned to a State, and then a Menu Item (With a few text fields, a textarea, and a photo upload) that can be assigned to a Town. I have made these before with old ASP code but want to start develpoing this in PHP. I believe I found a demo of a Product Catalog online and worked from there. Can someone put me in the right direction? Or show me where I can fine a sample of this. I want to make it so it can be modified or deleted, if needed, but not to delete something if it's assigned to something (like not being able to delete a SubCategory if there are 3 Menu Items assigned to it). I would appreciate any help or direction. Thanks! I do have a sql table named "module" and a parent module may have a sub module. Each parent module can have a maximum of 9 sub modules of three per <td>. This is how this "module" table looks like: +-----------+------------------+----------+------+--------+---------------------+ | module_id | name | page_url | icon | parent | created_date | +-----------+------------------+----------+------+--------+---------------------+ | 1 | User Modules | | NULL | NULL | 2021-07-21 11:46:16 | | 2 | Items | | NULL | 1 | 2021-07-21 11:46:16 | | 3 | Add New Item | | NULL | 2 | 2021-07-21 11:46:16 | | 4 | View Item | | NULL | 2 | 2021-07-21 11:46:16 | | 5 | Category | | NULL | 2 | 2021-07-21 11:46:16 | | 6 | Brand | | NULL | 2 | 2021-07-21 11:46:16 | | 7 | Unit | | NULL | 2 | 2021-07-21 11:46:16 | | 8 | Purchase | | NULL | 1 | 2021-07-21 11:46:16 | | 9 | Add New Purchase | | NULL | 8 | 2021-07-21 11:46:16 | | 10 | view Purchase | | NULL | 8 | 2021-07-21 11:46:16 | | 11 | Due Invoice | | NULL | 8 | 2021-07-21 11:46:16 | | 12 | Return | | NULL | 8 | 2021-07-21 11:46:16 | | 13 | Purchase Log | | NULL | 8 | 2021-07-21 11:46:16 | | 14 | Inventory | | NULL | 1 | 2021-07-21 11:46:16 | | 15 | Stock Transfer | | NULL | 14 | 2021-07-21 11:46:16 | | 16 | Stock Adjustment | | NULL | 14 | 2021-07-21 11:46:16 | | 17 | Batch Control | | NULL | 14 | 2021-07-21 11:46:16 | | 18 | Stock Take | | NULL | 14 | 2021-07-21 11:46:16 | +-----------+------------------+----------+------+--------+---------------------+ My desired HTML table layout looks somthing similar to this attach image.
I would like to know how we can do it in php, if is possible. Thank you. Edited July 23 by thara Hi, I use this code (found in post http://www.phpfreaks.com/forums/index.php?topic=205633.0) to create a tree structure of categories and subgategories. Code: [Select] $prevcat = ''; $prevsubcat = ''; $sql = "SELECT * FROM $tbl_name ORDER BY categ, subcateg"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); while($row = mysql_fetch_assoc($result)) { $cat = $row['categ']; $subcat = $row['subcateg']; $item = $row['itemname']; $description = $row['itemdesc']; if($cat != $prevcat){ echo $cat.'<br />'; echo 'sc '. $subcat.'<br />';//if the category has changed, we also want to show the new subcat }elseif($subcat != $prevsubcat){ echo $subcat.'<br />'; } echo 'it '.$item.'<br />'; echo 'desc '.$description.'<br />'; $prevcat = $cat; $prevsubcat = $subcat; } The above code works fine but I am trying to figure out how to count results of the deepest subcategory, so I will be able to change cell color or have results presented in two colums (left and right). Example: - main category 1 -- subcategory under category 1 ------ result 1 ------ result 2 ------ result 3 - main category 2 -- subcategory under category 2 ------ result 1 ------ result 2 - main category 3 -- subcategory under category 3 ------ result 1 ------ result 2 ------ result 3 ------ result 4 etc I want to count results under each subcategory, so on the above example I should have: 3 results for category 1 2 results for category 2 4 results for category 3 Any suggestions? Thank you. im stuck on this section of code atm its failing on the line "or die(mysql_error());" i think its the $table ifs. ive tryed "" around the query but i get other errors then <?php if ($_GET['make'] == ''){ //no input //all if ($_GET['make'] == 'all'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments like '{$_GET['make']}'"); //pass if ($_GET['make'] == 'pass'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments like '{$_GET['make']}'"); //not pass if ($_GET['make'] == 'notpass'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments not like '{$_GET['make']}'"); }else{ //by make $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments not like '{$_GET['make']}'"); } } } } ?> <div id="right"> <?php echo "$table"; or die(mysql_error()); $result=mysql_query($sql); ?> i have been trying to make this work for days, this needs to also include a discount for staying over >=5 days in Tokyo, no matter what i do i always gets syntax error this class is making me crazy how do i go about getting the discount in this????? please help <?php $destination = $_POST['destination']; $numTravelers = $_POST['numTravelers']; $numNights = $_POST['numNights']; $airFare = $_POST['airFare']; $hotel = $_POST['hotel']; if ($destination == Barcelona) {$airFare = 875.00; $perNight = 85.00;} elseif ($destination == Cairo) {$airFare= 950.00; $perNight = 98.00;} elseif ($destination == Rome) {$airFare = 875.00; $perNight = 110.00;} elseif ($destination == Santiago) {$airFare = 820.00; $perNight = 85.00;} elseif ($destination == Tokyo) {$airFare = 1575.00; $perNight = 240.00;} this is where i can not figure out how to put in the discount off the airfare for staying over five days elseif ($destination == Tokyo && $numNights >=5) $tickets = $numTravelers * $airFare; $hotel = $numTravelers * $numNights * $perNight; $totalCost = $tickets + $hotel; print("<p>Destination: $destination<br />"); print("Number of people: $numTravelers<br />"); print("Number of nights: $numNights<br />"); print("Airline Tickets: $".number_format($tickets, 2)."<br />"); print("Hotel Charges: $".number_format($hotel, 2)."</p>"); print("<p><strong>TOTAL COST: $".number_format($totalCost, 2)."</strong></p>"); ?> Hi Guys, One of my API providers has recently updated the way they output data in JSON to the following: { "ua":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko\/20100101 Firefox\/65.0", "type":"browser", "brand":null, "name":null, "url":"https:\/\/www.mozilla.org\/", "os":{ "name":"Windows 10", "code":"windows_10", "url":"https:\/\/en.wikipedia.org\/wiki\/Windows_10", "family":"Windows", "family_code":"windows", "family_vendor":"Microsoft Corporation.", "icon":"https:\/\/assets.userstack.com\/icon\/os\/windows10.png", "icon_large":"https:\/\/assets.userstack.com\/icon\/os\/windows10_big.png" }, "device":{ "is_mobile_device":false, "type":"desktop", "brand":null, "brand_code":null, "brand_url":null, "name":null }, "browser":{ "name":"Firefox", "version":"65.0", "version_major":"65", "engine":"Gecko" }, "crawler":{ "is_crawler":false, "category":null, "last_seen":null } } Previous the JSON data was not nested which means i now need to update my code to grab the values, I cant work out how to grab nested values, below is my code working off the old JSON output. How do i go about grabbing the data now with the new format? $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "URL-REMOVED"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); $http = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $apiresult = json_decode($result); foreach($apiresult as $result) { $ua_type = $result->ua_type; $os_name = $result->os_name; $os_version = $result->os_version; $browser_name = $result->browser_name; $browser_version = $result->browser_version; $ua_brand = $result->ua_brand; $ua_name = $result->ua_name; }
I'm a bit confused here on for loops. I don't quite understand why this script outputs what it does and I'd like it if someone could explain it to me. Code: (php) [Select] <?php for ($i = 1; $i < 3; $i = $i + 1) { for ($j = 1; $j < 3; $j = $j + 1) { echo "'i' is {$i}, 'j' is {$j}<br />"; } } ?> Result: Code: [Select] 'i' is 1, 'j' is 1 'i' is 1, 'j' is 2 'i' is 2, 'j' is 1 'i' is 2, 'j' is 2 I have a nested array. I'm trying to write code to produce the minimum value foreach first key of the $test array. So, ideally it would produce what's in the $result array. I don't know why i can't figure out how to do this. The multiple nests are throwing me off. I think i'm over thinking this. Code: [Select] <?php $test['abcd']['0'] = array('10','100','300'); $test['abcd']['1'] = array('1000','100','3000'); $test['abcd']['3'] = array('23','89','700'); $test['efgh']['0'] = array('3','55','300'); $test['efgh']['1'] = array('160','160','9000'); $test['efgh']['3'] = array('900','89','200'); //$result['abcd'] = 10; //$result['efgh'] = 3; ?> while($comp = mysql_fetch_assoc($company)) { echo "company name: $comp['name'] <br>"; $c = mysql_fetch_assoc(mysql_query("SELECT * FROM comp_images WHERE company='". $comp['name'] ."'")); echo $c; } When I use that, it only echos one image URL, none others. Hi guys and Marry Christmas to all of you who are celebrating! I'm traying to learn PHP on my own and I am stuck in traying to understand this concept of nested loops and using break/continue in them. So, can someone please explain to me how this code below is working and why I'm getting result that I don't expect. Code is: for($i = 0; $i < 6; $i++) { for($d = 0; $d < 4; $d++) { if($d == $i) { continue 2; } echo $d."d <br>"; echo $i."i <br>"; } } When I was writing this code I was expecting that result, because of continue 2, will be 4i and 5i. But instead of that I got this 0d,1i,0d,2i,1d,2i,0d,3i,1d,3i,2d,3i,0d,4i,1d,4i,2d,4i,3d,4i,0d,5i,1d,5i,2d,5i,3d,5i. I really want to how I got this result, I spent whole day traying to explain this to myself and failed miserably.
Hello i am new here, and new to php too. I try to learn php from about 20 days, and i am getting stuck in something, somebody asked me to make a program that will produce the following output, i have to use a nested for loop: 1 22 333 4444 55555 ........etc The code for is: Code: [Select] for($a=1;$a<10;$a++) { echo "<br>"; for ($b=0;$b<$a;$b++) echo $a; }I do know this is something elementary, but really i cannot understand how it works is there any saint that will comment the code and explain step by step whats happening there? Thank you. I am trying to dynamically create a form where I pass a table name and it presents me with a table of all the columns (varying number and names of columns) into an HTML table. Both of my queries are working, but for some reason, my nested while statements are not working. Any ideas? function getLuTableBody($lu_tableName) { $tableBodyHtml =""; $tableColumns=getTableColumns($lu_tableName); $tableData=getTableData($lu_tableName); if ($tableData->num_rows > 0) { while($row = $tableData->fetch_assoc()) { if ($tableColumns->num_rows > 0) { $tableBodyHtml .= "<tr>"; while($column = $tableColumns->fetch_assoc()) { $columnName=$column['COLUMN_NAME']; $tableBodyHtml .= "<td>$row[$columnName]<td>"; } $tableBodyHtml .= "</tr>"; } else { echo "problem with column data"; } } } else { echo "problem with record data"; } return $tableBodyHtml; }
Here's the contents of the db id bundleRole recordStatus 1 Database A 2 Web A 3 Base A 4 Application A 5 Print A
<table id="advanced_table" class="table dataTable"> <thead> <tr> <th>Record ID</th> <th>Bundle Role</th> <th>Record Status</th></tr> </thead> <tbody> <tr> <td>1</td> <td></td> <td>Database</td> <td></td> <td>A</td> <td></td> </tr> </tbody> </table> Edited June 13, 2020 by pizote added detail Hi I'm wondering how I can output nested comments. I have written a viewthread.php file that works nicely so far. From index.php it gets the IDOfThread and passes this to a $number then outputs all the comments assigned to the Thread ID However I'd like to be able to respond to each comment to create nested comments This is my viewthread.php so far <!DOCTYPE html> <html> <header> <link href="styles.css" rel="stylesheet" type="text/css" media="all"> <title>test Image Board</title> <div class="header"> <a href="index.php" class="logo">test forum online</a> <div class="header-right"> <a class="active" href="#home">Home</a> <a href="#news">News</a> <a href="#contact">Education</a> <a href="#about">Tech</a> </div> </div> </header> <body> <!-- <a href="CreateThread.php"> <h1>Create Thread</h1> </a> --> <div class ='Thread-grid-container'> <?php include 'dbconnect.php'; $number = intval($_GET['id']) ; session_start(); $_SESSION['id'] = $number ; $query = mysqli_query($conn, "SELECT * FROM Threads where id=$number") or die (mysqli_error($conn)); //Output Grid layout for a Thread post while ($row = mysqli_fetch_array($query)) { //output picture from upload folder $imageURL = 'upload/'.rawurlencode($row["filename"]); echo " <div class ='Thread-grid-item'> <div class='ThreadNumber'> Post {$row['id']}<br> </div> <div class='UserOnThread'>{$row['Users']} </div> <h2>{$row['Title']} </h2> <button type='button' class ='collapse'>Hide</button> <div class ='img-block'> <img src={$row['$imageURL']}$imageURL alt='' /> </div> <div class='bodytextThread'> <p>{$row['ThreadBody']}</p> </div> </div> \n"; }?> <div class="comment-upload-box"> <form action="CommentUpload.php" method="post" enctype="multipart/form-data"> <table> <tr> <td></td> </tr> <tr> <td>Comment: </td> <td> <textarea name="CommentText" cols="100" rows="10" > Enter your posts... </textarea> </td> <td></td> </tr> <tr> <td></td> <td><input type="submit" name='submit' value="Submit"/></td> <td></td> </tr> </table> </form> </div> <div class='divTableForComments'> <div class='divTableBody'> <?php include 'dbconnect.php'; //Output Comments onto page //Create a variable for the Comment boxes so when clicking reply a text area shows $ChildCommentBoxes = "<div class='child-comment-upload-box' style='margin-left: 48px'> <form action='ChildCommentUpload.php' method='post' enctype'multipart/form-data'> <table> <tr> <td></td> </tr> <tr> <td>Comment: </td> <td> <textarea name='ChildCommentText' cols='100' rows='10' > Enter your posts... </textarea> </td> <td></td> </tr> <tr> <td></td> <td><input type='submit' name='submit' value='Submit'/></td> <td></td> </tr> </table> </form>"; $query = mysqli_query($conn, "SELECT * FROM Posts where IDOfThread=$number") or die (mysqli_error($conn)); while ($row = mysqli_fetch_array($query)) { //May need this later to output pictures // $imageURL = 'upload/'.rawurlencode($row["filename"]); $CommentText = nl2br($row['CommentText']) ; $ParentComment = "" ; $replies = "" ; if (empty($row['ParentId'])) { $ParentComment .= " <div class='divTableRow'> <div class='divTableCell'>{$row['User']} <div class='pointsincommentbox'> {$row['Upvotes']}points</div> <div class='divTableComment'> $CommentText <br> <div class='divCommentLinks'> <div class='upvotes'> ⬆</div> <div class='upvotes'> ⬇</div> <div> view comment </div> <div>report </div> <div>permalink</div> <button type='button' class ='CommentChildButton'>reply</button> <div class ='OpenChildCommentBox'> $ChildCommentBoxes </div> </div> </div> </div> </div> \n"; } echo "$ParentComment "; } ?> <div class ="sidebar"> </div> </body> </html> <script> var coll = document.getElementsByClassName("collapse"); var i; for (i = 0; i < coll.length; i++) { coll[i].addEventListener("click", function() { this.classList.toggle("active"); var content = this.nextElementSibling; if (content.style.display === "block") { content.style.display = "none"; } else { content.style.display = "block"; } }); } </script> <script> var coll2 = document.getElementsByClassName("CommentChildButton"); var i; for (i = 0; i < coll2.length; i++) { coll2[i].addEventListener("click", function() { this.classList.toggle("active"); var content = this.nextElementSibling; if (content.style.display === "block ") { content.style.display = "none"; } else { content.style.display = "block"; } }); } </script> And this is what it looks like I think I would probably change the margin of the responses to jut them in a bit and am thinking the best way would be to create a function that cycles through and where it finds a ParentId of a comment matching the Posts.id it would then put this beneath it? My comments are stored in a table titled Posts and Posts looks like
MariaDB [test]> describe Posts ; +---------------+-----------------+------+-----+---------------------+-------------------------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-----------------+------+-----+---------------------+-------------------------------+ | id | int(6) unsigned | NO | PRI | NULL | auto_increment | | User | varchar(30) | NO | | NULL | | | PostTimeStamp | timestamp | NO | | current_timestamp() | on update current_timestamp() | | CommentText | varchar(8000) | YES | | NULL | | | IDOfThread | int(11) | YES | | NULL | | | Upvotes | int(11) | NO | | 0 | | | ParentId | int(11) | YES | | NULL | | +---------------+-----------------+------+-----+---------------------+-------------------------------+ 7 rows in set (0.002 sec)
Hello everybody, I hope someone can help me. I've got a database table with subscriber info linked to various tenders. The current layout of the table is as follows (this is dummy data): Subscriber Category Email Tender Info Dummy Company 1 Advertisting email@email.com Tender 1 Dummy Company 1 Advertisting email@email.com Tender 2 Dummy Company 1 Advertisting email@email.com Tender 3 Dummy Company 1 Advertisting email@email.com Tender 4 Dummy Company 2 Marketing email2@email.com Tender 5 Dummy Company 2 Marketing email2@email.com Tender 6 What I'm trying to do, is to send Company 1 an email with the info for all 4 tenders. If I do a normal loop, it sends 4 emails, each mail having the info only for one tender. Here's my code: Code: [Select] //Select subscriber and email address, grouped to only have one entry per sub $subs = "SELECT subscriber, email FROM tenders_temp GROUP BY subscriber"; $query = mysql_query($subs); while ($subsrs = mysql_fetch_array($query)) { //Select all tenders info $tender = "SELECT * FROM tenders_temp WHERE subscriber = '".$subsrs['subscriber']."'"; $restender = mysql_query($tender); //Send email $msg = "<html><body> <table width='100%' border='0' cellspacing='0' cellpadding='10'>"; while ($rstend = mysql_fetch_array($restender)) { $msg .= " <tr> <td valign='top'><strong>SUBSCRIBER:</strong></td> <td colspan='3'>".$rstend['subscriber']."</td> </tr> <tr> <td valign='top'><strong>CATEGORY:</strong></td> <td colspan='3'>".$rstend['tender_interests']."</td> </tr> <tr> <td width='16%' valign='top'><strong>REFERENCE: </strong></td> <td width='34%'>".$rstend['reference']."</td> <td width='15%'><strong>CLOSING:</strong></td> <td width='35%'>".$rstend['closedate']." ".$rstend['closetime']."</td> </tr> <tr> <td valign='top'><strong>DESCRIPTION:</strong></td> <td colspan='3'>".$rstend['summary']." ".$rstend['description']." ".$rstend['detail']."</td> </tr> <tr> <td valign='top'><strong>CONTACT:</strong></td> <td colspan='3'>".$rstend['organization']."; ".$rstend['contact']."; Phone: ".$rstend['dial_code']." ".$rstend['telno']."; Email: ".$rstend['email']."</td> </tr> <tr> <td valign='top'><strong>DOCUMENTATION:</strong></td> <td colspan='3'>".$rstend['documentation']."</td> </tr> <tr> <td> </td> <td> </td> <td colspan='2'> </td> </tr> <tr> <td> </td> <td> </td> <td colspan='2'> </td> </tr>"; } $msg .= " </table> </body></html>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; $headers .= "From: info@tenders24.com\r\n"; $headers .= "Reply-To: info@tenders24.com\r\n"; $headers .= "Return-Path: info@tenders24.com\r\n"; $headers .= "Organization: Tenders24\r\n"; $headers .= "X-Priority: 3\r\n"; mail($subsrs['email'], "Tenders24", $msg, $headers); } Looking at this code, in theory it should work. The first query groups the entries to have one email address, then the second loop, takes each entry and loops the number of tenders inside the email. I'm getting an error with this tho. Code: [Select] Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Can anybody please help?? Thanks in advance! Karen Hi there, im trying to nest two do loops. The first loop works fine but the last loop doesnt seem to work at all. Code: [Select] <? $colname_Planet = "-1"; if (isset($_GET['recordID'])) { $colname_Planet = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_Planet = sprintf("SELECT * FROM planet WHERE PlanetName = %s", GetSQLValueString($colname_Planet, "text")); $Planet = mysql_query($query_Planet, $swb) or die(mysql_error()); $row_Planet = mysql_fetch_assoc($Planet); $totalRows_Planet = mysql_num_rows($Planet); $plans = $row_Planet['PlanetName']; $colname_Fleet = "-1"; if (isset($_GET['recordID'])) { $colname_Fleet = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_Fleet = sprintf("SELECT * FROM fleet WHERE PlanetName = '$plans'"); $Fleet = mysql_query($query_Fleet, $swb) or die(mysql_error()); $row_Fleet = mysql_fetch_assoc($Fleet); $totalRows_Fleet = mysql_num_rows($Fleet); $fleetships = $row_Fleet['FleetName']; $colname_Ships = "-1"; if (isset($_GET['recordID'])) { $colname_Ships = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_Ships = sprintf("SELECT * FROM ships WHERE FleetName = '$fleetships'"); $Ships = mysql_query($query_Ships, $swb) or die(mysql_error()); $row_Ships = mysql_fetch_assoc($Ships); $totalRows_Ships = mysql_num_rows($Ships); ?> <?php do { ?> <?php echo $row_Fleet['FleetName']; ?> <?php echo $row_Fleet['PlanetName']; ?> <?php do { ?> <?php echo $row_Ships['ShipName']; ?> <?php } while ($row_Ships = mysql_fetch_assoc($Ships)); ?> <?php } while ($row_Fleet = mysql_fetch_assoc($Fleet)); ?> If you can spot anything wrong, please let me know. Thanks I think the problem is with echo "<td>".$row["countnow($i)"]."</td>"; it's not showing anything, any ideas how to fix it? Code: [Select] $i = 1; While ($i <25) { ?> <tr> <td><?php echo $i; ?></td> <?php $sql = "SELECT * FROM `systems` WHERE `solarSystemName` LIKE $sname" or die (mysql_error()); $result = mysql_query($sql); while ($row = mysql_fetch_array($result)){ echo "<td>".$row["countnow($i)"]."</td>"; } ?> <tr> <?php $i++; } Hi guys, Was wondering if anyone can help me with this. Here's what I'm trying to do: I've retrieved values from table a from mysql and post them on a form. Code: [Select] echo "<tr><td>" .$row['id']. "</td><td>" .$row['name']. "<input type='hidden' name=name[] value=" .$row['name']. "></td><td><select name='item[]'><option value ='' selected='selected'>Please Select</option><option value ='1'>1</option><option value ='2'>2</option><option value ='3'>3</option></td></tr>"; and now i'm trying to display these information one more time on a different page. So I did the usual retrieval Code: [Select] $name = $_POST['name']; $item = $_POST['item']; Then I'm using foreach loop to retrieve the item values. Code: [Select] foreach ($item as $getitem => $value) { echo "<tr><td>"; echo $value; echo "</td></tr>"; } Here is where I'm stumped. What's the best way to associate the name to the item. while loop? Thanks for the help. Hello everyone, I'm trying to pull a list of email campaigns from constant contact and display them on our site, require_once('ctctWrapper.php'); $data = new CampaignsCollection(); $campaigns = $data->listCampaigns(); foreach ($campaigns as $campaign) { foreach ($campaign as $value) { $feed .= $value . "\r\n"; } } echo $feed; The above code gives me the following error Quote Catchable fatal error: Object of class Campaign could not be converted to string in /home/******/public_html/tmpl/default.php on line 13 If I just print the array, this is how it starts out Code: (xml) [Select] Array ( [0] => Campaign Object ( [campaignName:private] => SimpleXMLElement Object ( [0] => aaaCopy of March 2011 Newsletter ) [id:private] => SimpleXMLElement Object ( [0] => http://api.constantcontact.com/ws/customers/******/campaigns/1105174741613 ) [link:private] => SimpleXMLElement Object ( [0] => /ws/customers/******/campaigns/1105174741613 ) [status:private] => SimpleXMLElement Object ( [0] => Draft ) [campaignDate:private] => SimpleXMLElement Object ( [0] => 2011-04-14T17:07:23.245Z ) [lastEditDate:private] => [campaignSent:private] => [campaignOpens:private] => [campaignClicks:private] => [campaignBounces:private] => [campaignForwards:private] => [campaignOptOuts:private] => [campaignSpamReports:private] => [subject:private] => [fromName:private] => [campaignType:private] => [vawp:private] => [vawpLinkText:private] => [vawpText:private] => [permissionReminder:private] => [permissionReminderText:private] => [greetingSalutation:private] => [greetingName:private] => [greetingString:private] => [orgName:private] => [orgAddr1:private] => [orgAddr2:private] => [orgAddr3:private] => [orgCity:private] => [orgState:private] => [orgInternationalState:private] => [orgCountry:private] => [orgPostalCode:private] => [incForwardEmail:private] => [forwardEmailLinkText:private] => [incSubscribeLink:private] => [subscribeLinkText:private] => [emailContentFormat:private] => [emailContent:private] => [textVersionContent:private] => [styleSheet:private] => [lists:private] => Array ( ) [fromEmailAddress:private] => [fromEmailAddressLink:private] => [replyEmailAddress:private] => [replyEmailAddressLink:private] => [archiveStatus:private] => [archiveUrl:private] => ) [1] => Campaign Object ( [campaignName:private] => SimpleXMLElement Object ( [0] => March 2011 Newsletter ) [id:private] => SimpleXMLElement Object ( [0] => http://api.constantcontact.com/ws/customers/******/campaigns/1104754710085 ) [link:private] => SimpleXMLElement Object ( [0] Hi I relatively new to MVC and trying to understand it all by coding my own MVC framework. I already have coded my (own variant) MVC application: a router calling controllers each creating CRUD(L)* forms (views) onto separate db tables. Now I want to create a dashboard with multiple forms each modifying a separate database table. I already have the ability for one controller to call another controller ad infinitum. However when I press "modify" on one of the forms I do not know how to route (call the router) to rebuild the dashboard restoring all the other forms (ie other controllers) to the same state they were in when my target form requested a modification. Basically I don't know how to go about routing in a hierarchical or nested MVC framework. Should I design a complex (non-linear tree-like) URL request that captures the state of my dashboard and have a very complex router that can decode it? Should each action be idempotent or should I use state in the session to make the request URL easier? *CRUD(L) a view with different forms for CRUD and L(ist) operations each invling different controller methods. I have tried searching under "HMVC" (but that seems to mean "modules") and "nested MVC" but for both terms I mostly get referred to established frameworks. Cheers GAJ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Second Testing</title> <link href="styler.css" rel="stylesheet" type="text/css" /> </head> <body> <?php error_reporting(0); $num_rows = 16; $number1 = 4; $inn = array(7,10,13,16); $outt = array(14,16,21,23); $numm = array(3,5,7,9); $r_time_in = min($inn); for($i = 0; $i <= $num_rows; $i++) { $new_r_timer_in[$i] = $r_time_in; $new_r_timer_out[$i] = $new_r_timer_in[$i] + 1; $r_time_in += 1; } // for($y = 0; $y <= $number1; $i++) // { // for($i = 0; $i <= ($num_rows - 1); $i++) // { // if(($inn[$y] <= $new_r_timer_in[$i]) || ($outt[$y] <= $new_r_timer_out[$i])) // { // $numb[$i] = $numm[$i] + $numm[$i - 1]; // } // else // { // $numb[$i] = $numm[$i - 1]; // } // } // } for($i = 0; $i <= ($num_rows - 1); $i++) { echo '<table width="526" border="0"><tr> <td width="169"> <input type="text" name="$r_in[]" value="'.$new_r_timer_in[$i].'" style="width:169px" readonly="readonly" class="text_non_color"/></td> <td width="169"> <input type="text" name="$r_out[]" value="'.$new_r_timer_out[$i].'" style="width:169px" readonly="readonly" class="text_non_color"/></td> <td width="169"> <input type="text" name="$r_num[]" value="'.$numb[$i].'" style="width:169px" readonly="readonly" class="text_non_color"/></td>'; } print("</tr>"); ?> </body> </html> the code above works very well in its current state. three columns are produced but only two have data, the third column is empty. when executed, the code is supposed to check whether a range(7 - is between the first element of array $inn and the first element of array $outt and then add the corresponding number in array $numm to the number in that(7 - range the commented out code is supposed to implement this idea but its not.........help. |