views:

30

answers:

2
$qry = mysql_query("SELECT test1,test2 FROM ".$table." ORDER BY RAND() LIMIT 6"); 

        $start =  new WP_Query('showposts=6&orderby=rand'); 

        if ($start->have_posts()) : while( $start->have_posts() && $rows = mysql_fetch_assoc($qry) ) : $start->the_post();

        $test1 = $rows['test1'];

        $test2 = $rows['test2']; 

I can manipulate the wordpress loop like this.... The problem appears when my table does not have 6 values inside, it happenes sometimes. Then, my index page doesn't show all the posts. For example, if i have 3 entries inside the table, than the loop displays only 3 posts instead of 6.

It would be great if i can make the query repeat itself... to supply the loop.

Any ideeas?

+1  A: 

Probably not the most efficient answer, but you could do a query before this one to get the number of entries in the table and then put that in the 'showposts=$numposts' part of the query you have here.

Dylan West
+1  A: 
$qry = mysql_query("SELECT test1,test2 FROM ".$table." ORDER BY RAND() LIMIT 6"); 

$start =  new WP_Query('showposts=6&orderby=rand'); 

if ($start->have_posts()) : while( $start->have_posts() ) : $start->the_post();
  $rows = mysql_fetch_assoc($qry)
  if (!$rows) {
    mysql_data_seek($qry,0);
    $rows = mysql_fetch_assoc($qry);
  }
vinhboy
I think it's briliant, tho it's not working Warning: mysql_data_seek(): supplied argument is not a valid MySQL result resource in /home/content/d/d/a/...
webmasters
my bad, I think you are supposed to use $qry in the mysql_data_seek()
vinhboy
thank you, didn't read your comment, and found that out for myself.Again lots of thx's;) you are one smart dude
webmasters