Re: Calling strings from fgets
| From: | David Robley | Date: | Mon, 14 Aug 2000 05:30:37 +0000 |
| Subject: | Re: Calling strings from fgets | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11561@lists.php.net to get a copy of this message | ||
On 14 Aug, Kris Howl wrote:
> Hello,
>
> I have a voting script I knocked up. And in poll.php4 there are the 6
> options of what the user can choose. These options are defined in $option# =
> "Choice number #";
>
> # Being replaced with a number from 1 to 6.
>
> In results.php4 which shows the graph of how many votes each option has
> taken, I want the $option# to appear above the graphic bar.
>
> This is what I have:
> ----------
> function readvar() {
>
> $openvar = fopen("poll.php4","r");
> $getvars = fgets($openvar,400000);
>
> global $op1, $op2, $op3, $op4, $op5, $op6;
>
> $op1 = $getvars["$option1"];
> $op2 = $option2;
> $op3 = $option3;
> $op4 = $option4;
> $op5 = $option5;
> $op6 = $option6;
> fclose($openvar);
>
> }
>
> readvar();
> print $op1;
> ---------
I'm not clear exactly what you are expecting this to do, but what it
actually appears to do is get the first line from poll.php4 and assign
it to the variable $getvars AS A STRING. Then when you attempt to treat
$getvars as an array, you are looking at probably the "" element, as
most likely $option1 is unset. So $op1 is most likely empty.
If this is database driven, could you not create a table with the voting
options, then call on that table to create a list of options? Or just
build an array with the options?
Cheers
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA