Jump to content

Increment the value of CSV via form


ibz786

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.