...

View Full Version : sql top 25 but only show 8 array_rand?



sitNsmile
06-15-2010, 05:32 PM
Okay, so I want to take the "Top" 25 entries in the database, but I only want it to show 8 at a time on the page. Here is the code im working with, (well a small part)



$SQL = $Data->queryCustom("g_featured='1'",25,0);

foreach($SQL as $R)
{
$g_id = $R->g_id;
echo $g_id;
}


Now that would "display" 25 g_id on the page, but I want it to only show 8 on "rand", how to place the array_rand, in this statement?

Thanks

sitNsmile
06-15-2010, 05:42 PM
Was thinking, I could possible build something like this,




$aRand = array_rand( $SQL , 5);
for($i = 0; $i < 5; $i ++)
{
$R = $SQL[$aRand[$i]];

sitNsmile
06-15-2010, 06:03 PM
I know I could do something like

but cant figure out what im doing wrong there.. not used to the array.



$aRand = array_rand( $SQL , 5);

foreach($aRand as $key)
{
echo $SQL[$key]['g_id'];
}

// probably this instead

$R = $SQL[$key];

kbluhm
06-15-2010, 06:53 PM
$SQL = $Data->queryCustom( "g_featured='1'", 25, 0 );

// Shuffle the order of $SQL
shuffle( $SQL );

// Reduce $SQL to first 8 items
$SQL = array_slice( $SQL, 0, 8 );

// Display the 8 random items
foreach( $SQL as $_SQL )
{
print_r( $_SQL );
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum