0
$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?

2 Answers 2

1
$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);
  }
Sign up to request clarification or add additional context in comments.

3 Comments

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/...
my bad, I think you are supposed to use $qry in the mysql_data_seek()
thank you, didn't read your comment, and found that out for myself. Again lots of thx's;) you are one smart dude
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.