PHP - Loop Through Variable And Separate Items Into Unique Variables
Hello,
If I have this string: $tags="baseball glove face" (this can vary from 1 to 15 different words) how would i loop through and divide these into different $tag1=baseball $tag2=glove $tag3=face .. and so on (if more words) Thanks for help Similar TutorialsI have this simple while loop which retrieves data from a mysql query and displays several links on my homepage. I would like to avoid using the php get function and add query strings to my urls I am thinking of using session variables but I need help and I'm pretty sure this can't be done. When a visitor clicks a link from the several ones displayed by the while loop, that particular variable would be set in a session. In my code, the session will always send the last var Can this be done? Code: [Select] <? session_start(); // Start Session Variables $result = mysql_query("my query"); while($slice = mysql_fetch_assoc($result)){ $url = $slice['url']; $name = $slice['name']; ?> <a href="<? echo $url; ?>"><? echo $name; ?></a> <? } $_SESSION['name'] = $name; // Store session data ?> First page adds a new job number, then the order page loaded with the job number id as a get id. Basically there is a while loop in the order page which shows products/services client can order and he chooses what he requires 'one or eight services' (8 in total) and some other variables like date of order and client name etc. Here is the order item code The first sql statement executes fine, but in the second sql query nothing happens $sql="insert into job_order(order_num,order_date,order_customer_id, order_remarks) values(".$_GET['id'].",NOW(),".$_POST['companyBox'].",'".$_POST['remarkBox']."');"; $res=mysql_query($sql); $id=mysql_insert_id(); foreach($_POST as $key => $value) { if(!empty($value)) { $key.' => '.trim(strip_tags($value)); $order="INSERT INTO orderprod (order_num,prod_id,order_amount,teeth_amount) VALUES ('$_GET[id]','$value','$value','$value');"; $orderres=mysql_query($order) or die(mysql_error()); } }?>$sql="insert into job_order(order_num,order_date,order_customer_id, order_remarks) values(".$_GET['id'].",NOW(),".$_POST['companyBox'].",'".$_POST['remarkBox']."');"; $res=mysql_query($sql); $id=mysql_insert_id(); foreach($_POST as $key => $value) { if(!empty($value)) { $key.' => '.trim(strip_tags($value)); $order="INSERT INTO orderprod (order_num,prod_id,order_amount,teeth_amount) VALUES ('$_GET[id]','$value','$value','$value');"; $orderres=mysql_query($order) or die(mysql_error()); } } ?> ============= This is the formI have removed parts which are irrelevant. Please note that dateBox and companyBox are not required to be looping as they are only for first table, echo "<form action=".$config_basedir."./vieworder.php?id=".$_GET['id']." name=form1 method=post>";?><table><tr><td><h4>JOB ORDER</H4></TD><TD></TD></TR><TR><TD>ORDER NUMBER</TD><TD><?PHP ECHO $_GET['id'] ?></td></tr><tr><td>ORDER DATE</td><td><input type=text name=dateBox></td></tr> <tr><td>COMPANY NAME</td><td><?PHP$sql="select * from customers";$res=mysql_query($sql);echo "<select name=companyBox><option value=''>Please select</option>";WHILE($fetch=mysql_fetch_assoc($res)){ echo "<option value='".$fetch['id']."'>".$fetch['cust_name']."</option>";} echo "</select>"; echo "</td></tr>"; ?> </table> <table><tr><th>ITEM</th><th>QUANTITY</th><th>N0. of Teeths</th></tr><tr><?PHP$sql="select * from products";$res=mysql_query($sql); WHILE($fetch=mysql_fetch_assoc($res)){ echo "<td><input type=text name=desBox value='".$fetch['prod_id']."'>".$fetch['prod_name']."</td><td><input type=text name=quantBox></td><td><input type=text name=teethBox></td>";echo "</tr>";}echo "</table>";?>echo "<form action=".$config_basedir."./vieworder.php?id=".$_GET['id']." name=form1 method=post>"; ?> <table> <tr> <td><h4>JOB ORDER</H4></TD><TD></TD> </TR> <TR> <TD>ORDER NUMBER</TD><TD><?PHP ECHO $_GET['id'] ?></td> </tr> <tr> <td>ORDER DATE</td><td><input type=text name=dateBox></td> </tr> <tr> <td>COMPANY NAME</td><td> <?PHP $sql="select * from customers"; $res=mysql_query($sql); echo "<select name=companyBox><option value=''>Please select</option>"; WHILE($fetch=mysql_fetch_assoc($res)){ echo "<option value='".$fetch['id']."'>".$fetch['cust_name']."</option>";} echo "</select>"; echo "</td></tr>"; ?> </table> <table> <tr> <th>ITEM</th><th>QUANTITY</th><th>N0. of Teeths</th> </tr> <tr> <?PHP $sql="select * from products"; $res=mysql_query($sql); WHILE($fetch=mysql_fetch_assoc($res)){ echo "<td><input type=text name=desBox value='".$fetch['prod_id']."'>".$fetch['prod_name']."</td> <td><input type=text name=quantBox></td> <td><input type=text name=teethBox></td>"; echo "</tr>";} echo "</table>"; ?> HERE IS THE IMAGE showing the populated services. http://dubads.com/images/order.jpg trying to create an array that is separating brackets, semi-colon and space from "mydata" and iterating over to create first and last name's separated into two subs... and then loop those through. so i'd like either change the way i can explode and loop the information... or place the first and second subs and skip the third sub in the array. $str = $_POST["mydata"]; $mores = explode("[];",$str); foreach ($mores as $more) { $datas = explode(" ",$more); if (array_values ($datas) === $datas) $xmlBody .= " <member name='$datas[1], $datas[0]' display='$datas[0] $datas[1]'>Name</member>"; } can someone please assist? much appreciated. For example if $names has a value of "Mark/Ben/James/Tom" how would I separate it to give each name its own variable, e.g $name1, $name2, $name3
Thanks,
I have a long PHP script that I didn't write. I'd like to get a simple text list of all the unique variables from the script -- all variables within the script that begin with $, such as $_ADMIN $query $category $user $id $result, etc..... Any ideas how a PHP dabbler can go about this? I did a PHPFreaks search, but didn't find a thread on this. Thank you! Hi there! On a page of mine, random tables get generated. The tables consist of 8 characters, so there's 5 . 10^13 possibilities. Yet ofcourse there is a possibility that 2 tables with the same name can be generated, which ofcourse is not desired. So I need an adjustment that can see whether there is already a name that's the same, and if so, make another random name. And if that one also exists, make a new one again. Untill the name doesn't exist yet and it remains. Here's the script I have right now: function createName($length) { $chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $i = 0; $password = ""; while ($i <= $length) { $password .= $chars{mt_rand(0,strlen($chars))}; $i++; } return $password; } $name = createName(8); mysql_select_db($database, $con); $sql = "CREATE TABLE " . $name . "( id int NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), devraag varchar(500), weergave varchar(500), naam varchar(500), inhoud varchar(500), tijd varchar(100))"; mysql_query($sql, $connection)or die(mysql_error()); I'm not goot with the combination of PHP and mysql, and really have no Idea how to do this. Any help? Hi I am new this forum and looking for some much appreciated help with something that has me stumped. I have extracted regions from image names in a directory. example: 'edinburgh_castle_(Edinburgh).jpg' (Extracted Edinburgh from in-between the brackets) So I have a list of Regions, extracted from all the various image names in the directory which I want to populate into a dynamic drop down menu for filtering purposes. Here's my issue... I want there to be only one 'Edinburgh' option appearing in my drop down menu. I don't want duplicates. Here is my code so far. php: [Select] Hi guys, Hi all, I have a situation where I need to remember what check boxes where checked over pagination, I have managed to do this via the use of this: http://jamesfunk.com/wordpress/?p=65 The problem is that as the code stood: Code: [Select] <input type="checkbox" name="compare" value="<?php echo $list['jobseeker_id'];?>" class="remember_cb"/> It was treating one ticked checkbox as them all because they all have the same name and are in the a while loop! I countered this by changing the code to: Code: [Select] <input type="checkbox" name="compare<?php echo $list['jobseeker_id']?>" value="<?php echo $list['jobseeker_id'];?>" class="remember_cb"/> Which effectively now makes the checkbox name unique... i.e. compare{id}. The problem with this is that I can now no longer process it. This is my processing code: $jobseekers = $_POST['compare']; $i = 0; for($i; $i<count($jobseekers); $i++){ $query = "SELECT * FROM jobseekers WHERE jobseeker_id = '$jobseekers[$i]'"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { // Spit out the required data } } As you can see I am trying to get the data from $_POST['compare'], which will obviously now be blank as I have had to make the name unique.... the trouble is I'm not sure how to actually process this. Can anyone help me out here? any help or advice would be greatly appreciated! many thanks, Greens85 Hello! Everybody in my class have their own folder on a domain, so its like: www.thedomain.no/nameofstudent. The problem we are facing is that when i log in on my site i also get logged in on all the other students sites too... (we are all using Dreamweaver CS5.5) We all have a: Welcome, USERNAME, massage on our sites. However if i first log in on my site, then visit another students site i get the massage: Welcome, (and the username i logged in with on my site!) another problem is when i try to access the shopping cart of student X's site (then i get redirected to the loging page on his site), If i then leave that tab open in chrome and open a new one, then i go to my login page in than new tab ON my site, then i log in on my site. Instead of getting redirected to MY index i get redirected to student X's shopping cart... I tried to rename the Session variable without luck. (default dreamweaver is $_Session['MM_Username']) Any Suggestions? Hope i made myself understandable Thanks Hi all, I have a table that shows data from an xml response that has been converted to an array. I have successfully managed to get that to work but it's showing more items than I want. I'm trying to isolate the items by state. There are 11 or so different states, of which I only want 7. I've tried the following with a while loop but I keep getting the message "undefined index: job_status" Here's my code (partial) $projects = array(); $xml=simplexml_load_string($response) or die("Error: Cannot create object"); foreach($xml->Jobs->Job as $item) { $projects[] = array( 'job_no' => (string)$item->ID, 'job_name' => (string)$item->Name, 'job_due' => (string)$item->DueDate, 'job_status' => (string)$item->State, 'job_staff' => (string)$item->Assigned->Staff->Name, ); } usort($projects, function($a,$b) {return $a['job_due'] <=> $b['job_due']; } ); $projects = array_reverse($projects); while ($projects['job_status'] == ('Feasibility') && ('Measure Up') && ('Model Drawing') && ('Concept Design') && ('Developed Design') && ('Resource Consent') && ('Construction Documentation')) { foreach ($projects as $proj) { $formatted = date('d/m/Y', strtotime($proj['job_due'])); $job_no ="{$proj['job_no']}"; $job_name ="{$proj['job_name']}"; $job_due ="$formatted"; $job_status ="{$proj['job_status']}"; $job_staff ="{$proj['job_staff']}"; Any help would be much appreciated thanks. does anyone know how to decode this XML variable value into string values? I also need to know the oposite way: creating variable values into xml. I've tried several code examples but they did filter the requested data. Code: [Select] $xml='<?xml version="1.0" encoding="utf-8"?> <elements> <text identifier="ed9cdd4c-ae8b-4ecb-bca7-e12a5153bc02"> <value/> </text> <textarea identifier="a77f06fc-1561-453c-a429-8dd05cdc29f5"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <textarea identifier="1a85a7a6-2aba-4480-925b-6b97d311ee6c"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <image identifier="ffcc1c50-8dbd-4115-b463-b43bdcd44a57"> <file><![CDATA[images/stories/red/cars/autobedrijf.png]]></file> <title/> <link/> <target/> <rel/> <lightbox_image/> <width><![CDATA[250]]></width> <height><![CDATA[187]]></height> </image> <text identifier="4339a108-f907-4661-9aab-d6f3f00e736e"> <value><![CDATA[Kramer 5]]></value> </text> <text identifier="ea0666d7-51e3-4e52-8617-25e3ad61f8b8"> <value><![CDATA[6000 RS]]></value> </text> <text identifier="90a18889-884b-4d53-a302-4e6e4595efa0"> <value><![CDATA[Eindhoven]]></value> </text> <text identifier="410d72e0-29b3-4a92-b7d7-f01e828b1586"> <value><![CDATA[APK Pick up and return]]></value> </text> <text identifier="45b86f23-e656-4a81-bb8f-84e5ea76f71f"> <value><![CDATA[15% korting op grote beurt]]></value> </text> <text identifier="3dbbe1c6-15d6-4375-9f2f-f0e7287e29f3"> <value><![CDATA[Gratis opslag zomerbanden]]></value> </text> <text identifier="2e878db0-605d-4d58-9806-8e75bced67a4"> <value><![CDATA[Gratis abonnement of grote beurt]]></value> </text> <text identifier="94e3e08f-e008-487b-9cbd-25d108a9705e"> <value/> </text> <text identifier="73e74b73-f509-4de7-91cf-e919d14bdb0b"> <value/> </text> <text identifier="b870164b-fe78-45b0-b840-8ebceb9b9cb6"> <value><![CDATA[040 123 45 67]]></value> </text> <text identifier="8a91aab2-7862-4a04-bd28-07f1ff4acce5"> <value/> </text> <email identifier="3f15b5e4-0dea-4114-a870-1106b85248de"> <value/> <text/> <subject/> <body/> </email> <link identifier="0b3d983e-b2fa-4728-afa0-a0b640fa34dc"> <value/> <text/> <target/> <custom_title/> <rel/> </link> <relateditems identifier="7056f1d2-5253-40b6-8efd-d289b10a8c69"/> <rating identifier="cf6dd846-5774-47aa-8ca7-c1623c06e130"> <votes><![CDATA[1]]></votes> <value><![CDATA[1.0000]]></value> </rating> <googlemaps identifier="160bd40a-3e0e-48de-b6cd-56cdcc9db892"> <location><![CDATA[50.895711,5.955427]]></location> </googlemaps> </elements>'; Basically I have the following code (posted below) foreach($char_xml->characterInfo->characterTab->items->item as $item) { //get the item id $item_id = $item->attributes()->id; //get the xml doc for that item from wow armory $url = "http://www.wowarmory.com/item-info.xml?i=" . $item_id; $data = fetchXML($url); //create a SimpleXML object to parse the xml $item_xml = new SimpleXmlElement($data); //print the item's name echo "<li type=square>" . $item_xml->itemInfo->item->attributes()->name . " "; echo "<b>(" . $item_xml->itemInfo->item->attributes()->level . ")</b></br>"; //calculate gear score total $calc=$calc+$item_xml->itemInfo->item->attributes()->level; } echo '</ul>'; //print the total item level echo '<b>Total Additive Item Score (Equipped):</b>' . $calc; echo '<br>'; //calculate the average item level(equipped) $ilvl=$calc/16; echo '<b>Average Item Score (Equipped):</b>' . round($ilvl) . "<br><br>"; It is working relatively well for what I am trying to accomplish. It pulls xml data from wowarmory and uses it to calculate a player's "average item level". The problem I am running in to is if a player is equipped with certain items (that should not be calculated), the average is incorrect. I know atleast the shirt, tabard and off-hand need to be ignored IF equipped. I am trying to find something relative to all 3 items in the xml data and thus tell the script to disregard them. Here is a printed example of the array I am working with (warning its LONG). This is an example of a player that has these 3 extra items. Shirt (Block 4), off-hand(shield) (Block 17), and Tabard (Block19) : Quote SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=59458 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_gizmo_newgoggles [id] => 59458 [level] => 359 [name] => Energized Bio-Optic Killshades [quality] => 4 [requiredSkill] => Engineering [requiredSkillRank] => 525 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 150956 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [createdBy] => SimpleXMLElement Object ( [spell] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => trade_engineering [id] => 81720 [name] => Energized Bio-Optic Killshades ) [reagent] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 20 [icon] => inv_misc_pyriumbar [id] => 52186 [name] => Elementium Bar [quality] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 20 [icon] => inv_stone_15 [id] => 54849 [name] => Obsidium Bar [quality] => 1 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 2 [icon] => inv_misc_truegold [id] => 58480 [name] => Truegold [quality] => 2 ) ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=67130 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_misc_forestnecklace [id] => 67130 [level] => 359 [name] => Dorian's Lost Necklace [quality] => 4 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 53434 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=58129 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_shoulder_mail_dungeonmail_c_04 [id] => 58129 [level] => 346 [name] => Seafoam Mantle [quality] => 3 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 112607 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_largeshard_superior [id] => 52721 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Heavenly Shard [quality] => 3 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=14617 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_shirt_red_01 [id] => 14617 [level] => 1 [name] => Sawbones Shirt [quality] => 1 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 6250 ) ) [dropCreatures] => SimpleXMLElement Object ( [creature] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Scholomance [areaUrl] => fl[source]=dungeon&fl[dungeon]=scholomance&fl[boss]=all&fl[difficulty]=all [classification] => 1 [dropRate] => 2 [heroic] => 1 [id] => 11261 [maxLevel] => 42 [minLevel] => 42 [name] => Doctor Theolen Krastinov [title] => The Butcher [type] => Humanoid [url] => fl[source]=dungeon&fl[dungeon]=scholomance&fl[difficulty]=heroic&fl[boss]=11261 ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=56563 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_chest_raidshaman_i_01 [id] => 56563 [level] => 359 [name] => Twilight Scale Chestguard [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 101750 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [createdBy] => SimpleXMLElement Object ( [spell] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => trade_leatherworking [id] => 78489 [name] => Twilight Scale Chestguard ) [reagent] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 10 [icon] => item_savageleather [id] => 52976 [name] => Savage Leather [quality] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_rubysanctum2 [id] => 52979 [name] => Blackened Dragonscale [quality] => 1 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_pelt_12 [id] => 52980 [name] => Pristine Hide [quality] => 3 ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilewater [id] => 52326 [name] => Volatile Water [quality] => 1 ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilefire [id] => 52325 [name] => Volatile Fire [quality] => 1 ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilelife_green [id] => 52329 [name] => Volatile Life [quality] => 1 ) ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=56538 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_belt_mail_raidshaman_i_01 [id] => 56538 [level] => 359 [name] => Stormleather Sash [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 53729 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [createdBy] => SimpleXMLElement Object ( [spell] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => trade_leatherworking [id] => 78462 [name] => Stormleather Sash ) [reagent] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 10 [icon] => item_savageleather [id] => 52976 [name] => Savage Leather [quality] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_rubysanctum2 [id] => 52979 [name] => Blackened Dragonscale [quality] => 1 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_pelt_12 [id] => 52980 [name] => Pristine Hide [quality] => 3 ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilewater [id] => 52326 [name] => Volatile Water [quality] => 1 ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilefire [id] => 52325 [name] => Volatile Fire [quality] => 1 ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilelife_green [id] => 52329 [name] => Volatile Life [quality] => 1 ) ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=67148 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_pant_raidshaman_i_01 [id] => 67148 [level] => 359 [name] => Kilt of Trollish Dreams [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 196103 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=62363 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_boots_raidshaman_i_01 [id] => 62363 [level] => 359 [name] => Earthmender's Boots [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 159778 ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=59310 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_bracer_raidshaman_i_01 [id] => 59310 [level] => 359 [name] => Chaos Beast Bracers [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 102564 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [dropCreatures] => SimpleXMLElement Object ( [creature] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Blackwing Descent [classification] => 3 [dropRate] => 3 [id] => 43296 [maxLevel] => 88 [minLevel] => 88 [name] => Chimaeron [type] => Beast ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Blackwing Descent [classification] => 3 [dropRate] => 2 [id] => 47774 [maxLevel] => 88 [minLevel] => 88 [name] => Chimaeron [type] => Beast ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=60314 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_glove_raidshaman_i_01 [id] => 60314 [level] => 359 [name] => Gloves of the Raging Elements [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 105223 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [dropCreatures] => SimpleXMLElement Object ( [creature] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Baradin Hold [classification] => 1 [dropRate] => 1 [id] => 47120 [maxLevel] => 88 [minLevel] => 88 [name] => Argaloth [type] => Demon ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Baradin Hold [classification] => 1 [dropRate] => 1 [heroic] => 1 [id] => 51350 [maxLevel] => 88 [minLevel] => 88 [name] => Argaloth [type] => Demon ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=59220 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_misc_rubystar [id] => 59220 [level] => 359 [name] => Security Measure Alpha [quality] => 4 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 53434 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [dropCreatures] => SimpleXMLElement Object ( [creature] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Blackwing Descent [classification] => 1 [dropRate] => 3 [id] => 42180 [maxLevel] => 88 [minLevel] => 88 [name] => Toxitron [type] => Mechanical ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Blackwing Descent [classification] => 1 [dropRate] => 3 [id] => 49050 [maxLevel] => 88 [minLevel] => 88 [name] => Toxitron [type] => Mechanical ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Blackwing Descent [classification] => 1 [dropRate] => 2 [id] => 49056 [maxLevel] => 88 [minLevel] => 88 [name] => Arcanotron [type] => Mechanical ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=67129 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_misc_pearlring1 [id] => 67129 [level] => 359 [name] => Signet of High Arcanist Savor [quality] => 4 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 53434 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=62465 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_misc_branch_01 [id] => 62465 [level] => 359 [name] => Stump of Time [quality] => 4 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 80507 ) ) [translationFor] => SimpleXMLElement Object ( [@attributes] => Array ( [factionEquiv] => 0 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_misc_branch_01 [id] => 62470 [level] => 359 [name] => Stump of Time [quality] => 4 ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=62047 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_inscription_tarot_volcanocard [id] => 62047 [level] => 359 [name] => Darkmoon Card: Volcano [quality] => 4 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 107343 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=67131 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_misc_cape_cataclysm_caster_c_01 [id] => 67131 [level] => 359 [name] => Ritssyn's Ruminous Drape [quality] => 4 [type] => Cloth ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 99205 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=61338 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_mace_1h_pvp400_c_01 [id] => 61338 [level] => 359 [name] => Vicious Gladiator's Gavel [quality] => 4 [type] => One-Handed Maces ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 334291 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=55070 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_shield_bwdraid_d_02 [id] => 55070 [level] => 359 [name] => Elementium Stormshield [quality] => 4 [type] => Shields ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 115029 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [createdBy] => SimpleXMLElement Object ( [spell] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => spell_shadow_sealofkings [id] => 76455 [name] => Elementium Stormshield ) [reagent] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 8 [icon] => inv_misc_ebonsteelbar [id] => 53039 [name] => Hardened Elementium Bar [quality] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_pyriumbar [id] => 52186 [name] => Elementium Bar [quality] => 1 ) ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=64672 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_shield_56 [id] => 64672 [level] => 359 [name] => Relic of Norgannon [quality] => 4 [type] => Relic ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 101843 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=65904 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_misc_tabard_tolvir [id] => 65904 [level] => 85 [name] => Tabard of Ramkahen [quality] => 1 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [buyPrice] => 10000 [sellPrice] => 2500 ) ) [vendors] => SimpleXMLElement Object ( [creature] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Uldum [classification] => 0 [heroic] => 1 [id] => 48617 [maxLevel] => 83 [minLevel] => 83 [name] => Blacksmith Abasi [title] => Ramkahen Quartermaster [type] => Humanoid ) ) ) ) ) ) I guess the shirt and tabard can be identified by the "[Quality]=>1" which no other items should typically have. The big issue comes with the third odd ball (off hand). This off-hand could be a shield or any weapon with few exceptions depending on the player class. As I continue to try and figure this out, one solution could be to first take the previous two "[Quality]=>1" items out of the equation IF they exist, then ONLY IF there are 17 items remaining subtract the value of block/iteration 17 before calulating as usual. If 16 items, then just run $calc is it currently is. How would I accomplish this? I do not mind displaying the item's name, in fact I would prefer to keep the item list as it currently I just need to not include the said items in the item level average. I know this is probably relatively straight forward to accomplish and that I am a noob, but would be grateful of your assistance. Thanks. Hi I have an array of items that I am currently displaying a foreach loop What I'm looking to do, is add a string, to all of items, a part from the last 4: foreach ($pager->getResults() as $items => $item) { echo $item->getName(); //need to add a string to this for the all but the last 4 } Thanks I've been trying to grab the unique auto incrementing table id and put into a session variable. $name_id = mysql_insert_id(); $query = sprintf("INSERT INTO profile ( name_id, bio, ex) VALUES (LAST_INSERT_ID(),'%s','%s')", mysql_real_escape_string($_SESSION['pro']['bio']), mysql_real_escape_string($_SESSION['pro']['ex'])); $result = mysql_query($query, $db) or die(mysql_error($db)); $name_id = mysql_insert_id(); $_SESSION['name_id'] = $name_id; //this is the key line $_SESSION['logged'] = 1; header('Refresh: 5; URL=main.php'); I've echoed out the result of $_SESSION['name_id'] and it says '0'. I've tried changing the key line to $_SESSION['name_id'] = LAST_INSERT_ID(); but I get this error message: Fatal error: Call to undefined function LAST_INSERT_ID() in C:\x\xa Is my goal acheivavle or should I just set up a select query after the insert query and extract the id key? Running a simple query: SELECT team, rank from table ORDER BY rank ASC returns 8 records in order from 1 to 8 I then want to a assign a new variable to each that I can use for later queries ie: team with rank 1 = $team1 team with rank 2 = $team2 team with rank 3 = $team3 etc.... Thanks in advance. Hello everyone, I can get Test 2 to successfully operate the if statement using a variable variable. But when I try the same method using a session variable (Test 1) the if statement is not executed. Please could you tell me why the if statement in Test 1 is not being executed? Code: [Select] <?php # TEST 1 $_SESSION[test_variable] = "abcd"; $session_variable_name = "_SESSION[test_variable]"; if ($$session_variable_name == "abcd") { echo "<br>line 373, abcd<br>"; } # TEST 2 $test_variable = "efgh"; $test_variable_name = "test_variable"; if ($$test_variable_name == "efgh") { echo "<br>line 379, efgh<br>"; } ?> Many thanks, Stu I'm new at PHP and have a problem. I have a MySql database with lists of students grouped into classrooms. A typical group is shown in the attached screenshot screenshot.docx. I want to be able to select one or more of the names by using the associated checkbox, and upgrade a student or students into a different group as defined in the radio button list also in the screenshot. I have the rudiments of the file attached, but I have absolutely no idea how I can post the array so that the records are updated. Each student has an individual record with a field name userGroup which holds a string nominated by their classroom teacher, such as "year7", "year 8" and so on while they are in one of the several classrooms, but when they leave school this is recorded in a field named noGroup with a value of 0 or 1. I can post further details as required, but it would be great if someone could help me. I have a mysql table which will store users email addresses (each is unique and is the primary field) and a timestamp. I have added another column called `'unique_code' (varchar(64), utf8_unicode_ci)`. What I would very much appreciate assistance with is; a) Generating a 5 digit alphanumeric code, ie: 5ABH6 b) Check all rows the 'unique_code' column to ensure it is unique, otherwise re-generate and check again c) Insert the uniquely generated 5 digit alphanumeric code into `'unique_code'` column, corresponding to the email address just entered. d) display the code on screen. What code must I put and where? **My current php is as follows:** Code: [Select] require "includes/connect.php"; $msg = ''; if($_POST['email']){ // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $mysqli->query("INSERT INTO coming_soon_emails SET email='".$mysqli->real_escape_string($_POST['email'])."'"); if($mysqli->affected_rows != 1){ throw new Exception('You are already on the notification list.'); } if($ajax){ die('{"status":1}'); } $msg = "Thank you!"; } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } I guess I'll rephrase since my wording wasn't very clear. Why don't echo "<p>\n"; if (!empty($locations) && is_array($locations)) { foreach ($locations as $field => $val) { if ($field == "City") { echo $field . ' : ' . $val . "<br />\n"; $val = $cityvar; } if ($field == "ZipPostalCode") { echo $field . ' : ' . $val . "<br />\n"; $val = $zipvar; } if ($field == "CountryName") { echo $field . ' : ' . $val . "<br />\n"; $val = $countryvar; } } } echo "</p>\n"; |