I've got a project that was just "dumped" on my lap...
85 video snippets are loading to a page for viewing. The person loaded them into a table and I am expected to mix them up every day for a few weeks.
I am thinking that if I build out the page as divs for each video element (losing the table), there is probably a code that will load them all randomly.
Maybe if I have each div element as a separate file in a specific directory and numbered such as div1.php, div2.php? Then something could search that directory, create an array and then randomly load each div upon page load...
Anyone able to direct me to a resource that will help?
(I do not consider myself a programmer - just knowledgeable enough to get into trouble)
randomize divs (load all randomly)
Moderator: General Moderators
Re: randomize divs (load all randomly)
So all 85 are on the same page?
No need to switch to divs. Just use the php shuffle() function to randomize the array.
In your table, echo out $vid1, $vid2, $vid3 in order. But shuffle your array and then loop through it to assign the images to the $vidX variables.
Should be pretty easy. In fact, this method will mean users see a different order of snippets with every page load.
No need to switch to divs. Just use the php shuffle() function to randomize the array.
In your table, echo out $vid1, $vid2, $vid3 in order. But shuffle your array and then loop through it to assign the images to the $vidX variables.
Should be pretty easy. In fact, this method will mean users see a different order of snippets with every page load.
Re: randomize divs (load all randomly)
yes, all 85 are on the same page...
right now there are 10 rows like so:
<tr>
<td width="100"><img src="video_filler.jpg" width="100" height="75" /></td>
<td width="100"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="69"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="104"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="16"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="16"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="16"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="16"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="16"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="27"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
</tr>
<tr>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
</tr>
It makes more sense to me that each video embed code and contestant name be in a single div... Or, I could create an xml file with each one, yes?
Can you direct me to something that will help me learn to randomize all the videos and write them to the page?
TIA,
Greg
right now there are 10 rows like so:
<tr>
<td width="100"><img src="video_filler.jpg" width="100" height="75" /></td>
<td width="100"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="69"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="104"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="16"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="16"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="16"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="16"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="16"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
<td width="27"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
</tr>
<tr>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
<td><div align="center"><span class="style3">Contestant Name</span></div></td>
</tr>
It makes more sense to me that each video embed code and contestant name be in a single div... Or, I could create an xml file with each one, yes?
Can you direct me to something that will help me learn to randomize all the videos and write them to the page?
TIA,
Greg
Re: randomize divs (load all randomly)
Code: Select all
//this
<td width="100"><img src="video_filler.jpg" alt="" width="100" height="75" /></td>
//becomes this
$vid1 = "name_of_one_file.jpg";
echo "<td width='100'><img src='$vid1' alt='' width='100' height='75' /></td>"
once you have your file names, loop through the array and assign them to the variable on the fly.
Re: randomize divs (load all randomly)
i don't have a db to work with - i am going to create an xml file to call in for the array...
you might have given me enough to get started with...
thank you,
Greg
you might have given me enough to get started with...
thank you,
Greg
Re: randomize divs (load all randomly)
an xml file should work just fine. You can even load it up with an ajax request and make it faster. But use jQuery and the .load() method. It's easier than trying to figure out the ajax stuff yourself. jQuery handles all of that for you.