Connecting Tech Pros Worldwide Help | Site Map

Uisng a string varibale with an array

Chris H
Guest
 
Posts: n/a
#1: Apr 5 '06
Okay, I am trying to us a varialble with a list of number values as my data
for an array, yet when I do this it doesnt return any values from the array,
i was able to temporarily fix the proble by just doing s normal array setup
in my function, but the problem is I want the ability to have teh array
values to be changed easily in a varibale style config/include file... Here
is the code i am working with...


===================================
VARIABLE.PHP (my config variables)
====================================
<?php

$pid_prefix = "LPPA";

$site_domain = "www.lafayettepoker.com";
######################################
# PAYOUT PERCENTAGE STRUCTURE
######################################
$range1 = ".60, .30, .10";
$range2 = ".50, .30, .12, .06, .02";
$range3 = "'.33, .17, .14, .12, .10, .06, .05, .04, .03, .02";
$range4 = ".25, .15, .10, .08, .07, .05, .05, .04, .03, .03, .02, .02, .02,
..02, .02, .01, .01, .01, .01, .01";
$range5 = "";
$range6 = "";
######################################
# POINT POOL
######################################
$pool = "5000";


?>
=======================================
MAIN PART OF SCRIPT
=======================================
<?php
require ('variables.php');



if ($tplayer >= 5 && $tplayer <= 10) {
$table = $range1;
}
elseif ($tplayer >= 11 && $tplayer <= 17) {
$table = $range2;
}
elseif ($tplayer >= 18 && $tplayer <= 35) {
$table = $range3;
}
elseif ($tplayer >= 36 && $tplayer <= 65) {
$table = $range4;
}
elseif ($tplayer >= 66 && $tplayer <= 99) {
if ($range5 == '') { $table = "$range4"; }
else { $table = "$range5"; }
}
elseif ($tplayer >= 100) {
if ($range6 == '') { $table = "$range4"; }
else { $table = "$range6"; }
}
else {
$msg = "Not Enough Players";
print_error_msg($msg);
}
calculate_points($table,$rank);




function calculate_points($table,$rank) {
global $pool;
$index = ($rank - 1);
$perc = array($table);
$total_points = $pool * $perc["$index"];
$total_points = round($total_points);
print "$total_points<br>";
}


// PRINT ERROR TO SCREEN
function print_error_msg($msg) {
print "$msg";
}

?>
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
Ive also tried a few differnt variatons of teh above, including formatting
the $range string to look similiar to an array, in other words i addded in
sigle-quotes so the range variables would look like this
$range1 = " '.60', '.30', '.10' "; (note the spaces seperating the double
and single quoute, is just there to show that there are 2 types of quotes
used)

Ok I will test this after i post this since i dont htink it will work
anyway, but looking at the above string, is it possible the reason that
string didnt works is because i didnt escape teh sigle quotes, and if that
is the case how come it doesnt work without teh single quotes at all.. I
really am not sure of what i am doing wrong here...


David Haynes
Guest
 
Posts: n/a
#2: Apr 6 '06

re: Uisng a string varibale with an array


