Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-20-2010, 05:02 PM   PM User | #1
doctordew
Regular Coder

 
Join Date: Jul 2007
Location: USA
Posts: 146
Thanks: 5
Thanked 3 Times in 2 Posts
doctordew is on a distinguished road
flashcard script not working

Here is the php

PHP Code:
<?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.
__________________
Quote:
Originally Posted by rmedek View Post
Doctordew, as soon as they come out with the opposite of an infraction, I am going to give you a million of them. You are my new favorite person on the forum.

Last edited by doctordew; 01-20-2010 at 07:49 PM..
doctordew is offline   Reply With Quote
Old 01-20-2010, 07:09 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
what I changed is commented:
PHP Code:
<?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,

Edit: forget to explain.
PHP Code:
$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

Last edited by oesxyl; 01-20-2010 at 07:14 PM..
oesxyl is offline   Reply With Quote
Users who have thanked oesxyl for this post:
doctordew (01-20-2010)
Old 01-20-2010, 07:48 PM   PM User | #3
doctordew
Regular Coder

 
Join Date: Jul 2007
Location: USA
Posts: 146
Thanks: 5
Thanked 3 Times in 2 Posts
doctordew is on a distinguished road
Two errors remained.

PHP Code:
$flashcard_picked $flashcards[$flashcard_picked]; 
and
PHP Code:
$flashcard_picked rand(0,$flashcards_number); 
$flashcard_picked $flashcards[$flashcards_number]; 
It's up and running though, thanks!
__________________
Quote:
Originally Posted by rmedek View Post
Doctordew, as soon as they come out with the opposite of an infraction, I am going to give you a million of them. You are my new favorite person on the forum.
doctordew is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:35 AM.


Advertisement
Log in to turn off these ads.