oriental_express Posted November 27, 2008 Share Posted November 27, 2008 hi there for my final year project I'm aiming to build a php script shell to use as an expert system ( I got a feeling this is gonna be difficult, VERY ) The idea is that i create txt / csv file with questions like 1, "How old are you?" , "10", 2 ,"11", 3 , ( where 2 and 3 is the next set of nodes ) 2, "Do you like sports?", "yes", 4 , "No", 5 3, "Do you like music?, "Yes", 6 , "No" , 7 At the end of the questions it will somehow produce some html files i've already created which would be the knowledge. Using this file I need to create a script that supposedly will use the fgetcsv function. I know in the script will need some html code to produce check boxes for the questions and choices. So basically this script can be used by anyone that doesn't know how to program. All the user would have to do is create a decision tree and edit the txt file. I will be using this for my own project. This is the spec ??? My project handing deadline is 1st May 2009 so ideally I want to be able to finish this by about 1st April for evaluation. The earlier the better. I've been trying to study php but I just can't seem to piece it together and don't know where to start. I would like some help please. I not asking for you guys to do it for cause I want to prove to myself I can do this. What I would like is if you guys could kindly give me some pointers such as areas I should look at more. I'm prepared to work hard for this, i just need a tiny bit of help Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/ Share on other sites More sharing options...
Mchl Posted November 27, 2008 Share Posted November 27, 2008 What can you do already? (I mean, how much do you know about PHP) Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700475 Share on other sites More sharing options...
oriental_express Posted November 27, 2008 Author Share Posted November 27, 2008 What can you do already? (I mean, how much do you know about PHP) Gonna be honest, I probably can do stuff like IF and Else statements and echoing replies using radio buttons. But thats too simple. I probably can understand the basics of it. I assume its not enough ? Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700480 Share on other sites More sharing options...
Mchl Posted November 27, 2008 Share Posted November 27, 2008 How about using $_POST and $_GET? Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700498 Share on other sites More sharing options...
oriental_express Posted November 27, 2008 Author Share Posted November 27, 2008 How about using $_POST and $_GET? yes i think i would be comfortable with that Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700500 Share on other sites More sharing options...
Mchl Posted November 27, 2008 Share Posted November 27, 2008 Not bad. You will use a lot of these Sessions? http://www.phpfreaks.com/tutorial/sessions-and-cookies-adding-state-to-a-stateless-protocol Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700506 Share on other sites More sharing options...
oriental_express Posted November 27, 2008 Author Share Posted November 27, 2008 Not bad. You will use a lot of these Sessions? http://www.phpfreaks.com/tutorial/sessions-and-cookies-adding-state-to-a-stateless-protocol Not too sure about this but I will do some learning and get back to you. Thanking for taking your time to help me ! Much appreciated ! Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700511 Share on other sites More sharing options...
oriental_express Posted November 27, 2008 Author Share Posted November 27, 2008 1, "How old are you?" , "10", 2 ,"11", 3 , ( where 2 and 3 is the next set of nodes ) 2, "Do you like sports?", "yes", 4 , "No", 5 3, "Do you like music?, "Yes", 6 , "No" , 7 Could someone confirm that this is the correct way write the questions in a txt / csv file for what i want to do ? Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700665 Share on other sites More sharing options...
Mchl Posted November 28, 2008 Share Posted November 28, 2008 Use quotes around each field. So you want it like this: Question 1: How old are you? is displayed. There are 2 answers '10' and '11' If user chooses '10' he gets to question 2 If user chooses '11' he gets to question 3 If so, I think it's pretty ok Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700846 Share on other sites More sharing options...
laffin Posted November 28, 2008 Share Posted November 28, 2008 I think so, thats how I understand it.... Complicated not at all, just follow Mchl's advice learn to work with forms. and shud be able to crank it out in a day or two Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700892 Share on other sites More sharing options...
Mchl Posted November 28, 2008 Share Posted November 28, 2008 He also needs a way to edit the CSV file. This might be the most complicated think in all this... give it two more days Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700909 Share on other sites More sharing options...
laffin Posted November 28, 2008 Share Posted November 28, 2008 notepad does great But I prefer a lil more power in my editor (UltraEdit) But there are some pretty good freeware editors as well.... To me looks like the csv isnt gonna be changed after initial, since its a school project and wasnt mentioned in first post. seems like a fun project if he were to go all out, add in an editor / updateable.. reminds me of an old program that came on Apple DOS Animals.bas. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700924 Share on other sites More sharing options...
Mchl Posted November 28, 2008 Share Posted November 28, 2008 All the user would have to do is create a decision tree and edit the txt file. As I understand it, editing tool should be part of the script. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-700935 Share on other sites More sharing options...
oriental_express Posted November 28, 2008 Author Share Posted November 28, 2008 Thank you for your replies. I want to clarify something. Although a text editor would be great to implement, I want to keep it simple as possible for me to create so that the a user would only have to edit a txt file in notepad (user would then have to upload to the folder) When I say the user would have to draw his own decision. Thats the easy bit because all they have to do is type in the questions into the txt file and follow the format. When you guys say I have to work with forms. Is using radio buttons a type of form ? Its hard for me to know where to start. I think I should be looking at fgetcsv to read a line. How would I create the php file to read the txt file to produce the questions and possible answer ready to go on to the next. If someone could show me examples I'd be very happy. I just want everyone to know, I'm not looking for handouts because I need to do this for myself. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701136 Share on other sites More sharing options...
Mchl Posted November 28, 2008 Share Posted November 28, 2008 Radio buttons are in fact a type of form Yes, fgetcsv seems to be a good choice. I think your script could work something like this 1. Load line 1 from file. Display question in form. 2. Answer gets to script through $_POST variable. Store answer in $_SESSION 3. Scripts uses fgetcsv to load line number equal to answer given. Display question in form... 4. When there are no more questions, show results (from $_SESSION) Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701172 Share on other sites More sharing options...
oriental_express Posted November 28, 2008 Author Share Posted November 28, 2008 Thanks for reply Mchl Yes I had something similar in mind but had no idea to write it down in php talk So this means I have to use arrays right ? I think im to start here with <?php $file = fopen("questions.csv","r"); print_r(fgetcsv($file)); fclose($file); ?> But that alone only reads the first line where abouts do I go from taking the 1st array (which would be the questions, where 0 is the question number) ? is there such thing like <?php $file = array(2); ?> ( I tried ) which will print the question, that is good but what about the choice ? How does map the choice to radio buttons using arrays ? What will happen when a questions has 3 choice of answers ? Can the script know to only "print" 2 radio buttons for a question with only 2 choices ? As far as I know creating a form uses HTML so I think it wont know Which makes me think of producing questions with only 2 answers. I'm probably wrong Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701217 Share on other sites More sharing options...
Mchl Posted November 28, 2008 Share Posted November 28, 2008 $file = fopen("questions.csv","r"); $line = fgetcsv($file); now you should have first line of your file stored in an array called $line Can you think of a way to load whole file into an array called $questions so that $questions[0] will have first line stored $questions[1] will have second line stored etc? Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701223 Share on other sites More sharing options...
oriental_express Posted November 28, 2008 Author Share Posted November 28, 2008 $file = fopen("questions.csv","r"); $line = fgetcsv($file); now you should have first line of your file stored in an array called $line Can you think of a way to load whole file into an array called $questions so that $questions[0] will have first line stored $questions[1] will have second line stored etc? Can you please explain why I need an array called $line ? I dont understand I can't think of a way because I've never been taught to think like a programmer. We only did a brief unit on php with CRUD thats it, didnt really use arrays. Does it mean there will be a nested array if your suggesting I load the whole file into an array called $questions ? Thanks for keep up with me ! Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701232 Share on other sites More sharing options...
Mchl Posted November 28, 2008 Share Posted November 28, 2008 You have to load data from your file, to be able to work on it. (Nested) array seems to be the most optimal way to store it in your program. The way you had it in your code print_r(fgetcsv($file)); you were just displaying first line from the file, without storing it anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701236 Share on other sites More sharing options...
oriental_express Posted November 28, 2008 Author Share Posted November 28, 2008 You have to load data from your file, to be able to work on it. (Nested) array seems to be the most optimal way to store it in your program. The way you had it in your code print_r(fgetcsv($file)); you were just displaying first line from the file, without storing it anywhere. When you say load, I assume you mean load data into memory ? I've saved the file as <?php $file = fopen("questions.txt","r"); $line = fgetcsv($file); fclose($file); ?> but this does nothing, just give me a bunch of errors. I assume cause I'm not telling it to do anything else. So would the next bit of php code tell it to display the array but position 1(which is the question) ? Would it be something like <?php echo $line[2]; ?> Hope im not making a fool of myself. Am i going the right direction ? thank Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701241 Share on other sites More sharing options...
Mchl Posted November 28, 2008 Share Posted November 28, 2008 Try this: <?php $file = fopen("questions.txt","r"); $line = fgetcsv($file); print_r($line); fclose($file); ?> It should print contents of $line BTW: what errors do you get? Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701300 Share on other sites More sharing options...
oriental_express Posted November 28, 2008 Author Share Posted November 28, 2008 My mistake, file name was changed Yes it works now questions.txt 1, "How old are you?" , "10", 2 ,"11", 3 2, "Do you like sports?", "yes", 4 , "No", 5 3, "Do you like music?", "Yes", 6 , "No" , 7 4, "www.aaa.com" 5, "www.bbb.com" 6, "www.ccc.com" 7, "www.ddd.com" Yes it prints contents of line. Array ( [0] => 1 [1] => How old are you? [2] => 10 [3] => 2 [4] => 11 [5] => 3 ) Am I correct in only wanting it to only print the question this time with <?php echo $line[1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701313 Share on other sites More sharing options...
oriental_express Posted November 28, 2008 Author Share Posted November 28, 2008 <?php $file = fopen("questions.txt","r"); $line = fgetcsv($file); print_r($line); echo $line[1]; fclose($file); ?> I have tried the above and the display is Array ( [0] => 1 [1] => How old are you? [2] => 10 [3] => 2 [4] => 11 [5] => 3 ) How old are you? Ok I actually feel like this is progressing now, well happy ! Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701317 Share on other sites More sharing options...
oriental_express Posted November 28, 2008 Author Share Posted November 28, 2008 I've done something like this <?php $file = fopen("questions.txt","r"); $line = fgetcsv($file); echo $line[1]; fclose($file); ?> which only displays the question. How would i connect certain values in the arrays to link to a radio button ? is this where the sessions come in ? Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701319 Share on other sites More sharing options...
Mchl Posted November 28, 2008 Share Posted November 28, 2008 not yet now you should learn how to create a html form you should do something like this <?php $file = fopen("questions.txt","r"); $line = fgetcsv($file); fclose($file); ?> <html> <head></head> <h1>Question: <?php echo $line[1]; ?></h1> <body> <!-- here you should create your form using html tags </body> </html> Note how the question is being output within html. I just reopen <?php tag and use echo. You can do the same with any variable. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/#findComment-701322 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.