Jump to content

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

No... I mean, that's where you should use one of them.

 

Like: "It's your big chance, your five minutes!" :D

 

lol ok ok i get it now. Too focused on php kinda forgetten my sense of humour. Last time we discussed that the page can call upon itself if I leave the form action blank

 

<FORM action="" method="post">

 

Would you say I just open some php tags perhaps up above the form and attempt to code it ? like so

 

<?php

 

?>

 

 

<FORM action="" method="post">

Share this post


Link to post
Share on other sites

Yeah. That's good idea.

 

Have all (or most) of your script at the beginning of your file, and html at the bottom. This way you're less prone to make errors.

Share this post


Link to post
Share on other sites

Yeah. That's good idea.

 

Have all (or most) of your script at the beginning of your file, and html at the bottom. This way you're less prone to make errors.

 

Ok ok let me see what I can do.  I'll probably come back with some cowboy code or something ... anyways here goes (into the unknown) :D Thanks for your support.

Share this post


Link to post
Share on other sites

Hi again

 

for some reason this does not work for me

 

 
<?php 
if ($quest[$1] [3] == $_POST['ans']){
$i = $i + 1;
} elseif ($quest[$1][5] == $_POST['ans']){
$i = $i + 2; 

I get this

Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in C:\wamp\www\Tree\tree.php on line 19

any ideas without tell me the answer yet ? thanks
}
?>

Share this post


Link to post
Share on other sites

if ($quest[$1] [3] == $_POST['ans']){

 

You sure you want $1 here? :P

 

 

Share this post


Link to post
Share on other sites

if ($quest[$1] [3] == $_POST['ans']){

 

You sure you want $1 here? :P

 

 

 

Yes sorry I placed a 1 there but its really an i because I don't want to be seen as cheating when I do the submissions. But it still does not work. nothing happening

Share this post


Link to post
Share on other sites

Show as your full script

Share this post


Link to post
Share on other sites

Here you are :D

 

<?php

$file = fopen("questions.txt", "r");
while (($data = fgetcsv($file, 1000, ",")) !== FALSE) 
{
   $questions[]= $data;
}
fclose($file);
//foreach($questions as $quest)
//{
//echo $quest[1];
//}
$i = 0;

?>

<?php

if ($questions[$i][3] == $_POST['answer']){
$i = $i + 1;
} elseif ($questions[$i][5] == $_POST['answer']){
$i = $i + 2; 
}

?>

<html>
<head></head>
<h1>Question: <?php echo $questions[$i][1]; ?></h1>   
<body>

<FORM action="tree.php" method="POST">
<input type="radio" name="answer" value="<?php $questions[$i][3]; ?>"> <?php echo $questions[$i][2]; ?>
<br>
<input type="radio" name="answer" value="<?php $questions[$i][5]; ?>"> <?php echo $questions[$i][4]; ?>

<INPUT TYPE=SUBMIT VALUE="submit">
</form>
</body>
</html>

Share this post


Link to post
Share on other sites

You have something lacking in here:

 

<input type="radio" name="answer" value="<?php $questions[$i][3]; ?>">

 

Share this post


Link to post
Share on other sites

You have something lacking in here:

 

<input type="radio" name="answer" value="<?php $questions[$i][3]; ?>">

 

 

its the echo right ? Woo hoo yesssssssss it works ! I feel ike i can breathe now

*does the chicken dance*  ;D

Share this post


Link to post
Share on other sites

I think my next step is to go through a few questions and as the user gets near the end the perhaps offer a solution.

Do you think its easier to use a solution as text or an html file ? What easier interms of getting something to appear ?

 

BTW will i still be using sessions ? From what it seems , it looks like i wont (correct me if im wrong ?)

Share this post


Link to post
Share on other sites

And also store the answers (if you want to store them)

 

Why not have a php script, that will load a solution from txt file and display it as HTML :P

Share this post


Link to post
Share on other sites

Sessions should be used to track what question they are on so they can't go back

 

Hi there, thanks for you reply umm I would like to know why the can't can't go back. I've been testing it and my browser lets me go back to see the previous question ?

 

And also store the answers (if you want to store them)

 

Why not have a php script, that will load a solution from txt file and display it as HTML :P

 

When you say store answers, that i dont understand, do you mean store clicks they have done ? and if they return to the page it will show the last question they were on ?

 

Is there a way to load a HTML file ? using the text file if i placed in the address www.etc.com  ? I just want to know if it's possible so i don't try and do something i cant. No answers please as usaul :)

Share this post


Link to post
Share on other sites

You mean no direct answers I suppose? :P

 

If you want the users to be able to go back or not, is up to you. You could use sessions to forbid them.

 

Also, you might use sessions, so that you can save all the answers a user have given to a file, in order to.. I don't know... analyze them later or something. If you don't need that... you probably will not need sessions at all.

 

Yes, you can load a txt file (and HTML is just a txt file) from the url address PROVIDED that your server allows that. You have to check if allow_url_fopen is enabled.

 

There's one more thing missing from your script. You'll see once you have more questions in your file.

Share this post


Link to post
Share on other sites

Yep no direct :D

 

" Also, you might use sessions, so that you can save all the answers a user have given to a file, in order to.. I don't know... analyze them later or something. If you don't need that... you probably will not need sessions at all. "

 

Good point mate. I think i do want that. To perhaps tailor my expert system :)

 

