[email protected] Posted August 16, 2010 Share Posted August 16, 2010 Hey guys! I require some help in overall planning/how to do this school thingy. I need to create a website which can save client consultations, view and edit the data. So far I have created login, home, data entry and data viewing pages which are working together nicely with supporting php login, data entry, and data viewing scripts. Right now all data is saved into one file. I need to modify it so that there is one file per client, and each file is full of all of the clients dated consultations. I think I can do this by appending each consultation record to the clients file, but I have no idea how I could edit only one part of the record without deleting the whole thing or just appending it to the end of the file. I'm fairly certain an array or two is what I need to use, but I'm not completely sure. Could you please give me an outline of the functions I am going to need to learn? Thanks for any help you can give me Link to comment https://forums.phpfreaks.com/topic/210844-arraying-it-up/ Share on other sites More sharing options...
kickstart Posted August 16, 2010 Share Posted August 16, 2010 Hi Any reason you don't want to use a database? All the best Keith Link to comment https://forums.phpfreaks.com/topic/210844-arraying-it-up/#findComment-1099781 Share on other sites More sharing options...
[email protected] Posted August 16, 2010 Author Share Posted August 16, 2010 Hi, I don't know how to create a database. I know it would be the best option for a system with an undefined size, but it's just a school project I have to do this week for learning php. Wouldn't storing text files be easier? thanks for replying Link to comment https://forums.phpfreaks.com/topic/210844-arraying-it-up/#findComment-1099783 Share on other sites More sharing options...
kickstart Posted August 16, 2010 Share Posted August 16, 2010 Hi A database would (to me) by far easier. However if this is a project to teach you how to write php then that might not be what is required. Writing to a flat file and appending data to the end of it is easy. However reading it in and splitting it up is likely to be non trivial. Doing it manually would mean reading each line of the file and deciding what to do with it. You would need to cope with people entering carraige returns / line feeds which would cause a new line in the file (probably best to convert these to something else to avoid them affecting the file you save them to). In php an array can contain other arrays, and can also be used almost as a structure. So you could have an array of reports, each of which is an array having a field for the date, and any other basic info, and maybe an array within that array for comments. Just built up. As such you could possibly store the full array in the file. Never tried it but I think this might be best done using serialize to turn it into one large chunk which can be read in later. Can't really say anymore for now without knowing more of what you want to store and whether a database is out of the question. As an aside, do you have any way of running the php scripts on your computer or do you have to write it and upload it at a later date? All the best Keith Link to comment https://forums.phpfreaks.com/topic/210844-arraying-it-up/#findComment-1099791 Share on other sites More sharing options...
[email protected] Posted August 17, 2010 Author Share Posted August 17, 2010 Sorry, I know I'm doing a crappy job at explaining the situation... If I was confident I could learn how to create a database within the next 3 days, I would. But I'm not. So here is what I was thinking of doing, maybe. The information for each patient will be accessed using an associative multidimensional array. The first level stores the each entire consultation as an element within the associative array using the date of each consultation as the index. The second level stores each piece of information regarding the specific consultation as an element of the associative array. The index will be the variable name. e.g. $Date, $Time, $Length, $Charge, $Prescription, $Medical_Charges and $Notes. Shorter. . . One text file per client. Multiple consultations per client file separated by the \n delineator. Each record within a consultation record is separated by the \t tab notation thingy. I really don't know how to explain an array well, but the main thing I think I am going to have a probem with is editing one of the existing records. After pulling up the consultation from the flat into an array, how would I replace just that consultation without deleting everything else in the file or appending it to the bottom... Thank you extemely superly much for your help Link to comment https://forums.phpfreaks.com/topic/210844-arraying-it-up/#findComment-1100104 Share on other sites More sharing options...
kickstart Posted August 17, 2010 Share Posted August 17, 2010 Hi It is certainly possible to store the details as you suggest, but be aware that doing it that way you need to manually read and write it, and cope with notes containing tabs (ie, an extra tab in a tab delimited file could cause chaos). Has the plus point that the resulting file can be easily opened and read . Using serialize / unserialize is possibly simpler, but has the down side that the resulting files cannot be simply read in a text editor. An example of how to do it using serialize follows. All this script does is generate a new random row each time it is called and appends it on the end, then displays all the rows. It does require the "PatientDetails" subdirectory to already exist. <?php // Only do anything if the patient id is passed if (isset($_REQUEST['Patient'])) { // Get patient id $Patient = $_REQUEST['Patient']; // Set up patient array $PatientArray = array(array('EventDate'=>'','EventDetails'=>array('Date'=>'','Time'=>'','Length'=>'','Charge'=>'','Prescription'=>'','Medical_Charges'=>'','Notes'=>''))); // Check it file already exists for this patient (file name is the patient id followed by .ppp, stored in the PatientDetails subdirectory of the directory this script is in). if (file_exists("PatientDetails/$Patient.ppp")) { // Read the entire file and unserialize and store in the PatientArray $PatientArray = unserialize(file_get_contents("PatientDetails/$Patient.ppp")); } // Create a random new record on the end of the PatientArray $EventDetails = array('Date'=>date('l jS \of F Y h:i:s A'),'Time'=>'','Length'=>'','Charge'=> rand(1,1000),'Prescription'=>'Something','Medical_Charges'=>rand(1,1000),'Notes'=>'SomeNotes'); $PatientArray[] = array('EventDate'=>date('l jS \of F Y h:i:s A'),'EventDetails'=>$EventDetails); // Display all the patient details echo "<table>"; echo "<td>EventDate</td>"; echo "<td>Date</td>"; echo "<td>Time</td>"; echo "<td>Length</td>"; echo "<td>Charge</td>"; echo "<td>Prescription</td>"; echo "<td>Medical_Charges</td>"; echo "<td>Notes</td>"; echo "</tr>"; foreach($PatientArray AS $aPatientVisit) { echo "<tr>"; echo "<td>".$aPatientVisit['EventDate']."</td>"; echo "<td>".$aPatientVisit['EventDetails']['Date']."</td>"; echo "<td>".$aPatientVisit['EventDetails']['Time']."</td>"; echo "<td>".$aPatientVisit['EventDetails']['Length']."</td>"; echo "<td>".$aPatientVisit['EventDetails']['Charge']."</td>"; echo "<td>".$aPatientVisit['EventDetails']['Prescription']."</td>"; echo "<td>".$aPatientVisit['EventDetails']['Medical_Charges']."</td>"; echo "<td>".$aPatientVisit['EventDetails']['Notes']."</td>"; echo "</tr>"; } echo "</table>"; // Serialize the PatientArray $PatientDetails = serialize($PatientArray); // Open the relevant patient details file and write the serialized patient array to it $somefile = fopen("PatientDetails/$Patient.ppp",'wb'); fwrite($somefile,$PatientDetails); fclose($somefile); } else { echo "A patient id must be passed"; } ?> Doing something similar to this you can just update existing array members once it has been read in. All the best Keith Link to comment https://forums.phpfreaks.com/topic/210844-arraying-it-up/#findComment-1100241 Share on other sites More sharing options...
[email protected] Posted August 18, 2010 Author Share Posted August 18, 2010 Thank you times a BILLION for this! It's really helped me out of a rut. Although I must say, it is a little worrying that you are able to be up and write all that before 07:16:43 AM! :S Hahaa Thanks! Link to comment https://forums.phpfreaks.com/topic/210844-arraying-it-up/#findComment-1100631 Share on other sites More sharing options...
kickstart Posted August 18, 2010 Share Posted August 18, 2010 Although I must say, it is a little worrying that you are able to be up and write all that before 07:16:43 AM! :S Hahaa The wonder of time zones! I am in the UK so wrote that about mid day yesterday. All the best Keith Link to comment https://forums.phpfreaks.com/topic/210844-arraying-it-up/#findComment-1100635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.