Jump to content

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">

  • Replies 115
  • Created
  • Last Reply

Top Posters In This Topic

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.

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

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

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>

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

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

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

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.

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

 

 

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

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

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

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.