Chris H wrote:[color=blue]
> Okay, I am trying to us a varialble with a list of number values as my data
> for an array, yet when I do this it doesnt return any values from the array,
> i was able to temporarily fix the proble by just doing s normal array setup
> in my function, but the problem is I want the ability to have teh array
> values to be changed easily in a varibale style config/include file... Here
> is the code i am working with...
>
>
> ===================================
> VARIABLE.PHP (my config variables)
> ====================================
> <?php
>
> $pid_prefix = "LPPA";
>
> $site_domain = "www.lafayettepoker.com";
> ######################################
> # PAYOUT PERCENTAGE STRUCTURE
> ######################################
> $range1 = ".60, .30, .10";
> $range2 = ".50, .30, .12, .06, .02";
> $range3 = "'.33, .17, .14, .12, .10, .06, .05, .04, .03, .02";
> $range4 = ".25, .15, .10, .08, .07, .05, .05, .04, .03, .03, .02, .02, .02,
> .02, .02, .01, .01, .01, .01, .01";
> $range5 = "";
> $range6 = "";
> ######################################
> # POINT POOL
> ######################################
> $pool = "5000";
>
>
> ?>
> =======================================
> MAIN PART OF SCRIPT
> =======================================
> <?php
> require ('variables.php');
>
>
>
> if ($tplayer >= 5 && $tplayer <= 10) {
> $table = $range1;
> }
> elseif ($tplayer >= 11 && $tplayer <= 17) {
> $table = $range2;
> }
> elseif ($tplayer >= 18 && $tplayer <= 35) {
> $table = $range3;
> }
> elseif ($tplayer >= 36 && $tplayer <= 65) {
> $table = $range4;
> }
> elseif ($tplayer >= 66 && $tplayer <= 99) {
> if ($range5 == '') { $table = "$range4"; }
> else { $table = "$range5"; }
> }
> elseif ($tplayer >= 100) {
> if ($range6 == '') { $table = "$range4"; }
> else { $table = "$range6"; }
> }
> else {
> $msg = "Not Enough Players";
> print_error_msg($msg);
> }
> calculate_points($table,$rank);
>
>
>
>
> function calculate_points($table,$rank) {
> global $pool;
> $index = ($rank - 1);
> $perc = array($table);
> $total_points = $pool * $perc["$index"];
> $total_points = round($total_points);
> print "$total_points<br>";
> }
>
>
> // PRINT ERROR TO SCREEN
> function print_error_msg($msg) {
> print "$msg";
> }
>
> ?>
> ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
> Ive also tried a few differnt variatons of teh above, including formatting
> the $range string to look similiar to an array, in other words i addded in
> sigle-quotes so the range variables would look like this
> $range1 = " '.60', '.30', '.10' "; (note the spaces seperating the double
> and single quoute, is just there to show that there are 2 types of quotes
> used)
>
> Ok I will test this after i post this since i dont htink it will work
> anyway, but looking at the above string, is it possible the reason that
> string didnt works is because i didnt escape teh sigle quotes, and if that
> is the case how come it doesnt work without teh single quotes at all.. I
> really am not sure of what i am doing wrong here...
>
>[/color]

Either:

$table = array( .60, .30, .10 );
or
$table = explode(', ', ".06, .30, .10");

should work for you.


Chris H
Guest
 
Posts: n/a
#3: Apr 6 '06

re: Uisng a string varibale with an array


see the problem is i really need the array values to come from a string
variable, this way the administartor can easily set/modify the payout
percentage "range" witrhin teh variables.php file, so the admin never has to
be in the main parts of my code, i guess i could always just use mySQL and
have the ranges set in a table for the scripts configs. altho i really am
trying to keep from using MySQL so much to relieve any server strain


