ID: 43902 User updated by: webmaster at jaimemontoya dot com Reported By: webmaster at jaimemontoya dot com Status: Open Bug Type: PHP options/info functions Operating System: FreeBSD PHP Version: 4CVS-2008-01-21 (CVS) New Comment:
The solution is only: echo $music; I said that it was necessary to print with echo both $music and $value, but only echo $music is necessary for things to work properly. Anyway it is bad, it is a bug, PHP 4.3.11 has problems with this combination of Switch and rand(), or something wrong is happening. It should work well without printing $ music variable. Previous Comments: ------------------------------------------------------------------------ [2008-01-21 05:22:25] webmaster at jaimemontoya dot com The full code is: <?php echo "<form action='index.php' method='post'>"; echo "<input type='submit' name='stopmusic' value = 'Stop Music'>"; if ($_POST[stopmusic]) { } else{ $value = rand(1,51);//Random between 1 to 51 (inclusive). switch($value){ case 1: $music = 'pactos.mid'; break; case 2: $music = 'otrave.mid'; break; case 3: $music = 'vivi.mid'; break; case 4: $music = 'nellyfurtado_imlikeabird_karaoke.mid'; break; case 5: $music = 'nellyfurtado_turnoffthelight.mid'; break; case 6: $music = 'beethoven_furelise1.mid'; break; case 7: $music = 'yanni_onceuponatime.mid'; break; case 8: $music = 'dido_thankyou.mid'; break; case 9: $music = 'dido_hunter.mid'; break; case 10: $music = 'rickymartin_shesallieverhad.mid'; break; case 11: $music = 'celinedion_anewdayhascome.mid'; break; case 12: $music = 'celinedion_beautyandthebeast.mid'; break; case 13: $music = 'lynyrdskynyrd_sweethomealabama.mid'; break; case 14: $music = 'bonjovi_always.mid'; break; case 15: $music = 'coldplay_clocks.mid'; break; case 16: $music = 'nellyfurtado_powerless.mid'; break; case 17: $music = 'jessicasimpsonithinkiminlo.mid'; break; case 18: $music = 'nelly_furtadote_busque.mid'; break; case 19: $music = 'paris_hiltonnothing_in_this_world.mid'; break; case 20: $music = 'nelly_furtadoall_good_things.mid'; break; case 21: $music = 'nelly_furtadotry.mid'; break; case 22: $music = 'paris_hiltonstars_are_blind.mid'; break; case 23: $music = 'nelly_furtadomaneater.mid'; break; case 24: $music = 'sarahadia.mid'; break; case 25: $music = 'letitbethebeatles.mid'; break; case 26: $music = 'ashlee_simpson_pieces_of_me.mid'; break; case 27: $music = 'blackeyedpeas_dontlie.mid'; break; case 28: $music = 'blackeyedpeas_letsgetstart.mid'; break; case 29: $music = 'blackeyedpeas_masquenada.mid'; break; case 30: $music = 'blackeyedpeas_requestline.mid'; break; case 31: $music = 'eagles_hotelcalifornia.mid'; break; case 32: $music = 'enya_barddnce.mid'; break; case 33: $music = 'enya_book_of_days.mid'; break; case 34: $music = 'enya_china_roses.mid'; break; case 35: $music = 'rhianna_unfaithful.mid'; break; case 36: $music = 'enya_epona.mid'; break; case 37: $music = 'enya_evacuee.mid'; break; case 38: $music = 'enya_eveningfalls.mid'; break; case 39: $music = 'enya_exile.mid'; break; case 40: $music = 'enya_fairytale.mid'; break; case 41: $music = 'enya_from whereiam.mid'; break; case 42: $music = 'enya_hopehasaplace.mid'; break; case 43: $music = 'enya_howcanikeepfromsinging.mid'; break; case 44: $music = 'enya_ebudae.mid'; break; case 45: $music = 'shakira_dontbother.mid'; break; case 46: $music = 'shakira_fool.mid'; break; case 47: $music = 'shakira_hipsdontlie.mid'; break; case 48: $music = 'emilia_bigbigworld.mid'; break; case 49: $music = 'shakira_objection.mid'; break; case 50: $music = 'shakira_theone.mid'; break; case 51: $music = 'shakira_underneathyourclothes.mid'; break; //default: //There is nothing to do as default because I am sure that the randow will always give a valid number. } //End of Switch. echo "<embed src='$music' hidden='true' volume='75%'>"; } //End of If. ?> As I said before, if $value=50, $music should be 'shakira_underneathyourclothes.mid', but $music takes another random value. The solution is: echo $value; echo $music; But why do I have to print the values for things to work properly? ------------------------------------------------------------------------ [2008-01-21 05:18:35] webmaster at jaimemontoya dot com Description: ------------ Hi , this is really really weird, I think it is a problem with PHP language, maybe the version PHP5 does not have this problem. Do you remember that you suggested me to change the Ifs for Switch? I did it, but for example if song 5 was "vivi.mid", it plays another random song, even when the result of random is 5. I checked carefully the code and it is good. The solution is to print the variables, both variables, the one of case (the one that will have 1, 2, 3, 4, 5) and the one with the value assigned for each case (example $music=vivi.mid). But if I do not print the 2 variables, it playes something always random but different than the corresponding case. It is totally crazy, but this is out of my hands to control, I think it is a problem with PHP language, probably other versions have improved this. It is weird and crazy. But since you believe that case will make this faster than If (and I believe that too), I will use Switch, and I will try to find a way to print the two variables but invisible, example: $value = rand(1,51);//Random between 1 to 51 (inclusive). switch($value){ case 1: $music = 'pactos.mid'; break; case 2: $music = 'otrave.mid'; break; } echo "<embed src='$music' hidden='true' volume='75%'>"; If I don't print both $value and $music with echo, the results are crazy, because $value takes the value of 1 and $music takes other value, let's say the song corresponding to $value 40. So, crazy thing, oh well, I will see how to print the two variables invisible, which solves the problem. Reproduce code: --------------- $value = rand(1,51);//Random between 1 to 51 (inclusive). switch($value){ case 1: $music = 'pactos.mid'; break; case 2: $music = 'otrave.mid'; break; } echo "<embed src='$music' hidden='true' volume='75%'>"; Expected result: ---------------- If $value=1, I would expect to hear pactos.mid song, but I hear a different one, like the one in case 2, or any other different case. Actual result: -------------- If $value=1, I would expect to hear pactos.mid song, but I hear a different one, like the one in case 2, or any other different case. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43902&edit=1