Trying to grab several random videos from database, but it just shows the same one all the time.
Posted
by
Birk
on Stack Overflow
See other posts from Stack Overflow
or by Birk
Published on 2011-01-17T03:04:57Z
Indexed on
2011/01/17
3:53 UTC
Read the original article
Hit count: 227
Hi guys,
I'm trying to grab several random videos from my database, and have them show on a page. However, it just keeps on grabbing the same video rather than several different ones. So I end up with 5 of the same video rather than 5 different ones.
Here's the grab random PHP code file... and after it is the template output file.
//=====================================================
// Random | Previous | Next
//=====================================================
$show['random'] = $db->quick_fetch(
"SELECT file_id, title, title_seo, category_id, thumb FROM files
WHERE files.category_id = '".$show['main']['category_id']."'
AND files.verified=1 ORDER BY RAND() LIMIT 0,1;
");
Here's the template CSS html thingy code I have this pasted 5 times to show 5 random videos
<td valign="top" width="53%"><?
$sql="select * from files ORDER BY rand() limit 0,5"; $res=@mysql_query($sql); $data=@mysql_result($res,0,'filename'); $id=@mysql_result($res,0,'file_id'); $title=@mysql_result($res,0,'title'); $title2=str_replace(" ", "-",$title); $path="{$siteurl}/media/{$file.random.file_id}/{$file.random.title_seo}/"; $img="{$siteurl}/thumbs/{$file.random.thumb}"; echo "
{$file.random.title}"
© Stack Overflow or respective owner