There's one more thing missing from your script. You'll see once you have more questions in your file.

 

I have no idea right now but yeah.... am gonna work on it

This script is farrrrrrrrr from finished ! I still need to work with

" if theres no element echo element 1 ( the html file url ) Something like that

Am I going along the right lines ?

 

Thanks again. !

 

 

Share this post


Link to post
Share on other sites

Yeah. Basically you have to recognize, if it is the first question, or later so that you can actually get farther that second question :)

Share this post


Link to post
Share on other sites

Hello there again. Been so busy with baby etc, loss alot of sleep grrr

 

I've been playing around with the script and your right, how come it doesn't go past the second question ? even though $i is assigned the number 2 and if you select it again why does it not add 2 to it again ?

 

I've tried to work around it by doing something like

 

 <?php
if ($questions[$i][3] == $_POST['answer']){

// $i = $i + 1; //$questions[$i][3];
$i = $questions[$i][3] == an element in $questions[$i];
// trying to do something like that but I know the value in the element is just a value and not an integer ? does that make sense ?


} elseif ($questions[$i][5] == $_POST['answer']){
$i = $i + 2; 
}

?>

 

I would like some hints to what im doing wrong ? and again no direct answers please :)

Share this post


Link to post
Share on other sites

Remember that PHP script is running once, and then forgets all about its past. When you select answer for a question, you run another instance of your script, that doesn't remember, what $i was last time it run.

 

Sorry, I'm busy more than usual tonight (is night here) so I might not reply as often as usual :)

Share this post


Link to post
Share on other sites

Will check it out, when I got a minute (the x-mas season is killing me)

Share this post


Link to post
Share on other sites

Will check it out, when I got a minute (the x-mas season is killing me)

 

No worries mate, your work comes first !

Thanks again for support !

Have a good christmas !  :)

Share this post


Link to post
Share on other sites

Hello everyone, i think i've cracked it for now

The script is able to go to any questions that is

in the CSV file or text file

 

http://minhtri-nguyen.com/tree.php

http://minhtri-nguyen.com/questions.csv

 

I've also uploaded the CSV file to you can see what is going on

The CSV is a load of nonsense because I just wanted to test.

 

 

Script needs to be improved so watch this space.........

Comment are appreciated :)

Share this post


Link to post
Share on other sites

Nice to hear you're doing progress!

 

Can't open links you're provided though...

Share this post


Link to post
Share on other sites

×

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.