PHP - I Need Help With A Nested Array
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] Similar TutorialsI have this example php string: Code: [Select] $string = "@[item_1][door] @[mozart][grass] = yes @[mozart][green] = no @[mozart][human] @[blue][movie]=yes @[item_1][beat] = yes @[item_1][music] = no "; now $string idented just to easy view: Code: [Select] @[item_1][door] @[mozart][grass] = yes @[mozart][green] = no @[mozart][human] @[blue][movie]=yes @[item_1][beat] = yes @[item_1][music] = no I want to know how can i get this string ( or other string following this style ) and transform in an array that looks like: Code: [Select] Array ( [item_1] => Array ( [door] => Array ( [mozart] => Array ( [grass] => yes [green] => no [human] => Array ( [blue] => Array ( [movie] => yes ) ) ) ) [beat] => yes [music] => no ) ) What i tried I tried to use and recursive function to create an nested array but i can't have access to the array pointer ( in deep levels ) in recursive functions.. don't know why.. maybe is the wrong patch to the answer. thank you, Does anyone know a way of to find the 'coordinates' of a deeply nested key in a multidimensional array whilst using array_walk_recursive? I am using array_walk_recursive() to stripslashes() of all values of an array. However I need to be able to get the full coordinates of a key if the said key is of a certain value. The function key() only seems to get the highest level key. As a test I have the following array which has three occurrences of a key named 'date'. Upon each occurrence I want to be able to know exactly where in the array it is so i can call is directly later. <?php $pages = array(array("variation"=>"xccsdc", "items"=>array(array("nm"=>"ss", "type"=>"ta", "kkl"=>"Prodion." ), array("nm"=>"nm", "type"=>"nwsfd", "kkl"=>"nws fd", "nws"=>array(array("date"=>"1328982639", "kkl"=>"f nfgfgnfgn", "title"=>"nfgn fgn fhn " ), array("date"=>"1328982632", "kkl"=>"fgn fgn", "title"=>" fgn" ) ) ), array("nm"=>"nm", "type"=>"nwsfd", "kkl"=>"nws fd", "nws"=>array(array("date"=>"1328982655", "kkl"=>" gh fgh","title"=>"n fgh n" ) ) ) ) ) ); function test_print(&$item, $key, $pages) { if($key == 'date') { //strip the slashes $item = stripslashes($item); //if the key is 'date' which is deeply nested, return the key. echo key(current($pages)); echo '<br/>'; } } array_walk_recursive($pages, 'test_print', $pages); ?> What is returned from the 'test_print' function is: Quote variation variation variation Is this because array_walk_recursive() does not move the internal pointer pointer along? I found this thread on stackoverflow: http://stackoverflow.com/questions/3133054/php-find-key-position-in-multidimensional-array which has a great function for finding the key, however i'm struggling to get my head around how I can apply something like this whilst using array_walk_recursive(). Does anyone have any ideas? Hey all, I have two objects that contain object instances. I want to compare the properties of the instances and if the old_parent's property doesn't exist as one of the $new_parent's property, then I place the old_parent's property in an array called unneeded_ids. Problem is when I use nested foreach to loop through the instances of the two objects, despite old_parent having only one instance with a property id of 1, because it loops twice, the array gets two "1" values rather than just one: Code: [Select] public function update(){ $vanity_url = new VanityUrl(); $vanity_url->where('user_id',$this->current_user()->id)->get(); $zones = $this->input->post('zones'); $zone = new Zone(); $zone->where_in('name', $zones)->get(); $subcategory = new Category(); $subcategory->where('id',$this->uri->segment(4))->get(); $old_parents = new Category(); $old_parents = $subcategory->related_category->get(); $unneeded_ids = array(); if(!$this->input->post('catupload')){ if($subcategory->save($zone->all)){ redirect("blogs/$vanity_url->url/categories"); } else { echo "Error occurred. Please try again."; } } else { $new_parents = new Category(); $controller = $this->input->post('catupload'); $new_parents->where_in('controller',$controller)->get(); foreach($new_parents as $new){ foreach($old_parents as $old){ if($new->id != $old->id){ array_push($unneeded_ids, $old->id); } } } var_dump($unneeded_ids); } } The var_dump outputs: Code: [Select] array(4) { [0]=> int(126) [1]=> int(127) [2]=> int(126) [3]=> int(127) } but it should only output: Code: [Select] array(2) {[0]=> int(126) [1]=> int(127)} That's because there's only one object instance of old_parent that has a property id value of 126 and the same for 127. The nested for each loop is causing it to iterate twice against the same object and sticking it into the array. How do I get desired result? Thanks for response. Hello everyone.
please I have problem with printing out a value from inside an array of a nested json. ive tried several ways its always returns "index not define". $valr= "https://ice3.com/api/v1/orderbook/ticker"; ////////////////////////////source $valrGet = file_get_contents($valr); $valrD = json_decode($valrGet, true); $valrSell = ["ask"] ["price"]; Here is the structure of the json from the source : {"errors":false,"response":{"entities":[{"pair_id":3,"pair_name":"BTC\/ZAR","ask":{"price":"179382.54","amount":"0.05357142"},"bid":{"price":"177229.4286563","amount":"0.0011"}},{"pair_id":4,"pair_name":"BTC\/NGN","ask":{"price":"8890000.00","amount":"0.10"},"bid": my target is to output the value of ("price") from "pair_name" BTC\/ZAR please help. Thanks in advance I have a stdClass Object array with nested User arrays as a value that I would like to display in a table cell. I am struggling and have exhausted a lot of time. I am hoping to get a shove in the right direction if possible. The image below will show what I am trying to do.
$someArray = json_decode($token_result); foreach ($someArray as $key => $value) { $combined[] = "<tr><td>" . $value->customer . "</td><td>" . $value->city . '</td> <td>' . $value->state . "</td><td>" . $value->zipcode . '</td> <td>' . $value->totalUsers . "</td><td>" . $value->totalActiveUsers . "</td><td>" . $value->totalInActiveUsers . '</td><td> <a href="">' . $value->users . "</a></td></tr>"; } foreach ($combined as $value) { print $value; } Here is what my Array and Objects look like Array ( [0] => stdClass Object ( [customer] => SWSH [city] => Thomasville [state] => GA [zipcode] => 31792 [totalUsers] => 6 [totalActiveUsers] => 6 [totalInActiveUsers] => 0 [users] => Array ( [0] => stdClass Object ( [firstName] => xxx [lastName] => xxx [phoneNumber] => [userName] => cb_igwrth@xxx.com [createdBy] => [isActive] => 1 ) [1] => stdClass Object ( [firstName] => Dan [lastName] => Stewart [phoneNumber] => +11111111111 [userName] => dan.sxx@xxx.ga.gov [createdBy] => kwilliams@xxx.com [isActive] => 1 ) ) ) [1] => stdClass Object ( [customer] => xxxx [city] => Carver [state] => MA [zipcode] => 02330 [totalUsers] => 3 [totalActiveUsers] => 3 [totalInActiveUsers] => 0 [users] => Array ( [0] => stdClass Object ( [firstName] => Leo [lastName] => Furtado [phoneNumber] => 781-000-0000 [userName] => LFurtado@xxx.com [createdBy] => TConger@ccccc.com [isActive] => 1 ) ) ) ) Table is attached
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); ?> 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.
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 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)
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. 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++; } 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 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. 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 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; ?> 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; }
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. 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>"); ?> |