"David Haynes" <david.haynes2@sympatico.ca> wrote in message
news:GYXYf.73009$nF1.22196@fe64.usenetserver.com.. .[color=blue]
> Chris H wrote:[color=green]
>> Okay, I am trying to us a varialble with a list of number values as my
>> data for an array, yet when I do this it doesnt return any values from
>> the array, i was able to temporarily fix the proble by just doing s
>> normal array setup in my function, but the problem is I want the ability
>> to have teh array values to be changed easily in a varibale style
>> config/include file... Here is the code i am working with...
>>
>>
>> ===================================
>> VARIABLE.PHP (my config variables)
>> ====================================
>> <?php
>>
>> $pid_prefix = "LPPA";
>>
>> $site_domain = "www.lafayettepoker.com";
>> ######################################
>> # PAYOUT PERCENTAGE STRUCTURE
>> ######################################
>> $range1 = ".60, .30, .10";
>> $range2 = ".50, .30, .12, .06, .02";
>> $range3 = "'.33, .17, .14, .12, .10, .06, .05, .04, .03, .02";
>> $range4 = ".25, .15, .10, .08, .07, .05, .05, .04, .03, .03, .02, .02,
>> .02, .02, .02, .01, .01, .01, .01, .01";
>> $range5 = "";
>> $range6 = "";
>> ######################################
>> # POINT POOL
>> ######################################
>> $pool = "5000";
>>
>>
>> ?>
>> =======================================
>> MAIN PART OF SCRIPT
>> =======================================
>> <?php
>> require ('variables.php');
>>
>>
>>
>> if ($tplayer >= 5 && $tplayer <= 10) {
>> $table = $range1;
>> }
>> elseif ($tplayer >= 11 && $tplayer <= 17) {
>> $table = $range2;
>> }
>> elseif ($tplayer >= 18 && $tplayer <= 35) {
>> $table = $range3;
>> }
>> elseif ($tplayer >= 36 && $tplayer <= 65) {
>> $table = $range4;
>> }
>> elseif ($tplayer >= 66 && $tplayer <= 99) {
>> if ($range5 == '') { $table = "$range4"; }
>> else { $table = "$range5"; }
>> }
>> elseif ($tplayer >= 100) {
>> if ($range6 == '') { $table = "$range4"; }
>> else { $table = "$range6"; }
>> }
>> else {
>> $msg = "Not Enough Players";
>> print_error_msg($msg);
>> }
>> calculate_points($table,$rank);
>>
>>
>>
>>
>> function calculate_points($table,$rank) {
>> global $pool;
>> $index = ($rank - 1);
>> $perc = array($table);
>> $total_points = $pool * $perc["$index"];
>> $total_points = round($total_points);
>> print "$total_points<br>";
>> }
>>
>>
>> // PRINT ERROR TO SCREEN
>> function print_error_msg($msg) {
>> print "$msg";
>> }
>>
>> ?>
>> ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
>> Ive also tried a few differnt variatons of teh above, including
>> formatting the $range string to look similiar to an array, in other words
>> i addded in sigle-quotes so the range variables would look like this
>> $range1 = " '.60', '.30', '.10' "; (note the spaces seperating the
>> double and single quoute, is just there to show that there are 2 types of
>> quotes used)
>>
>> Ok I will test this after i post this since i dont htink it will work
>> anyway, but looking at the above string, is it possible the reason that
>> string didnt works is because i didnt escape teh sigle quotes, and if
>> that is the case how come it doesnt work without teh single quotes at
>> all.. I really am not sure of what i am doing wrong here...[/color]
>
> Either:
>
> $table = array( .60, .30, .10 );
> or
> $table = explode(', ', ".06, .30, .10");
>
> should work for you.
>
>[/color]


Chris H
Guest
 
Posts: n/a
#4: Apr 6 '06

re: Uisng a string varibale with an array


nevermind i figured it out, just have to make the config variables as arrays
instead, i dunno tho for some reason that variation didnt work earlier must
of had syntax error somewhere.

thanks agian for ur help all

