![](https://forums.phpfreaks.com/uploads/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
wildteen88
-
Posts
10,480 -
Joined
-
Last visited
Never
Posts posted by wildteen88
-
-
Then replace the spaces with an underscore (_) instead?
-
On line 67 in form_proceessed2011-NEW.php there is some form of output therefore header() will not work. The solution would be to modify your script so there is no output before the use of the header() function. Or for a simple fix revert to using output buffering.
-
Look for PHP validation tutorials. There isn't a built in function which will do it all for you.
-
Does the folder Changes exist within the Projects folder? fwrite will not create the directory structure if it doesn't exist. You'll first need to create the directory structure and then create/write to the file.
Also make sure the folder Changes if it exists is not set to Read Only in Windows.
-
The only way I got it to work is to use type casting. Change the foreach loop to
foreach($XML->xml->establishments->land as $value) { $key = (int) $value->id; $cost = (int) $value->cost; $income = (int) str_replace(array('$', ','), '', (string) $value->income); $properties[ $key ]['cost'] = $cost; $properties[ $key ]['income'] = $income; $ratios[ $key ] = $income / $cost; }
-
I didn't test my code using XML data. I used some hard coded values. However this shouldn't make a difference. Could I see how your XML file is constructed?
-
You should be replacing the spaces in PHP when outputting your links. Not mod_rewrite.
-
The only places you use explode on are lines 58 and 69
58. $temp = explode(' ', $this->numbers[$j]); 59. for ($a =0; $a <$temp.length; $j++); ... 69. $temp1 = explode(' ', $this->numbers[$j]); 70. for ($a =0; $a <$temp1.length; $j++);
On lines 58 and 69 you use explode to get the individual numbers from $this->numbers[$j]. But you are not doing anything with them afterwards (lines 59 and 70). The for loop is not constructed incorrectly. Variables do not have properties such as .length.
-
Is it possible to open a file in append mode only if the file exists, otherwise open it in write mode?
Why when that is what append mode does. Quote from the manual
Mode 'a'Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
-
Yea sorry, I posted in the wrong code earlier. I tried to edit it before you read my reply.
-
Templates as in what?
-
only problem is your code is quite different from mine, and at present because I am learning I don’t want to simply cut and paste someone else’s code
That fine. I just through you may have forgotten about your previous post as you didn't reply to it last time.
I want them placed in an array in that format, not splitting them up into single integers?If you want to add a string of numbers, eg
$numbers = '1, 3, 18, 27';
And you want to add them into an array you can simply do
$array[] = $numbers;
That will add the string of numbers to the array.
-
You can use a script called PHPMailer for sending emails with attachments. Basic usage example:
-
Just replace the HTML with
header('Location: thankyou.php');
However you will want to remove this gap
?> <?php
Before using that function. header() will not work if there is any kind of output beforehand.
-
There is nothing wrong with building a CMS in PHP. There a probably thousands of content management scripts that where made with PHP, the most popular being Joomla and WordPress and few others.
-
Rather than assign each properties values to seperate variables ($id10_code $id10_value $id10_id etc). You'll want to assign them to an array instead within your foreach loop
$key = $value->id; $properties[ $key ]['name'] = $value->name; $properties[ $key ]['cost'] = $value->cost; $properties[ $key ]['income'] = $value->income;
After calculate the ratio and add it to a separate array for storing the ratios. When adding the ratio to the array assign its key as the property id eg
$ratios[ $key ] = $value->income / $value->cost;
Now after the foreach loop you then use max to get the highest ratio from the $ratios array.
$highestRatio = max($ratios); // get the highest ratio
Next use array_search to get property details for the highest ratio.
$propertyKey = array_search($highestRatio, $ratios); // get the property key $property = $properties[ $propertyKey ]; // get the property with the highest ratio
$property will be associative array of the properties details (name, cost, income).
Complete code
$XML = simplexml_load_string("property_list.xml"); $ratios = array(); $properties = array(); foreach($XML->xml as $value) { $key = $value->id; $properties[ $key ]['name'] = $value->name; $properties[ $key ]['cost'] = $value->cost; $properties[ $key ]['income'] = $value->income; $ratios[ $key ] = $value->income / $value->cost; } $highestRatio = max($ratios); // get the highest ratio $propertyKey = array_search($highestRatio, $ratios); // get the properties ID $property = $properties[ $propertyKey ]; // get the property with the highest ratio echo $property['name'] . ' has the best ratio of ' . $highestRatio;
-
So you only want to calculate the ratios with the properties that have the id of 10, 12 and 16? Or do you want to do it for all properties within property_list.xml?
-
Without seeing your code how you are getting the cost/income and calculating the ratio I cannot provide you a better answer other than what I posted above. This is what you will need to do
add all the ratios your script calculates into an array then use max which will pick the highest ratio from the array
-
-
-
Basically add all the ratios your script calculates into an array then use max which will pick the highest ratio from the array
-
Where is $allwordsgeneral defined?
-
Im going to PM you wildteen
No point I don't read PM's. If you need help post it in the forums.
-
Use an if which compares the two variables
if($FirstRatio > $SecoundRatio) echo $FirstRatio; else echo $SecoundRatio;
RE: REDIRECT PAGE - 05.22.11
in PHP Coding Help
Posted
Have look at the manual on output buffering.