Hi all

I have a question regarding whether it's possible to have 4 mySQL queries and then paginate the results from all 4 into one list?

Basically, I have 2 tables and four types of advert I want to display. They are one filtered result from one mySQL table 1st, then a different filtered result from the same table, then a 3rd result from the 2nd table and a 4th result from the 2nd table. All of these results will be a large list that I then want to split into 10 results per page.

Is this possible?

The reason I have 4 different queries is because I want a different <div> shown in each.

Many thanks for your help.

Pete

    petenaylor wrote:

    I have a question regarding whether it's possible to have 4 mySQL queries and then paginate the results from all 4 into one list?

    A better question to ask would be: Why are you using 4 separate queries to get information that belongs in 1 single data set?

    You might want to post your DB schema and the four queries. Even if what you're after can't be better implemented (e.g. using JOINs and whatnot), you could still reduce them down to 1 single query with the use of some UNIONs.

      Hi there

      Thanks for your response. Here's my code. Not sure if these can be combines into one query?

       <!-- Get Trader premium adverts -->
      
         <?php 
      	 $gettraderads = mysql_query("SELECT * FROM `trade-adverts` WHERE type = 'premium' AND paid = 1 AND categoryid = 1 AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC ");
      	 $numtraderads = mysql_num_rows($gettraderads);
      	 while ($showtraderads = mysql_fetch_array($gettraderads)) {
      	include('trader-ad-cell.php'); 
      	 }
      	?>
      
      <!-- Get Trader standard adverts -->
      
         <?php 
      	 $gettraderads = mysql_query("SELECT * FROM `trade-adverts` WHERE type = 'standard' AND categoryid = 1 AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC ");
      	 $numtraderads = mysql_num_rows($gettraderads);
      	 while ($showtraderads = mysql_fetch_array($gettraderads)) {
      	include('trader-ad-cell.php'); 
      	 }
      	?>
      
      <!-- Get premium adverts -->
      
      <?php 
       $getads = mysql_query("SELECT * FROM `adverts` WHERE categoryid = 1 AND type = 'premium' AND paid = 1 AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC ");
       while ($showads = mysql_fetch_array($getads)) {
       include('ad-cell.php'); 
       }
      ?>
      
      <!-- Get standard adverts -->
      
      <?php 
       $getads = mysql_query("SELECT * FROM `adverts` WHERE categoryid = 1 AND type = 'standard' AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC ");
       while ($showads = mysql_fetch_array($getads)) {
        $standarduserid = $showads['userid'];
        $getstandarduserinfo = mysql_query(" SELECT * FROM `users` WHERE id = '".$standarduserid."'");
        $showstandarduserinfo = mysql_fetch_array($getstandarduserinfo);
       include('standard-ad-cell.php'); 
       }
      ?>
      

      Thanks
      Pete

        Write a Reply...