PHP - Struggling To Break Apart Array For Math
I have to take over somebody else's project. So I have the combination of being a beginner, not understanding their code well, and not experienced with arrays. I'm in over my head.
I have an array passed to the page, that would be something like this: Array ( [215] => [213] => 1 [212] => 2 [214] => ) the user chose 1 person in 213, and 2 people in 212 and I basically need to break it apart to do math like this: (#people x cost of 213 = totalcostA ) + (# people x cost of 212 = totalcostB) = total The broken down data goes into the database, and the total is used for the cart. I've taken suggestions and gotten to this jumbled mess: Code: [Select] $ids = $_POST['workshop_id']; print_r($_POST['participantqty']); // the above shows the arrays are sending to this page and printing correctly: Array ( [215] => [213] => 1 [212] => 2 [214] => ) foreach ($_POST['workshop_id'] as $id){ $qty = $_POST['participatqty'][$id]; } if(sizeof($_POST['workshop_id'])) { // loop through array $number = count($ids); for ($i=0; $i<=$number; $i++) { // store a single item number and description in local variables $itno = $ids[$i]; $qty_insert = $qty[$i]; $query_insertItemWorkshop = "INSERT INTO tbl_registration_workshop (registration_id, workshop_id, regworkshop_qty) VALUES ('$reg_id', '$itno', '$qty_insert')"; $dberror = ""; $ret = mysql_query($query_insertItemWorkshop); $query_selectAllItems_events = 'SELECT * FROM tbl_workshops where workshop_id = '.$itno; @$result_all_events = mysql_query($query_selectAllItems_events); @$numRows_all_events = mysql_num_rows($result_all_events); @$num=mysql_num_rows($result_all_events); @$z_row = mysql_fetch_array($result_all_events); // I want the below to work, but it won't until I can figure out how to break it all down. $qty_total=$qty_insert*$z_row['workshop_price']; $total = $total + $qty_total; if ($ids[$i] <> '') { // I want the info to also appear below, but can't until I figure out how to break them down. echo $total_students; echo "<tr><td valign=top><b>Description:</b> ". $z_row['workshop_title'] ."</td><td align='right' colspan='2' width=300 valign=top>" . $qty_insert . " at ". $z_row['workshop_price'] ." each: </td><td valign=top> $". $qty_total ."</td></tr>"; Similar TutorialsSo I have a list of events happening on certain dates Date event event event Date event event Date event Date event event i.e the number of events per date change. The whole list is stored in an array called $matches. Depending on the formatting of the event or date tells the computer (or me) whether it is an event or a date. So the locations of the dates within $matches[] are stored in the array $dayKeys, and the position of the events within $matches[] is stored in the array $tournKeys. I am trying to print the list back out in the correct order. Code: [Select] foreach($dayKeys as $a => $b) { $c = $a; foreach($tournKeys as $c => $d) { if (($tournKeys[$c] > $dayKeys[$a]) && ($tournKeys[$c] < $dayKeys[$a+1])) //if both are true print the events until it is required to print the next date as oppposed to an event. { ......print the data from matches..... } } } I have tried to simplify the above loops as much as possible for this thread. My point is though, that when I am at the end of $dayKeys, $dayKeys[$a+1] generates an error, because there are no more $dayKeys. So my question is how should I rephrase that if condition so that I dont have to look to see whether The next thing to print is a date or an event by looking at the next $dayKeys value? I suck with arrays, there I said it . With that said, hopefully someone can help me here. I have two multi-dimensional arrays called $allteams and $chosenteams (the contents of which are listed below). I simply want to compare them and make a new array of the items that are in the first array ($allteams) but NOT in the second array ($chosenteams). NOTE: I tried to use array_diff() but couldn't get it to work since they are multidimensional... FYI, I'm also confused why the info appears to be listed twice but I think that just has to do with associative vs. numeric arrays (i.e. I think I just need to specify one and the amount info would be cut in half), but I'll research this more on my own as it seems like it has to be easy to find $allteams Array ( => Array ( => 1 [teamid] => 1 [1] => Philadelphia [teamcity] => Philadelphia [2] => Eagles [teamname] => Eagles ) [1] => Array ( => 2 [teamid] => 2 [1] => Dallas [teamcity] => Dallas [2] => Cowboys [teamname] => Cowboys ) [2] => Array ( => 3 [teamid] => 3 [1] => New York [teamcity] => New York [2] => Giants [teamname] => Giants ) [3] => Array ( => 4 [teamid] => 4 [1] => Washington [teamcity] => Washington [2] => Redskins [teamname] => Redskins ) [4] => Array ( => 5 [teamid] => 5 [1] => Detroit [teamcity] => Detroit [2] => Lions [teamname] => Lions ) [5] => Array ( => 6 [teamid] => 6 [1] => Minnesota [teamcity] => Minnesota [2] => Vikings [teamname] => Vikings ) [6] => Array ( => 7 [teamid] => 7 [1] => Green Bay [teamcity] => Green Bay [2] => Packers [teamname] => Packers ) [7] => Array ( => 8 [teamid] => 8 [1] => Chicago [teamcity] => Chicago [2] => Bears [teamname] => Bears ) [8] => Array ( => 9 [teamid] => 9 [1] => Tampa Bay [teamcity] => Tampa Bay [2] => Buccs [teamname] => Buccs ) [9] => Array ( => 10 [teamid] => 10 [1] => New Orleans [teamcity] => New Orleans [2] => Saints [teamname] => Saints ) [10] => Array ( => 11 [teamid] => 11 [1] => Carolina [teamcity] => Carolina [2] => Panthers [teamname] => Panthers ) [11] => Array ( => 12 [teamid] => 12 [1] => Atlanta [teamcity] => Atlanta [2] => Falcons [teamname] => Falcons ) [12] => Array ( => 13 [teamid] => 13 [1] => Seattle [teamcity] => Seattle [2] => Seahawks [teamname] => Seahawks ) [13] => Array ( => 14 [teamid] => 14 [1] => San Francisco [teamcity] => San Francisco [2] => 49ers [teamname] => 49ers ) [14] => Array ( => 15 [teamid] => 15 [1] => St. Louis [teamcity] => St. Louis [2] => Rams [teamname] => Rams ) [15] => Array ( => 16 [teamid] => 16 [1] => Arizona [teamcity] => Arizona [2] => Cardinals [teamname] => Cardinals ) [16] => Array ( => 17 [teamid] => 17 [1] => New York [teamcity] => New York [2] => Jets [teamname] => Jets ) [17] => Array ( => 18 [teamid] => 18 [1] => Miami [teamcity] => Miami [2] => Dolphins [teamname] => Dolphins ) [18] => Array ( => 19 [teamid] => 19 [1] => Buffalo [teamcity] => Buffalo [2] => Bills [teamname] => Bills ) [19] => Array ( => 20 [teamid] => 20 [1] => New England [teamcity] => New England [2] => Patriots [teamname] => Patriots ) [20] => Array ( => 21 [teamid] => 21 [1] => Baltimore [teamcity] => Baltimore [2] => Ravens [teamname] => Ravens ) [21] => Array ( => 22 [teamid] => 22 [1] => Cincinnati [teamcity] => Cincinnati [2] => Bengals [teamname] => Bengals ) [22] => Array ( => 23 [teamid] => 23 [1] => Pittsburgh [teamcity] => Pittsburgh [2] => Steelers [teamname] => Steelers ) [23] => Array ( => 24 [teamid] => 24 [1] => Cleveland [teamcity] => Cleveland [2] => Browns [teamname] => Browns ) [24] => Array ( => 25 [teamid] => 25 [1] => Houston [teamcity] => Houston [2] => Texans [teamname] => Texans ) [25] => Array ( => 26 [teamid] => 26 [1] => Tennessee [teamcity] => Tennessee [2] => Titans [teamname] => Titans ) [26] => Array ( => 27 [teamid] => 27 [1] => Jacksonville [teamcity] => Jacksonville [2] => Jaguars [teamname] => Jaguars ) [27] => Array ( => 28 [teamid] => 28 [1] => Indianapolis [teamcity] => Indianapolis [2] => Colts [teamname] => Colts ) [28] => Array ( => 29 [teamid] => 29 [1] => Denver [teamcity] => Denver [2] => Broncos [teamname] => Broncos ) [29] => Array ( => 30 [teamid] => 30 [1] => Kansas City [teamcity] => Kansas City [2] => Chiefs [teamname] => Chiefs ) [30] => Array ( => 31 [teamid] => 31 [1] => Oakland [teamcity] => Oakland [2] => Raiders [teamname] => Raiders ) [31] => Array ( => 32 [teamid] => 32 [1] => San Diego [teamcity] => San Diego [2] => Chargers [teamname] => Chargers ) ) $chosenteams Array ( => Array ( => 2 [teamid] => 2 [1] => Dallas [teamcity] => Dallas [2] => Cowboys [teamname] => Cowboys ) [1] => Array ( => 3 [teamid] => 3 [1] => New York [teamcity] => New York [2] => Giants [teamname] => Giants ) ) Again, I just want to compare those two multi-dimensional arrays and end up with another array that only has the items that are in the first but NOT in the second. So now I'm trying to do it the way below using simply "array_push" Code: [Select] $remainingteams = array(); foreach($allteams as $teamname=> $value) { if (in_array($teamname, $chosenteams)) { } else { array_push($remainingteams,$teamname); } } My end result based on the way the arrays are in this example should be... $remainingteams (really the only difference is that the Cowboys and Giants info is gone) Array ( => Array ( => 1 [teamid] => 1 [1] => Philadelphia [teamcity] => Philadelphia [2] => Eagles [teamname] => Eagles ) [3] => Array ( => 4 [teamid] => 4 [1] => Washington [teamcity] => Washington [2] => Redskins [teamname] => Redskins ) [4] => Array ( => 5 [teamid] => 5 [1] => Detroit [teamcity] => Detroit [2] => Lions [teamname] => Lions ) [5] => Array ( => 6 [teamid] => 6 [1] => Minnesota [teamcity] => Minnesota [2] => Vikings [teamname] => Vikings ) [6] => Array ( => 7 [teamid] => 7 [1] => Green Bay [teamcity] => Green Bay [2] => Packers [teamname] => Packers ) [7] => Array ( => 8 [teamid] => 8 [1] => Chicago [teamcity] => Chicago [2] => Bears [teamname] => Bears ) [8] => Array ( => 9 [teamid] => 9 [1] => Tampa Bay [teamcity] => Tampa Bay [2] => Buccs [teamname] => Buccs ) [9] => Array ( => 10 [teamid] => 10 [1] => New Orleans [teamcity] => New Orleans [2] => Saints [teamname] => Saints ) [10] => Array ( => 11 [teamid] => 11 [1] => Carolina [teamcity] => Carolina [2] => Panthers [teamname] => Panthers ) [11] => Array ( => 12 [teamid] => 12 [1] => Atlanta [teamcity] => Atlanta [2] => Falcons [teamname] => Falcons ) [12] => Array ( => 13 [teamid] => 13 [1] => Seattle [teamcity] => Seattle [2] => Seahawks [teamname] => Seahawks ) [13] => Array ( => 14 [teamid] => 14 [1] => San Francisco [teamcity] => San Francisco [2] => 49ers [teamname] => 49ers ) [14] => Array ( => 15 [teamid] => 15 [1] => St. Louis [teamcity] => St. Louis [2] => Rams [teamname] => Rams ) [15] => Array ( => 16 [teamid] => 16 [1] => Arizona [teamcity] => Arizona [2] => Cardinals [teamname] => Cardinals ) [16] => Array ( => 17 [teamid] => 17 [1] => New York [teamcity] => New York [2] => Jets [teamname] => Jets ) [17] => Array ( => 18 [teamid] => 18 [1] => Miami [teamcity] => Miami [2] => Dolphins [teamname] => Dolphins ) [18] => Array ( => 19 [teamid] => 19 [1] => Buffalo [teamcity] => Buffalo [2] => Bills [teamname] => Bills ) [19] => Array ( => 20 [teamid] => 20 [1] => New England [teamcity] => New England [2] => Patriots [teamname] => Patriots ) [20] => Array ( => 21 [teamid] => 21 [1] => Baltimore [teamcity] => Baltimore [2] => Ravens [teamname] => Ravens ) [21] => Array ( => 22 [teamid] => 22 [1] => Cincinnati [teamcity] => Cincinnati [2] => Bengals [teamname] => Bengals ) [22] => Array ( => 23 [teamid] => 23 [1] => Pittsburgh [teamcity] => Pittsburgh [2] => Steelers [teamname] => Steelers ) [23] => Array ( => 24 [teamid] => 24 [1] => Cleveland [teamcity] => Cleveland [2] => Browns [teamname] => Browns ) [24] => Array ( => 25 [teamid] => 25 [1] => Houston [teamcity] => Houston [2] => Texans [teamname] => Texans ) [25] => Array ( => 26 [teamid] => 26 [1] => Tennessee [teamcity] => Tennessee [2] => Titans [teamname] => Titans ) [26] => Array ( => 27 [teamid] => 27 [1] => Jacksonville [teamcity] => Jacksonville [2] => Jaguars [teamname] => Jaguars ) [27] => Array ( => 28 [teamid] => 28 [1] => Indianapolis [teamcity] => Indianapolis [2] => Colts [teamname] => Colts ) [28] => Array ( => 29 [teamid] => 29 [1] => Denver [teamcity] => Denver [2] => Broncos [teamname] => Broncos ) [29] => Array ( => 30 [teamid] => 30 [1] => Kansas City [teamcity] => Kansas City [2] => Chiefs [teamname] => Chiefs ) [30] => Array ( => 31 [teamid] => 31 [1] => Oakland [teamcity] => Oakland [2] => Raiders [teamname] => Raiders ) [31] => Array ( => 32 [teamid] => 32 [1] => San Diego [teamcity] => San Diego [2] => Chargers [teamname] => Chargers ) ) Can anyone help me figure this out? i've been trying for hours (I know, that's pathetic ) Having to go into somebody else's code yet again! Gah! Originally the totaling page just subtracted a flat discount. But now the client wants to be able to subtract percentage discounts and 'per item' discounts. In the discount table I added a field to determine whether the discount chosen is to be applied as flat off total, flat per item, % off total, and % off each item. I also entered a field that can have a class id, in case this discount is only for that class. (the intention being that otherwise the discount is on anything) I've got a session variable that generates something like : Array ( [217] => 1 [215] => 2 ) meaning 1 person in class #217, and 2 people in class 215. $_SESSION['s_to_be_added'] = array_filter($_POST['participantqty']); Then on the page I'm concerned with, I've been trying to write the script. I know I still need some math stuff figured out But how do I take the array, do the math, and then generate an overall cost for the whole thing? and this is just the discounting? I don't even have a clue how to work in delimiting it if there's a class id.. did any of that make sense? Code: [Select] <?php // the above is the array I want to use to $passed_array = array_filter($_SESSION['s_to_be_added']); // this is the discount 'code' the user entered. $discount = mysql_escape_string($_POST['discount']); // just a donation added after everything. $donation = mysql_escape_string($_POST['donation']); // finding the discount that matches the discount 'code' entered. $query_selectAllItems_events = "SELECT discount_amount,discount_type,workshop_link_1 FROM tbl_discount where discount_value = '$discount'"; $result_all_events = mysql_query($query_selectAllItems_events); $numRows_all_events = mysql_num_rows($result_all_events); $num=mysql_num_rows($result_all_events); $z_row = mysql_fetch_array($result_all_events); // this is just a number: 1, 20, 90 etc. $discount_amount = $z_row['discount_amount']; /*this is 1,2,3,4 - for each type of discount 1- flat 2- flat per item 3- discount on all, 4- discount per item */ $discount_type = $z_row['discount_type']; // the workshop id if the discount is onlyh for this workshop $discount_link_1 = $z_row['workshop_link_1']; // just a description $discount_name = $z_row['discount_name']; if ($discount_type ==1) { /* flat discount on total here */ $total = mysql_escape_string($_POST['total']); $final_total = ($total - $discount_amount); $final_total = ($final_total + $donation); } elseif ($discount_type ==2)) { /* discount per item total here */ $total = mysql_escape_string($_POST['total']); $final_total = ($total - $discount_amount); $final_total = ($final_total + $donation); } elseif ($discount_type ==3)) { /* percentage discount on total here */ $total = mysql_escape_string($_POST['total']); $final_total = ($total * ($discount_amount/100)); $final_total = ($final_total + $donation); } elseif ($discount_type ==4)) { /* percentage discount per item here */ $total = mysql_escape_string($_POST['total']); $final_total = ($total * ($discount_amount/100)); $final_total = ($final_total + $donation); } ?> I have the following code: Code: [Select] private function buildJSResponse(){ $data = ""; $i = 0; $arr = array(); while($this->db->row()){ $arr[] = (int)$this->db->field("average"); } $this->max = max($arr); $this->min = min($arr); $this->mid = round(($this->max + $this->min) / 2); foreach($arr as $val){ $nTime = ($val / $this->max) * 100; $data .= "data[$i] = ".$nTime.";"; $i++; } return $data; } It takes an array, finds the max/min and number halfway between the min/max. The next part I am not sure what to do. I am making a line graph using the canvas, so I am building a javascript array, which will contain the point on the chart. The problem I am having, is location. Lets say $max = 110, and $min = 95. the y position on the graph should be 0 for $max, and 100 for $min, then all the other points need to fall into their place as well. $nTime is supposed to do that, but it doesn't any suggestions? The attachment is the result I am getting from my above code. As you can see the lowest number is 49, so the value with 49 should touch the bottom, which it doesn't. Hi, In my mysql database i have a text input option, in the registration form and edit my details form i have a multiple select dropdown list, which user selects options to populate the text input box, which ultimately populates the text field in the mysql database. All works perfectly. The dropdownlist consists of 3 parts <optgroups> first is current selection (what is the usesr current selection)works fine, The second <optgroup> is existing words, what words we(the site) have given as options, and the third <optgroup> is the words that others have used. This is where im having a small problem. Because its a text field when i call the data from the database, it calls the entire text box as a single option in my select list.. I want to break the words in the text field (at the comma) and have them listed each one as an option in the select list. Example what i need: Words in text box:(my input allows the "comma") word1, word2, word3, word4, word5, word6, How i want them called/displayed: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> here's my code: $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $original_functionsexperience =doSelectSql($query,1); $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $functionsexperiencelist=doSelectSql($query); $funcexpList ="<select multiple=\"multiple\" onchange=\"setFunctionsexperience(this.options)\">"; foreach ($functionsexperiencelist as $functionsexperienceal) { $selected=""; if ($functionsexperienceals->allwords == $original_functionsexperience) $selected=' selected="selected"'; $allwords=$functionsexperienceal->allwords; $funcexpList .= "<optgroup label=\"Current selection\"> <option value=\"".$allwords."\" ".$selected." >".$allwords."</option> </optgroup> <optgroup label=\"Existing Words\"> <option value=\"existing1,\">existing1</option> <option value=\"existing2,\">existing2</option> <option value=\"existing3,\">existing3</option> <option value=\"existing4,\">existing4</option> <option value=\"existing5,\">existing5</option> <option value=\"existing6,\">existing6</option> </optgroup> <optgroup label=\"Others added\"> //heres problem <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option> </optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; The result im getting for optgroup others added: word1, word2, word3, word4, word5, how can i get it like this: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> I have a form with 2 inputs specific to file uploads (where one day I may add more either through a dynamic layer of adding more than, or just might put 2 or 3 more fields). I can get a single file to upload without issue, but i seem to be having issues trying to get more than one at a time. What is the best way to handle this? I seem to be completely lost on this. I need to implement vanity url's on our web site, partly because they look "prettier" but more importantly because Google doesn't seem to like links that end in ".pgm" (many of our pages on our IBM iSeries are written using Websmart ILE and the program suffix is ".pgm").
I am halfway there, I think, but I am not sure if I am doing this right, and I still find taking examples of htaccess redirects and applying them to what I am trying to achieve pretty complicated.
All the page links are coded correctly and are going to the right place, but the browser is showing the resulting url, not the link that is clicked on.
Hopefully someone can help to steer me in the right direction if I explain what we have...
The resulting link needs to be:
http://www.mydomain.com/prodpage.pgm?name=750ml Orange Line Marker Spray Paint&item=41912The vanity link should be: http://www.mydomain.com/product/41912/750ml Orange Line Marker Spray PaintI have this working using the following in .htaccess: RewriteRule product/(.*)/(.*) http://www.mydomain.com/prodpage.pgm?name=$2&item=$1 [L]However... the url that shows in the browser is the resulting link. I need it to be the link that is clicked on. Any thoughts please. I have tried lots of things but nothing seems to give the desired result. Hi people, please can any of you guys help us out? I need to write some php code but i'm getting more and more confused everytime i get into php. Anyways this is what i'm trying to do on my site: I want the user to type in a company name in a text field in a very simple html form. The user hits submit buton and the text the user typed in gets sent to a php document for processing. If the user has typed in a company name that matches one of the 3 company names that i have, then the user gets sent to one page. (sucess page) If the what the user has entered into the search form does not match one of my 3 company names, then I want them to be sent to another page (error page). I know this is real simple stuff guys, but i just cant get my head round this so far, please, please help. Many thanks in advance, Marcus. I can not figure this out... <?php include 'include/config.php'; $sql = mysql_query(" SELECT * FROM logos "); while($row = mysql_fetch_assoc($sql)) { echo $row['image']; echo "<br />"; } ?> now that is printing a nice list now how can I just split it into two columns? Creating a basic MVC framework. I may confuse myself while asking this, so bare with me if this is confusing for you also... As far as i understand, the URLs are in the following format: www.example.com/controller/method/args My goal here is to not show 'method' in the URL if it's not necessary. For example, www.example.com/contact instead of www.example.com/contact/view. This is OK. I can accomplish this. But problems arise when I want to pass arguments in the URL. Say I have the URL: www.example.com/users <----- this would by default, user the controller 'users' and call default method, 'view'..just list all users. But say i want to view a user.. John. www.example.com/users/john How can I make my script know that 'john' is an argument, and not a method? The only way I can think of this is if I always have a method in the url .. like www.example.com/users/view/username/john As of now, my script breaks up the URL at / and the first element in the array is is the controller. It calls the controller with the other arguments. so www.example.com/users/john. The script would do (simplified) $controller = 'users' $controller = new $controller('john') the 'Users' class would then see if 'john' is a method. If it is, call it, if not, then call the default method (view) with john as argument... but what if I have a method called 'edit' and someone's username is edit? then www.example.com/users/edit would be a problem. So my guestion to you guy is... how do you deal with this issue? If you have www.example.com/users/edit, how do you let the script know that 'edit' is someone's username and now a method to call? Do you pass the method in the url like so www.example.com/users/edit/edit ? Or if you have worked with a framework (Zend, cakePHP, Symfony, CodeIgniter, etc), how does the framework handle it? Ideally, i would like to be able to have www.example.com/users/john instead of www.example.com/users/view/id/john Hi, I have products page which products page and I am echoing the ID of each product into a link with the description of the product as the anchor text. Code: [Select] <a href="product.php?ID=<?php echo $row['ID']; ?>" class='productlink' ><?php echo $row['description']; ?></a> However I am struggling to Get the information from the receiving 'product.php' page. The code I have on the product.php page is as follows: Code: [Select] <?php $ID = 0; if (isset($_GET['ID'])) { $ID = $_GET['ID']; } ?> <?php echo $_GET['price']; // outputs: 1 ?> However nothing is being echoed out. I just a blank screen. Am I missing like capital letters. My column is title 'ID'. Do I need to query the database in someway on the receiving page or do I just use a different GET code? Hi Guys, I'm trying to build a form which includes a file field. The idea is that it will upload the file and then email it as an attachment, I couldnt' figure that out at all so I thought I'd go with uploading the file and including a link to it in the email, however that isn't working either and I don't understand why... i'm not getting any error messages and the upload folder is set to 777. if (($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); $fileLink = $siteroot. "/upload/" . $_FILES["file"]["name"]; } } else { echo "Invalid file"; } $to = str_replace('info', 'sales', $sc_email); $subject = "Quotation request from website"; $body = "From: ".$_POST['first_name']." ".$_POST['last_name']."\n"; if ($_POST['job_title']) { $body .= "(".$_POST['job_title']." at ".$_POST['your_company'].")\n"; } $body .= "E-Mail: ".$_POST['your_email']."\n"; $body .= "Telephone: ".$_POST['your_telephone']."\n"; $body .= "Address:\n ".$_POST['your_address']." ,".$_POST['your_country']."\n\n"; $body .= "Project: ".$_POST['project_details']."\n"; $body .= "Translate to: ".$_POST['lang_target']." from ".$_POST['lang_source']."\n"; $body .= "by: ".$_POST['project_deadline']; $body .= "The text: ".$_POST['text_to_translate']; $body .= "Link to attachment: <a href=".$fileLink."> Link </a>"; Just helping me to figure out this would be enough but if anyone has a solution to the emailng as attatchment thing that would be even better. I've looked at a few tutorials but they seem a bit confusing. Thanks in advance. I'm trying to read in a file which is essentially a csv. (I have a couple of books and am a n00b faffing with sessions/cookies etc and am trying to set up an app for a local forum I'm involved with...) I originally tried fgetcsv and also reading the file in line by line (via fgets/explode) and for the most part it works. However some of the entries have a '<' character within them and whenever the script hits a line with one of these it screws up and truncates the line. I presume the '<' is attempting to redirect the data somewhere(?), but have found no way of being able to read this in whole as of yet and I dont really want to resort to processing each line character by character... An example line would be: 3p!<ph4il,Fabulous Diamond Eyes,Lizzies,Div 3C I welcome some advice to put me out of my misery on the matter Hi guys. I'm using php to randomly generate a simple math verification question. But, I'm having a hard time validating the input. Can someone please tell me what I'm doing wrong? Thank you } else if(trim($verify) != $_SESSION['UserData']['Math'][0]+$_SESSION['UserData']['Math'][1]){ $error = '<div class="error_message">Attention! The verification number you entered is incorrect.</div>'; } <?php echo "<span class='label'><span class='required'>*</span>What is ".$_SESSION['UserData']['Math'][0]." + ".$_SESSION['UserData']['Math'][1]."?</span> "; ?> <input name="verify" type="text" id="verify" size="3" value="<?=$verify;?>" /><br /><br /> I'm trying to make a script to check a files date time and if its under so many seconds long the page will refresh. here is what I've got. I've been testing the output of the date() functions but when i do the math all i get is a 0. where did i go wrong? is it just i can't do math with dates? Thanks in advanced. Code: [Select] <html><head> <meta http-Equiv="Cache-Control" Content="no-cache"> <meta http-Equiv="Pragma" Content="no-cache"> <meta http-Equiv="Expires" Content="0"> <? $proFile = "profilePics/profile.jpg"; //if ( date ("m d Y H:i:s.") - date ("m d Y H:i:s.", filemtime($proFile)) <= 00 00 0000 00:00:04 ){ //this is where the magic should happen. //echo "<meta http-equiv="refresh" content='4'>"; } ?> </head> <? echo date ("m d Y H:i:s."); echo "<br>"; echo date ("m d Y H:i:s.", filemtime($proFile)); echo "<br>"; echo date ("m d Y H:i:s.") - date ("m d Y H:i:s.", filemtime($proFile)); //only outputs 0 ?> is there a math function that give you an integer value when u divide 2 numbers? ie in 7/3 i just want 2 as a result not floating number. thanks in advance. Hello Everyone, I'm a newbie trying to improve my script below. The script works fine but I would like to add the 3 radio buttons computations enhancements Ergo, if a user chooses 'Matte Paper" a 10% would be added to the Price Quote result. If a user chooses ' Gloss Paper, a 10% would be added to the Price Quote result. If a user chooses 'Canvas" , a 20 % would be added to the Price Quote result. If someone could assist with the math or post me a helpful link it would be greatly appreciated. Thank you. Paul from Melbourne, Australia. <div style="border:dashed 1px; width:570px;"> <form method="post" action="<?php echo $_SERVER['php_SELF'];?>"> <p> 1. Enter the size (100w.x180h. cm) you want your picture printed: Width <input type="text" name="width" size="1" maxlength="3" value="0" onFocus="this.value=''; this.style.color='#ff0000';"> Height <input type="text" name="height" size="1" value="0" maxlength="3" value="0" onFocus="this.value=''; this.style.color='#ff0000';"> </p> <p> 2. Choose the printing material for your pictu <input type="radio" value="cms in Matte paper" name="material" size="3" maxlength="3" /> Matte Paper <input type="radio" value="cms in Gloss Paper:" name="material" size="3" maxlength="3" /> Gloss Paper <input type="radio" value="cms in Canvas:" name="material" size="3" maxlength="3" /> Canvas </p> <p> 3. Submit your info for our Price Quote below : <input type="submit" name="submit" value="Submit" /> or: <input type="submit" name="clear" value="Reset" /> </p> <p> 5. Our Price Quote to print your artwork sized: <?php $width = $_POST['width']; /* if artwork wider than 101 cm no quote, exits*/ if ($width >=101) {echo "Error!"; exit ;} $height = $_POST['height']; /* if artwork higher than 181 cm no quote, script exits */ if ($height >=181) {echo "Error!"; exit ;} $measurement = $_POST['measurement']; $material = $_POST['material']; $result = $width * $height; echo " $width x $height $material is: "; echo "$".number_format($result,2). "" ; ?> </p> </form> </div> Trying to get the percentage of rent for a property in php. Im completely lost .... Code: [Select] <?php $purchase = 44000; $rent = 9860; $percent = $purchase * $rent; //this is wrong, it returns 4.3 but should be over 18 echo "Percentage is {$percent}%"; ?> Hi, I am TheMeq. I am currently developing a Text-Based MMORPG in PHP/MySQL. I have quite alot of the code laid down, its just this bit that is starting to throw me a bit. I've been working on it since 8am this morning.. it is now 4:30pm and i think it's nearly there. It's just not working the way I would like. So if I was to ask for help, should I just post what code I have? I am trying to create a math equation inside a variable but I am struggling to achieve the desired result. On one php page I have this:
$x = "date('Y')"; On my main page I have linked to the above and also $description but the result I am getting is: In this classic lecture which was delivered over date('Y') - 1989 years ago,
I want to create a variable so I don't need to go back every year and change the description. Is this possible? Robert
|