English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

OBJECTIVE: When a visitor goes to index.php and clicks the enter button, it will add the input from "field1" into the $dAta array. AND, this is the most important, it will save the entries into the $dAta array.

CURRENT: This is the code that i have for now. When i type something into "field1" and click enter, i see the new entry into the array with the print_r. But when i exit and go back to open the index.php the added entry is not there.

THEORY: Any ideas??? Does this require the use of f.open, f.write. f.close? Im thinking something along the lines of scanning the existing array into a temporary array, add then entry from field 1, then write the new array to a new php file? Thanks.

---------CODE SECTION BELOW----------
$dAta = array(1 => "961204","961205","961206",);
?>





$dAta[] = $_POST[field1];
print_r($dAta);
?>

2006-11-24 04:57:21 · 3 answers · asked by f1avor_f1av 3 in Computers & Internet Programming & Design

3 answers

You actually would want to use a database for something like this, or if it is just a per user basis, a cookie.

PHP doesn't have built in memory without using one of these options. You could use the file functions, but those functions lock the text file so noone else can read/write to that text file until the lock is released. This isn't an issue for small apps that only one person is likely to use at a time, but for web apps that multiple users can be on concurrently, it becomes an issue. Even if the lock is only for a moment, as more users are on the site the likelihood of it being locked when someone else is trying to use it will increase.

2006-11-24 05:10:21 · answer #1 · answered by John J 6 · 0 0

You need to add your array to a session variable or some other permanent storage system, because PHP is without state. Additionally, you aren't really cuing the array to expand on post.

session_start();
if(!isset($_SESSION['dAta'])) {
$_SESSION['dAta'] = array("961204","961205","961206");
}

if(isset($_POST['submit'])) {
$arr = $_SESSION['data'];
$arr[] = $_POST['field1'];
$_SESSION['dAta'] = $arr;
print_r($_SESSION['dAta'];
}
?>






Anyplace you want to use the session variable, make sure you have session_start() at the top of that page.

2006-11-24 08:39:52 · answer #2 · answered by Anonymous · 0 0

For the sorting, you could do this contained in the question purely append it on the right of ur question "order by 'YOUR_DATE_COLUMN'"; to modify the date formate for reveal purpose, use date("F d, Y", mktime(0,0,0,$nMonth, $nDay, $nYear)); the position $nMonth, $nDay, $nYear will be from the date cost in database. you could might want to fetch this stuff from that date field.

2016-11-29 10:29:26 · answer #3 · answered by brenneman 4 · 0 0

fedest.com, questions and answers