Jump to content

Search the Community

Showing results for tags 'shuffle'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 6 results

  1. I am working on a quiz app image 1 shows the index.php page image 2 shows the first question image 3 shows the second question image 4 shows the third question image 5 shows the result after completing the quiz image 6 shows the database 'quizzer' and its tables image 7 shows the 'questions' table image 8 shows the 'choices' table THIS LINK CONTAIN ALL THE CODE (and images) I HAVE DONE SO FAR https://www.mediafire.com/folder/g5ao7f5q0fe6y/quiz 1.Now my question is how to select the question RANDOMLY from 'questions' table along with 'choices' (by adding code to the existing file or create a new one). 2.If user refresh/reload the page before starting ('Start Quiz') or click 'Take Again' after finishing the quiz, the question should appear randomly. 3.Basically I want to change the order of question appearing in the browser each time I refresh. 4.My work so far is mentioned above.........Please help me with this "RANDOM" problem !! P.S - Will it be possible, by creating a random function in PHP which will check for repeat questions in a session and check for the 'id' of the question and if it is new display it on the page. If so what should I do and if no then how to do?
  2. Hi in my code below, echo $body; outputs the link to every song in my $SongsFolder. How can I make it echo only one link and that link is the song the $Shuffle chose? I know I have array but is there a way to get around it? Anything I should change up? <?php function fooFucker($url) { $a = join('/', array_map('urlencode', explode('/', $url))); return str_replace('+', '%20', $a); } $SongsFolder = "songs"; header("Content-Type: audio/x-mpegurl"); $body = ''; $Songs = glob($SongsFolder."/*.mp3"); shuffle($Songs); $first = 0; foreach($Songs as $Song) { $SongPath = pathinfo($Song); if ($first != 0) { $body .= "\n"; } $first = 1; $body .= "http://".$_SERVER['HTTP_HOST'].fooFucker(dirname($_SERVER['PHP_SELF']))."/".fooFucker($SongsFolder)."/".fooFucker($SongPath['basename']); } header('Content-Length: ' . strlen($body)); echo $body; ?>
  3. So in my code below I have a script where it shuffles through .mp3 in a folder. How can I make the line below know which song the shuffle() has picked? $ThisFileInfo = $getID3->analyze($Songs[0]); <?php require_once('/home/manveers94/public_html/getID3-1.9.7/getid3/getid3.php'); $getID3 = new getID3; function fooFucker($url) { $a = join('/', array_map('urlencode', explode('/', $url))); return str_replace('+', '%20', $a); } $SongsFolder = "songs"; header("Content-Type: audio/x-mpegurl"); $body = ''; $Songs = glob($SongsFolder."/*.mp3"); shuffle($Songs); $first = 0; foreach($Songs as $Song) { $SongPath = pathinfo($Song); if ($first != 0) { $body .= "\n"; } $first = 1; $body .= "http://".$_SERVER['HTTP_HOST'].fooFucker(dirname($_SERVER['PHP_SELF']))."/".fooFucker($SongsFolder)."/".fooFucker($SongPath['basename']); } set_time_limit(30); $ThisFileInfo = $getID3->analyze($Songs[0]); getid3_lib::CopyTagsToComments($ThisFileInfo); $body .= 'File name: '.$ThisFileInfo['filenamepath'].'<br>'; $body .= 'Artist: '.(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<BR>', $ThisFileInfo['comments_html']['artist']) : ' ').'<br>'; $body .= 'Title: '.(!empty($ThisFileInfo['comments_html']['title']) ? implode('<BR>', $ThisFileInfo['comments_html']['title']) : ' ').'<br>'; $body .= 'Bitrate: '.(!empty($ThisFileInfo['audio']['bitrate']) ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps' : ' ').'<br>'; $body .= 'Play time: '.(!empty($ThisFileInfo['playtime_string']) ? $ThisFileInfo['playtime_string'] : ' ').'<br>'; header('Content-Length: ' . strlen($body)); echo $body; ?>
  4. Hi I have an .m3u playlist file on my server, it has links to different songs on my server. The .m3u playlist streams all the music. The thing I want the .m3u file to do is shuffle the music instead of going in the same order. I've been using this method to do it but it doesn't work. Any other ways or something wrong with my code? <?php $playlist = “/DONTFUCKWITHME/playlist.m3u"; if ($_SERVER['PATH_INFO'] == "/playlist.m3u") { # This a request for the actual playlist. playlist(); } else { # Fall through to end of script and display # the player HTML. } function playlist() { header("Content-type: audio/mpeg"); # Needed for PHP versions OLDER than 4.2.0 only. # If your host still has PHP older than 4.2.0, shame on them. # Find a better web host. srand(make_seed()); # Fetch our list of songs from a file. $songs = file($playlist); shuffle($songs); # Now output the URLs in random order. foreach ($songs as $song) { # Remove newline and any other leading and trailing # whitespace from URL of song. $song = trim($song); echo "$song\n"; } # Now exit before any HTML is produced. exit(0); } # Needed only for very old versions of PHP, # see srand call earlier. function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } ?> <html> <head> <title>MP3s Playing in Random Order</title> </head> <body> <h1 align="center">MP3s Playing in Random Order</h1> <embed src="/examples/randomsongs.php/playlist.m3u" width="0" height="0" autostart="true" type="audio/mpeg" loop="true"/> </body> </html>
  5. So this is my 2nd PHP class ever. And this right here is part of my final. I'm sure you all know what the "shuffle" function does. What I thought I could make it do was randomize a bunch of echoes I have. Is that possible? Any help would be greatly appreciated. KCCO! Here's the code I need tweaked: <html> <head> <title>Characters</title> <link rel="stylesheet" href="assets/css/bootstrap.css" media="screen"> <link rel="stylesheet" href="assets/css/bootstrap-responsive.css" media="screen"> <link rel="stylesheet" href="assets/css/normalize.css" type="text/css" media="screen"> <link rel="stylesheet" href="assets/css/style.css" media="screen"> </head> <body> <div class="navbar"> <div class="navbar-inner"> <a class="brand" href="#"></a> <ul class="nav"> <li class="active"><a href="Characters.php">Previous Clients</a></li> <li><a href="workForSupers.php">Work for Supers</a></li> </ul> </div> </div><!-- END of navbar--> <div align="center"> <h1>Supers we've helped locate</h1> <? date_default_timezone_set("America/Los_Angeles"); # set default timezone $imageDir = "images/"; # Comics is a PARENT class - Emily, Jenny, and so forth all are CHILDREN of Comics, meaning: They inherit the properties and methods included inside Comics. # For example: echo $joker->comiccharacters; will print out the $comiccharacters stored in Comics class Comics { const IMAGEDIR = "images/"; public $comiccharacters = "Comics"; } class Spiderman extends Comics { public $name = "Spiderman"; public $location = "New York City"; public $superpower = "his spider-sense, augmented speed and strength and his web shooters."; public $sex = "male"; public $published = "1963-03-01."; public $hero = true; public $asseskicked = 37; public $personscaught = [12,16,19,29,51]; public $powerlevel= '++++++'; public $email = "SpiderMan4Reals@gmail.com"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "spiderman.jpg"; } } $spiderman = new Spiderman(); class Magneto extends Comics { public $name = "Magneto"; public $location = "New York City."; public $superpower = "power of magnetism."; public $sex = "male"; public $published = "1963-10-15."; public $hero = false; public $asseskicked = 52; public $personscaught = [21,11,21,43,31]; public $powerlevel= '+++++++'; public $email = "ElMagneto@yahoo.com"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "magneto.jpg"; } } $magneto = new Magneto(); class Nightwing extends Comics { public $name = "Nightwing"; public $location = "Gotham City"; public $superpower = "is his peak physical conditioning, gadgets, and detective skills."; public $sex = "male"; public $published = "1985-01-06"; public $hero = true; public $asseskicked = 76; public $personscaught = [32,41,53,48,63]; public $powerlevel= '++++++'; public $email = "NightwingIsAwesome@hotmail.com"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "nightwing.jpg"; } } $nightwing = new Nightwing(); class GreenArrow extends Comics { public $name = "Green Arrow"; public $location = "Starling City"; public $superpower = "is his peak physical conditioning and accuracy with his gadgets."; public $sex = "male"; public $published = "1941-11-19"; public $hero = true; public $asseskicked = 62; public $personscaught = [17,17,29,31,49]; public $powerlevel= '++++++'; public $email = "ImTheGreenArrow@gmail.com"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "greenarrow.jpg"; } } $greenArrow = new GreenArrow(); class TheJoker extends Comics { public $name = "The Joker"; public $location = "Gotham City"; public $superpower = "being completely insane and psychotic."; public $sex = "male"; public $published = "1940-04-11"; public $hero = false; public $asseskicked = 112; public $personscaught = [61,79,103,94,52]; public $powerlevel= "++++++++"; public $email = "KillingForAJoke@gmail.com"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "joker.jpg"; } } $thejoker = new TheJoker(); # Create an array containing all the members classes $members = array($spiderman, $magneto, $nightwing, $greenArrow, $thejoker); # Calculate Ages - this cycles through all of the classes, and calculates the age for each band member, and places it in a property named "$age" foreach($members as $obj) { $obj->age = calculateAge($obj->published); } # Display our Jump Menu echo "<form name=\"jump\"> <p align=\"center\"> <select name=\"menu\" onchange='window.location.href=this.options[this.selectedIndex].value'> <option selected>All Characters</option> <option value=\"?sort=name\">Sort by Name</option> <option value=\"?sort=ageLoToHi\">Sort by Age (youngest to oldest)</option> <option value=\"?sort=ageHiToLo\">Sort by Age (oldest to youngest)</option> </select></p> </form>"; # Access the sort value from the url: blah.com/?sort=blam $sort = ''; if (isset($_GET['sort'])) { $sort = $_GET['sort']; } # Let's introduce all our members echo "<h2>Heroes and Villains Alike</h2>"; for ($i=0; $i < count($members); $i++) { switch ( $sort ) { # sort=name -- sorts alphabetically by 'name' in the member array case "name" : usort($members, 'sortByName_ascend'); displayProfile($members[$i]); break; case "nameRev" : usort($members, 'sortByName_descend'); displayProfile($members[$i]); break; # sort=ageLoToHi -- sorts alphabetically by 'age' ascending case "ageLoToHi" : usort($members, 'sortClassesByAgeLoHi'); displayProfile($members[$i]); break; # sort=ageHiToLo -- sorts alphabetically by 'age' descending case "ageHiToLo" : usort($members, 'sortClassesByAge_HiLo'); displayProfile($members[$i]); break; # sort=ageHiToLo -- sorts alphabetically by 'age' descending case "asseskicked" : uksort($members, 'sortAsseskicked'); displayProfile($members[$i]); break; # default -- spit out all band members according to their order in the array default : displayProfile($members[$i]); break; } } # This is a custom sorting function that works with usort(). # If you provide usort() with either an array or a set of objects, # it goes through all the items and compares them, and puts them in order # according to the rules below. function sortClassesByAgeLoHi($a, $b) { if ( $a->published == $b->published ) { #return 0; # this makes equivalent aged folks disappear return 1; } elseif ( $a->published > $b->published ) { return -1; } else { return 1; } } function sortClassesByAge_HiLo($a, $b) { return sortClassesByAgeLoHi($b, $a); # just reverse the arguments } function sortByName_ascend($a, $b) { if ( $a->name == $b->name ) { #return 0; # this makes equivalent aged folks disappear return 1; } elseif ( $a->name > $b->name ) { return 1; } else { return -1; } } function sortByName_descend($a, $b) { return sortByName_ascend($b, $a); # just reverse the arguments } # FUNCTIONS - Store all functions down here - I could also store them in another file function displayProfile($memberClass) { echo "<div class='memberProfile'><p>"; # spit out the image of our character # <img src="images/spiderman.jpg" /><br /> echo "<img src=\"".$memberClass->imagePath."\" width=200px /><br />"; #should make it so that when you refresh the page, it randomizes the order of the elements in the array shuffle($memberProfile); THE FOLLOWING IS SPECIFICALLY WHAT I WANT TO RANDOMIZE # spit out our caption echo "This is ".$memberClass->name.".<br>"; //counts the "+" for the power level echo "He has a power level of ".strlen($memberClass->powerlevel)." <br> "; echo "He resides in ".$memberClass->location.". <br>"; echo "He was first published in ".displayBirthdate($memberClass->published).".<br>"; echo "Making him ".calculateAge($memberClass->published)." years old! <br>"; //wraps the string after the specified # of characters echo "His superpower is ".wordwrap($memberClass->superpower,35,"<br>\n")."<br>"; echo "And in that time he's kicked the asses of ".$memberClass->asseskicked." people! <br>"; //finds the average & wraps the string after the specified # of characters echo "They normally capture their respective enemy ".average($memberClass->personscaught)." times a year.<br>"; echo "You can reach them at <a href=\"#\"> ".$memberClass->email.".</a>. <br> </p></div> "; } function displayBirthdate($bandmateBirthdate) { # January 1, 1984 $birthDateFormatted = date('F j, Y', strtotime($bandmateBirthdate)); return $birthDateFormatted; } function calculateAge($bandmateBirthdate) { #$currentTime = time(); # as a Unix timestamp list($year, $month, $day) = explode("-",$bandmateBirthdate); $elapsedYears = date('Y') - $year; $age = $elapsedYears; # calculates number of years elapsed # If current date < birthdate (i.e. Oct01 < Dec01), then subtract 1 year if ( date('n') < $month || ( date('n') == $month && date('j') < $day ) ) { $age = $age - 1; } return $age; } //example how to get the average in an array function average($average) { if (!is_array($average)) return false; return array_sum($average)/count($average); } ?> </body> <script type="text/javascript" src="js/bootstrap.js"></script> </html> Characters.php
  6. Hey guys i've got a rookie question. How do i shuffle an array then display each number in the array using implode? Heres my code. $maximum_integer = strip_tags(trim($_REQUEST['maximum_integer'])); $range = range(0,$maximum_integer); $range_randomized[] = shuffle($range); $random_range_imploded = implode(', ', $range_randomized); print $random_range_imploded; it just keeps displaying '1'.... Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.