Jump to content

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

 

  • Replies 115
  • Created
  • Last Reply

Top Posters In This Topic

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 ?

 

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 !

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 ?

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

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.

 

 

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.

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)

 

 

 

 

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

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

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

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.

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

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

 

 

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

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 ?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


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