oriental_express Posted December 2, 2008 Author Share Posted December 2, 2008 thanks for your reply. yes that makes sense. btw is blades have most of the clues in it ? will get back asap as I'm hospital now on my internet phone. thanks again Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-704222 Share on other sites More sharing options...
Mchl Posted December 2, 2008 Share Posted December 2, 2008 Why don't you take a day or two off from coding and stay with your girls? Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-704240 Share on other sites More sharing options...
oriental_express Posted December 2, 2008 Author Share Posted December 2, 2008 Why don't you take a day or two off from coding and stay with your girls?  I wish I could mate but deadlines are not moving. the girls know I'm doing it for them.  sorry to ask but I would love some more clues. so when you said "question[0] would be line 1" I was assuming you suggested a variable for each line. you mean an array for each line right ?  is it true that   $questions[]= $data; gives an array for the whole file which is not what I want ?  thank you Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-704259 Share on other sites More sharing options...
DeanWhitehouse Posted December 2, 2008 Share Posted December 2, 2008 $questions[]= $data; That will put the var $data into the array $questions. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-704262 Share on other sites More sharing options...
Mchl Posted December 2, 2008 Share Posted December 2, 2008 is it true that   $questions[]= $data; gives an array for the whole file which is not what I want ?  It is true, but why wouldn't you want that?  Let's think for a while.  We should now have a code, that reads all lines from CSV file into $questions array, where $questions[0] is the first line, $questions[1] is the second etc... In other words $questions is an array of arrays...  Now, when your script is run for the first time, it should take first line ($questions[0]), and display question and answers form. When the scripts is called with answer from the form posted, it should take line from $questions associated with the answer, and display its question and answers. Rinse and repeat  What do you think?  Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-704269 Share on other sites More sharing options...
laffin Posted December 3, 2008 Share Posted December 3, 2008 A common case of overcomplicating the simple. Â Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-704706 Share on other sites More sharing options...
Mchl Posted December 3, 2008 Share Posted December 3, 2008 A common case of overcomplicating the simple. Â Â Care to explain? Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-704906 Share on other sites More sharing options...
laffin Posted December 6, 2008 Share Posted December 6, 2008 Well have to look at the pros and cons of each routine  1) $questions contains all the items. the file parsing is easier to code the search code is a bit harder to code Multidimensional array  2) $questions contains just the item needed the file parsing is harder to code as it has the search parsing as well No search code needed Single array  and since the page reloads, ya may consider doing the search within the file parsing. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-707462 Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 How is 1) $questions contains all the items. the file parsing is easier to code Extremely easy. the search code is a bit harder to code How is that? The array is indexed by line numbers, and we use line numbers to get items from it. No search at all. Multidimensional array Again, I fail to see it as a flaw. That's just two dimensions. Nothing really complicated. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-707488 Share on other sites More sharing options...
redarrow Posted December 6, 2008 Share Posted December 6, 2008 member mchl, when the users done his work and thanks u, Â can u kindly write a quick tutorial on the process on this grate help your teaching the other user... Â im following all this for fun and enjoying it.. Â it grate to learn new ways off doing things good work mshl Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-707499 Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 member mchl, when the users done his work and thanks u,  can u kindly write a quick tutorial on the process on this grate help your teaching the other user...  im following all this for fun and enjoying it..  it grate to learn new ways off doing things good work mshl  I'll think about it... It could actually be a good subject for a small tutorial. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-707500 Share on other sites More sharing options...
redarrow Posted December 6, 2008 Share Posted December 6, 2008 Thank u, i am enjoying it, can not wait till the sessions come in place..... Â where i get stuck....... Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-707504 Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 Sessions would be used here, to store user's answers until he gets to the last question. Once there, the answers should beretrieved from session and stored to file/to a database/diplayed/whatever. Â There's already a tutorial about sessions on phpfreaks. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-707505 Share on other sites More sharing options...
oriental_express Posted December 8, 2008 Author Share Posted December 8, 2008 Hello everyone. I managed to claw some time back. Shes been a good baby for the past 8 days phew. still tiring though. Â Â Â <?php $file = fopen("questions.txt", "r"); while (($data = fgetcsv($file, 1000, ",")) !== FALSE) { Â $questions[]= $data; } fclose($file); print_r($question[6][1]);Â // <---- see here - a multidimensional array. //First number says which line from csv, //second number says which column from csv ?> Â Thank you again for your support. yes i was playing around with the script the multidimensional array works: But isn't the page supposed to reload ? So if im to use <h1>Q: <?php echo $questions[0][1]; ?></h1> Â Isnt always going to be that questions whether I reload or submit a page ? Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-709200 Share on other sites More sharing options...
Mchl Posted December 8, 2008 Share Posted December 8, 2008 That's exactly what you have to cope with Find a way to display the question that should be displayed, not the same question each time Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-709238 Share on other sites More sharing options...
oriental_express Posted December 8, 2008 Author Share Posted December 8, 2008 That's exactly what you have to cope with Find a way to display the question that should be displayed, not the same question each time  I'll try and get back to you on that watch this space. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-709522 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 Look into rand  That may help you, and insert into the array definition for the first array, just make sure the top most number is the last array key or else you will get errors half the time.  <?php $max = count($questions) - 1; // minus 1 since arrays are zero based. $randIndex = rand(0, $max); ?> <h1>Q: <?php echo $questions[$randIndex][1]; ?></h1>  Hope that helps ya. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-709528 Share on other sites More sharing options...
Mchl Posted December 8, 2008 Share Posted December 8, 2008 No. He doesn't need a random line. He need a line indicated, by the answer to previous question. Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-709619 Share on other sites More sharing options...
oriental_express Posted December 9, 2008 Author Share Posted December 9, 2008 I been pulling my hair out, getting stressed all night over this. I just can't seem to get it. Tried googling similar terms like " Read first line in array" and many others but they only seem to give results like echo $questions[0][1]; ?> I know this is not what I want.  I know for sure that one of the echo for the actual question will be something like $quest[1] and answers $quest[2] $quest[4]  I just have no idea how to "make" my script read the first line first without using $questions[0][1] for the question. I understand exactly what your saying Mchl but I just dont know where to look for such a function. I don't even know what its called.  For real this is not me crying for anyone to do the work for me as I will get caught for "contract cheating". My degree depends on this project. I am working hard, trying to think of ways (I've already thought of the (no choice left) way to do this by using $question1 = $questions[0];  $question2 = $questions[1];  $question3 = $questions[2];  $question4 = $questions[3];  $question5 = $questions[4];  $question6 = $questions[5];  $question7 = $questions[6]; just incase I can't do this but to no avail. Sound like I'm about to cry lol, I know  Are there any examples on the web that I don't know about ? Thank you. Your a life saver ! Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-710211 Share on other sites More sharing options...
laffin Posted December 9, 2008 Share Posted December 9, 2008 Well have to look at the pros and cons of each routine  1) $questions contains all the items. the file parsing is easier to code the search code is a bit harder to code Multidimensional array  2) $questions contains just the item needed the file parsing is harder to code as it has the search parsing as well No search code needed Single array  and since the page reloads, ya may consider doing the search within the file parsing.  This was one of the reasons for my post, multi-dimensional arrays are good but ya need to know how to work with them. as well as the file parsed may not begin with 1 as the index, it could begin with 412. which means finding the correct array becomes a search routine.  From the looks of it, you definately need a guide on working with arrays. and that is wut u shud google, not a quick fix for the code. In order to understand how arrays work, and thus yer own knowledge ya should google: using arrays php guide  Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-710422 Share on other sites More sharing options...
Mchl Posted December 9, 2008 Share Posted December 9, 2008 And how about this? Â $i = 1; echo $questions[$i][1]; $i = 2; echo $questions[$i][1]; Â Yup. You can use variables, to indicate array indexes. You just have to find out, how to get (!) proper value into $i Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-710473 Share on other sites More sharing options...
oriental_express Posted December 11, 2008 Author Share Posted December 11, 2008 $i = 1; echo $questions[$i][1]; $i = 2; echo $questions[$i][1];   Yes that has helped quite alot. I gotta say its exciting to learn new things about php ! Thank you. I've been testing here and there  $i = 0; $i = 1; $i = 2;  I have notived that php seems to only load 2 into the variable $i as its the last one. I've left it as $i = 0 as this is the first line i want to display. So I think (correct me if this is the wrong method) i should leave it as $i = 0 for the script to load first time. Saying that this will always load $i = 0.  Now I realise that when a user clicks the submit button and using the variable VALUE from the form, is it right or possible to, depending on the value choses (ie would be eg <? php $questions[$i][5]; ?>" so if its line 2 (in index term line 1) is it possible to somehow change the original value of $i = 0 to $i = 1 ? or is this where sessions comes into play ?  Maybe im thinking ahead of myself or I just got it totally wrong. But from what the testing has given me by declaring the variables like so  $i = 0; $i = 1; $i = 2; shows that it wont work cause its just going to 'forget' $i = 0; $i = 1;  I hope that all made sense (trying to speak php language)  Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-713100 Share on other sites More sharing options...
Mchl Posted December 11, 2008 Share Posted December 11, 2008 You're thinking quite right. Any variable remembers only the last value assigned to it. Â And yes... since you want to load first line when script starts, it should be set to 0. Then you have to capture data from form... remember those $_POST and $_GET variables? This is their five minutes in your script! Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-713113 Share on other sites More sharing options...
oriental_express Posted December 11, 2008 Author Share Posted December 11, 2008 This is their five minutes in your script! Â Thanks for speedy reply mate ! Â How do you mean five minutes in script ?. As soon as the post or get is submitted I only have five mins. Sorry abit confused Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-713123 Share on other sites More sharing options...
Mchl Posted December 11, 2008 Share Posted December 11, 2008 No... I mean, that's where you should use one of them. Â Like: "It's your big chance, your five minutes!" Quote Link to comment https://forums.phpfreaks.com/topic/134533-final-year-project-please-point-me-in-the-right-direction/page/3/#findComment-713125 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.