PDA

View Full Version : Need help to make random videos from db


sarvnaa
08-17-2009, 09:31 AM
Hello Coding gurus,
I am new for programming.

I am trying to get random video using sql. I tried using rnd(), but it is not working.

here is the sample of the code for getting top videos. can anyone please help me to fetch random videos from the database.

Thanks


function top_videos($hits, $limit = '7') {



global $config;



$sql = "SELECT * FROM pm_videos ORDER BY ";

$sql .= ($config['views_from'] == 1) ? "yt_views" : "site_views";

$sql .= " DESC LIMIT ".$limit."";



$query = mysql_query($sql);

$result = '';

$i = 1;

while($row = mysql_fetch_array($query)) {



if($i !=1) {

$results .= "

<div class=\"item\">

<a href=\"".makevideolink($row['uniq_id'])."\"><img src=\"".show_thumb($row['uniq_id'])."\" alt=\"".$row['video_title']."\" class=\"imag\" width=\"72\" height=\"53\" align=\"left\" /></a>

<span class=\"artist_name\">".$row['artist']."</span>

<a href=\"".makevideolink($row['uniq_id'])."\" class=\"song_name\">".$row['video_title']."</a>

</div>";



} else {



$results .= "

<div class=\"item\">

<a href=\"".makevideolink($row['uniq_id'])."\"><img src=\"".show_thumb($row['uniq_id'])."\" alt=\"".$row['video_title']."\" class=\"imag\" width=\"72\" height=\"53\" align=\"left\" /></a>

<span class=\"artist_name_1\">".$row['artist']."</span>

<a href=\"".makevideolink($row['uniq_id'])."\" class=\"song_name\">".$row['video_title']."</a>

</div>";

}

$i++;

}

return $results;

}

sarvnaa
08-17-2009, 11:13 AM
i had tried this code..but still it is not working :(


function random_videos($how = 'random', $limit = '5') { // newest, top views, etc etc etc



$query = mysql_query("SELECT * FROM pm_videos ORDER BY RAND() LIMIT 8");

$result = '';

while($row = mysql_fetch_array($query)) {



$results .= "

<div class=\"item\">

<a href=\"".makevideolink($row['uniq_id'])."\"><img src=\"".show_thumb($row['uniq_id'])."\" alt=\"".$row['video_title']."\" class=\"imag\" width=\"72\" height=\"53\" /></a><br />

<a href=\"".makevideolink($row['uniq_id'])."\" class=\"song_name\">".$row['video_title']."</a>

</div>";



}

return $results;

}

djm0219
08-17-2009, 11:56 AM
What exactly isn't working?