mysql - php keeping track of random condition -
at moment i've 3 conditions need met randomly 1 time on 3 pages. if page 1 gets randomly second condition, page 2 can randomly condition 1 or 3 , on. write database (i using database log activities) , call on other pages see condition has been met on previous pages.
i created first page random function:<?php $rand = rand(1, 3); ?>
the second page:
if ($row['manip_1'] == 1){ $man = rand(2,3); } elseif ($row['manip_1'] == 2){ //should randomly 1 or 3, $man_a = rand(1,2); //but don't know how skip #2 in if($man_a == 2){ //random function, solved $man = 3; } else { $man = 1; } } else { $man = rand(1,2); } the third page:
if ($row['manip_1'] == 1 && $row['manip_2'] == 2){ $man = 3; } elseif ($row['manip_1'] == 1 && $row['manip_2'] == 3){ $man = 2; } elseif ($row['manip_1'] == 2 && $row['manip_2'] == 1){ $man = 3; } elseif ($row['manip_1'] == 2 && $row['manip_2'] == 3){ $man = 1; } elseif ($row['manip_1'] == 3 && $row['manip_2'] == 1){ $man = 2; } else { $man = 1; } the problem need have fourth page. meaning there should fourth condition. means number of possibilities 25 on last page. can program again did before, wondering if there not more convenient way program random condition dependent on conditions of previous pages. during 4 pages each condition can shown once.
define array of conditions, , store them in session, e.g.
$conditions = array(1,2,3,4); $_session['conditions'] = $conditions; randomization easy:
array_shuffle($_session['conditions']); then on each of individual pages, pop off 1 of values session:
<?php # page 1 session_start(); $random_condition = array_pop($_session['conditions']); and other pages:
<?php #page n session_start(); $random_condition = array_pop($_session['conditions']);
Comments
Post a Comment