Jump to content

nderevj

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

nderevj's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. My gut tells me that you should create another PHP file to process the 2nd page / step. This feeling comes from the idea of script responsibility. Similar to if you give a class, method or even a standalone function too much responsibility it becomes difficult to maintain. The same might be said for reusing the categories.php script. I also envision an efficiency issues with reusing categories.php- the logic you have when the user lands at page 1, will be re-executed for page 2. Re-executing this logic might be meaningless and a waste of resources. Lastly if you need to make a change to page 1's logic (say you discover a bug or need to add a new feature) you're most likely going to break page 2 if you re-use categories.php. If your concern is propagating the $pagename variable to the various pages Id suggest using sessions or appending the parameter onto the URL for the next page. - Nick
  2. I'm not a database expert by any means but I think a redesign of the schema might be in order. My suggestion is to create an "appointments" table that contains various appointment information (name, location, agenda / notes, date, etc). You would then query on the appointments table's date column. Something like: SELECT * FROM appointments WHERE date BETWEEN '01/10/2011' AND '01/14/2011'; The date range would be the 5 days / week you need. You also might need to have the end date 1 day later- 01/15/2011. (Excuse my lack of database skills)
  3. If you simply need an indicator (don't care that the page refreshes) you could have your "save / update" script POST back to your form (?) with an HTTP POST parameter that flags a successful save / update. Then use code (javascript ?) to show a temporary message: "Your data has been saved." You could enhance this by using an ajax solution so the page doesn't need to refresh.
  4. Close, however that will only get you the files in the current directory (not in any sub-directories). Try this: <?php $directory = 'sample'; // Replace with your starting directory $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); while($it->valid()) { if(strtolower(substr($it->getFilename(), -4)) == '.txt') { var_dump($it->key()); // Not really needed, just used for debugging chmod($it->key(), 0777); } $it->next(); }
  5. Your theory of operation sounds good. You would probably need to update your "login_process" to know that its going to be communicating with a PHP script (containing javascript). On the other hand, I think you can use javascript to access cookie data directly. If my hunch is correct then you don't need to have a PHP-Javascript file.
  6. One way to do it is to have PHP generate the HTML for each of the radio buttons. As it generates each of the buttons it would check the database to determine if the person is Male or Female. Based on this info, it would generate a "checked" button that contains the attribute: checked="checked". For example (pseudocode): $profiles = ... // Assume you retrieved all of your profiles as a collection of objects from your database foreach($profiles as $profile) { if($profile->gender == 'male') { echo '<input type="radio" name="male" value="Male" checked="checked" />'; echo '<input type="radio" name="female" value="Female" />'; } else { echo '<input type="radio" name="male" value="Male" />'; echo '<input type="radio" name="female" value="Female" checked="checked" />'; } }
  7. You actually need to create a PHP file (with a PHP extension so that it is parsed by PHP's engine). Something like: // Script's Filename: javascript_location.php (note the extension) header("content-type: application/x-javascript"); echo "document.location = {$_SESSION['fwd_page']};"; The header is needed to have PHP and the web server generate a javascript file.
  8. Anti-Moronic, you have a good point. My quick script is very inefficient. Gathering all of the data to be inserted and constructing one SQL statement would cut down on database resources. Another thought I had was using prepared statements. PDO offers them- http://us.php.net/manual/en/pdo.prepared-statements.php.
  9. A couple of things: 1) Append brackets to your select's name- drop1[]. This will tell PHP to create an array based on the submitted data. 2) Make sure your PHP code references the $_POST element with the same name, minus the brackets- $_POST['drop1'].
  10. That is a bit more involved. Have you already created the database / tables? What database are you using (mysql, mssql, sqlite, etc)? What does the database schema look like? We'll be able to help you further with these details, but in general your script will do something like: $connection = new PDO(...); // This needs to be configured to your specific database settings $lines = file('sample.txt'); foreach($lines as $line) { $data = array(); $result = preg_match('/(?P<date>\S+)\s+(?P<time>\S+ \S\S)\s+(?P<size>[\d,]+)\s+(?P<name>.*)/', $line, $data); if($result) { $sql = "INSERT into table_name (size, filename) VALUES ('{$data['size']}', '{$data['name']}')"; // Replace table_name, size, filename with the correct values from your database schema $connection->exec($sql); } }
  11. $lines = file('sample.txt'); // Replace sample.txt with the full path to your text file. foreach($lines as $line) { $data = array(); $result = preg_match('/(?P<date>\S+)\s+(?P<time>\S+ \S\S)\s+(?P<size>[\d,]+)\s+(?P<name>.*)/', $line, $data); if($result) { // Replace this line with whatever size and filename processing you need... echo $data['size'] . ";" . $data['name'] . "\n"; } }
  12. Does your list of files contain directories as well?
  13. I just noticed that your trying to parse a text file that has the contents of a directory. My script actually reads files from the file system. My mistake. Let me post another solution.
  14. $inputDir = dirname(__FILE__); // Replace with your starting directory... $dir = new DirectoryIterator($inputDir); foreach($dir as $fileinfo) { if(!$fileinfo->isDot()) { // Replace this line with whatever size and filename processing you need... echo $fileinfo->getSize() . ';' . $fileinfo->getFilename() . "\n"; } }
  15. I might not be understanding your question, but max_execution_time is defined as: "sets the maximum time in seconds a script is allowed to run before it is terminated by the parser." (php.net) So if you have code that takes 30 seconds to execute (does many calculations), setting max_execution_time to 5 would mean that after 5 seconds the script will "fail". What it sounds like is that you need to set max_execution_time to be longer than the time it takes to perform all of your script's calculations. Try setting it to something like 40 or 60, or figure out a way to optimize your code so that it executes faster. - Nick
×
×
  • 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.