Jump to content
#StayAtHome ×

Archived

This topic is now archived and is closed to further replies.

oriental_express

Final year project, please point me in the right direction

Recommended Posts

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  :)

 

Share this post


Link to post
Share on other sites

What can you do already? (I mean, how much do you know about PHP)

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites

How about using $_POST and $_GET?

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

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.

 

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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)

 

 

 

 

Share this post


Link to post
Share on other sites

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 )  :o

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

Share this post


Link to post
Share on other sites

$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?

Share this post


Link to post
Share on other sites

$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 !

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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]; ?>

 

 

Share this post


Link to post
Share on other sites

<?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 !

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×
×
  • 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.