...

View Full Version : flashcard script not working



doctordew
01-20-2010, 06:02 PM
Here is the php


<?php
$flashcards = file_get_contents('flashcards.txt');
$flashcards = explode(',',$flashcards);

$flashcards_number = count($flashcards);
$flashcards_number = $flashcards_number-1;
$random_note = rand(0,$flashcards_number);

$flashcard_picked = rand(0,$flashcards_number);
$flashcard_picked = $flashcards[$flashcards_number];

$spanish_word = explode('|',$flashcard_picked);
$spanish_word = $spanish_word[0];

$english_answer = $spanish_word[1];

echo $spanish_word;
echo '<center>';
echo '<br /><a href=javascript:alert("' . $english_answer . '");>English Answer</a> | <a href="flashcard.php?card=' . $random_note . '">Random Flash Card</a>';
echo '</center>';
?>

The text it is taking from is located at *example removed*

The script itself is installed on *example removed*

It won't switch words, it won't display the answer, and I'm kind of trying to prepare for an exam with this script. Could anybody help me get this working? Maybe I have my text file written front, maybe it's an error with the code.

oesxyl
01-20-2010, 08:09 PM
what I changed is commented:

<?php
$flashcards = file_get_contents('flashcards.txt');
$flashcards = explode(',',$flashcards);

$flashcards_number = count($flashcards);
$flashcards_number = $flashcards_number-1;
$random_note = rand(0,$flashcards_number);

$flashcard_picked = rand(0,$flashcards_number);
$flashcard_picked = $flashcards[$flashcards_number];

$spanish_word = explode('|',$flashcard_picked);
$spanish = $spanish_word[0]; // changed this

$english_answer = $spanish_word[1];

echo $spanish; // ... and this
echo '<center>';
echo '<br /><a href=javascript:alert("' . $english_answer . '");>English Answer</a> | <a href="flashcard.php?card=' . $random_note . '">Random Flash Card</a>';
echo '</center>';
?>

good luck with your exam, :)

forget to explain.


$spanish_word = explode('|',$flashcard_picked);
// next line will overwrite the array and $english_answer will be only first char
$spanish_word = $spanish_word[0];

$english_answer = $spanish_word[1];

best regards

doctordew
01-20-2010, 08:48 PM
Two errors remained.


$flashcard_picked = $flashcards[$flashcard_picked];
and

$flashcard_picked = rand(0,$flashcards_number);
$flashcard_picked = $flashcards[$flashcards_number];

It's up and running though, thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum