ibz786 Posted February 26, 2011 Share Posted February 26, 2011 I have a textfile called 'houses.txt': HA11QS, 200, house1.jpg, 4 HA22BR, 280, house2.jpg, 10 HA33AB, 390, house3.jpg, 3 HA44CD, 320, house4.jpg, 8 I have a php file which puts all this into an array and using a form, when the user enters a value e.g. 300 it, displays all the houses equal to or less than that. This works fine <?php if (isset($_POST['price'])) { $filename = "houses.txt"; $fileOpen = fopen($filename, "r"); $max = $_POST['price']; $rowsArr = file ($filename); foreach ($rowsArr as $row) { $lineDetails = $row; $item_array = explode (",", $row); if (((int) $item_array[1]) <= $max) { echo("<form action='visit.php' method='post'>"); echo("Post Code - " . $item_array[0]. "<br>"); echo("Price - " . $item_array[1]. ",000 <br>"); echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $item_array[3]. "<br>"); echo("<input type='checkbox' name='mybox'>"); echo("<input type='submit' value='Visit Property'>"); echo("</form>"); } } fclose($fileOpen); } ?> However what i need to do is using a form, (Form values which i have just recently added to the code supplied above) Is that when a user clicks on property, it returns the house or houses selected with the checkboxes and the number of houses visits are incremented by 1 each time All i have is: <?php if (isset($_POST['mybox'])) { $filename = "houses.txt"; $fileOpen = fopen($filename, "r+"); $rowsArr = file ($filename); foreach ($rowsArr as $row) { $lineDetails = $row; $item_array = explode (",", $row); $house_visit = $item_array[3]; $house_visit++; echo("Post Code - " . $item_array[0]. "<br>"); echo("Price - " . $item_array[1]. ",000 <br>"); echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $item_array[3]. "<br>"); echo("<br>"); } fclose($fileOpen); } ?> But it really doesnt work, if anyone can help me i would be grateful Thanks Link to comment https://forums.phpfreaks.com/topic/228934-increment-the-value-of-csv-via-form/ Share on other sites More sharing options...
mattal999 Posted February 26, 2011 Share Posted February 26, 2011 Well, you aren't echoing the correct variable. $house_visit = $item_array[3]; $house_visit++; echo("Post Code - " . $item_array[0]. "<br>"); echo("Price - " . $item_array[1]. ",000 <br>"); echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $house_visit. "<br>"); echo("<br>"); But then you need to re-save the file with that new variable included. Link to comment https://forums.phpfreaks.com/topic/228934-increment-the-value-of-csv-via-form/#findComment-1180051 Share on other sites More sharing options...
ibz786 Posted February 26, 2011 Author Share Posted February 26, 2011 Hmm thats not really what i need Ive read somewhere, that i need to have both the "r+" and then the fwrite function However im really not sure how to handle this, can any one help me please? Thanks Link to comment https://forums.phpfreaks.com/topic/228934-increment-the-value-of-csv-via-form/#findComment-1180080 Share on other sites More sharing options...
ibz786 Posted February 27, 2011 Author Share Posted February 27, 2011 Hmm ive tried alot of things but im having now luck, is anyone able to help me with this If you are then i would be extremely grateful thanks Link to comment https://forums.phpfreaks.com/topic/228934-increment-the-value-of-csv-via-form/#findComment-1180172 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.