"Chris H" <lppa2004@insightbb.com> wrote in message
news:3HYYf.667749$084.20176@attbi_s22...[color=blue]
> see the problem is i really need the array values to come from a string
> variable, this way the administartor can easily set/modify the payout
> percentage "range" witrhin teh variables.php file, so the admin never has
> to be in the main parts of my code, i guess i could always just use mySQL
> and have the ranges set in a table for the scripts configs. altho i really
> am trying to keep from using MySQL so much to relieve any server strain
>
>
> "David Haynes" <david.haynes2@sympatico.ca> wrote in message
> news:GYXYf.73009$nF1.22196@fe64.usenetserver.com.. .[color=green]
>> Chris H wrote:[color=darkred]
>>> Okay, I am trying to us a varialble with a list of number values as my
>>> data for an array, yet when I do this it doesnt return any values from
>>> the array, i was able to temporarily fix the proble by just doing s
>>> normal array setup in my function, but the problem is I want the ability
>>> to have teh array values to be changed easily in a varibale style
>>> config/include file... Here is the code i am working with...
>>>
>>>
>>> ===================================
>>> VARIABLE.PHP (my config variables)
>>> ====================================
>>> <?php
>>>
>>> $pid_prefix = "LPPA";
>>>
>>> $site_domain = "www.lafayettepoker.com";
>>> ######################################
>>> # PAYOUT PERCENTAGE STRUCTURE
>>> ######################################
>>> $range1 = ".60, .30, .10";
>>> $range2 = ".50, .30, .12, .06, .02";
>>> $range3 = "'.33, .17, .14, .12, .10, .06, .05, .04, .03, .02";
>>> $range4 = ".25, .15, .10, .08, .07, .05, .05, .04, .03, .03, .02, .02,
>>> .02, .02, .02, .01, .01, .01, .01, .01";
>>> $range5 = "";
>>> $range6 = "";
>>> ######################################
>>> # POINT POOL
>>> ######################################
>>> $pool = "5000";
>>>
>>>
>>> ?>
>>> =======================================
>>> MAIN PART OF SCRIPT
>>> =======================================
>>> <?php
>>> require ('variables.php');
>>>
>>>
>>>
>>> if ($tplayer >= 5 && $tplayer <= 10) {
>>> $table = $range1;
>>> }
>>> elseif ($tplayer >= 11 && $tplayer <= 17) {
>>> $table = $range2;
>>> }
>>> elseif ($tplayer >= 18 && $tplayer <= 35) {
>>> $table = $range3;
>>> }
>>> elseif ($tplayer >= 36 && $tplayer <= 65) {
>>> $table = $range4;
>>> }
>>> elseif ($tplayer >= 66 && $tplayer <= 99) {
>>> if ($range5 == '') { $table = "$range4"; }
>>> else { $table = "$range5"; }
>>> }
>>> elseif ($tplayer >= 100) {
>>> if ($range6 == '') { $table = "$range4"; }
>>> else { $table = "$range6"; }
>>> }
>>> else {
>>> $msg = "Not Enough Players";
>>> print_error_msg($msg);
>>> }
>>> calculate_points($table,$rank);
>>>
>>>
>>>
>>>
>>> function calculate_points($table,$rank) {
>>> global $pool;
>>> $index = ($rank - 1);
>>> $perc = array($table);
>>> $total_points = $pool * $perc["$index"];
>>> $total_points = round($total_points);
>>> print "$total_points<br>";
>>> }
>>>
>>>
>>> // PRINT ERROR TO SCREEN
>>> function print_error_msg($msg) {
>>> print "$msg";
>>> }
>>>
>>> ?>
>>> ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
>>> Ive also tried a few differnt variatons of teh above, including
>>> formatting the $range string to look similiar to an array, in other
>>> words i addded in sigle-quotes so the range variables would look like
>>> this
>>> $range1 = " '.60', '.30', '.10' "; (note the spaces seperating the
>>> double and single quoute, is just there to show that there are 2 types
>>> of quotes used)
>>>
>>> Ok I will test this after i post this since i dont htink it will work
>>> anyway, but looking at the above string, is it possible the reason that
>>> string didnt works is because i didnt escape teh sigle quotes, and if
>>> that is the case how come it doesnt work without teh single quotes at
>>> all.. I really am not sure of what i am doing wrong here...[/color]
>>
>> Either:
>>
>> $table = array( .60, .30, .10 );
>> or
>> $table = explode(', ', ".06, .30, .10");
>>
>> should work for you.
>>
>>[/color]
>
>[/color]


David Haynes
Guest
 
Posts: n/a
#5: Apr 6 '06

re: Uisng a string varibale with an array


Chris H wrote:[color=blue]
> see the problem is i really need the array values to come from a string
> variable, this way the administartor can easily set/modify the payout
> percentage "range" witrhin teh variables.php file, so the admin never has to
> be in the main parts of my code, i guess i could always just use mySQL and
> have the ranges set in a table for the scripts configs. altho i really am
> trying to keep from using MySQL so much to relieve any server strain[/color]


See that string in the explode function?
What's wrong with that?

How about this for clarity?

<?php
include_once('variables.php');

$table = explode(',', $range1);
printf("The first value is %f\n", $table[0]);
printf("The second value is %f\n", $table[0]);
?>

[variables.php]
$range1 = "0.60, 0.41, 0.20";

David Haynes
Guest
 
Posts: n/a
#6: Apr 6 '06

re: Uisng a string varibale with an array


David Haynes wrote:[color=blue]
> Chris H wrote:[color=green]
>> see the problem is i really need the array values to come from a
>> string variable, this way the administartor can easily set/modify the
>> payout percentage "range" witrhin teh variables.php file, so the admin
>> never has to be in the main parts of my code, i guess i could always
>> just use mySQL and have the ranges set in a table for the scripts
>> configs. altho i really am trying to keep from using MySQL so much to
>> relieve any server strain[/color]
>
>
> See that string in the explode function?
> What's wrong with that?
>
> How about this for clarity?
>
> <?php
> include_once('variables.php');
>
> $table = explode(',', $range1);
> printf("The first value is %f\n", $table[0]);
> printf("The second value is %f\n", $table[0]);[/color]
correction: should be $table[1][color=blue]
> ?>
>
> [variables.php]
> $range1 = "0.60, 0.41, 0.20";
>[/color]

Closed Thread