Jump to content

Split results on multiple pages


blunder

Recommended Posts

I am trying to split the mysql results on multiple pages, but the problem is that I want the limit to focus on the first table called. I have a LEFT JOIN in the SQL text, which ends up addding more rows, but I want the LIMIT to focus on the initial table (series)

 

This is an illustration of the sql text (not complete, just an illustration):

 

SELECT * FROM series LEFT JOIN articles

 

Anyone have any ideas?

Link to comment
Share on other sites

Or just pass a variable $page

 

<?

if(!isset($page) $page = 1;

 

# How many per page

$npp = 30;

 

$start = ($page*$npp)-($npp);

$num = ($page*$npp);

 

 

$sql = "SELECT * FROM series LEFT JOIN articles LIMIT $start,$num";

$qry = mysql_query($sql);

 

while ($row = mysql_fetch_object($qry))

{

  # Print our row

  print $row->id." - " $row-name;

#etc

}

 

?>

 

Should do the job :)

Link to comment
Share on other sites

Or just pass a variable $page

--snip--

Should do the job :)

 

I am already doing this and it is not hiting the mark. Let me illustrate, lets say this is the data in the two tables. Two first come from series table and the "article title" and "article desc" from articles.

 

SERIE NAME 1 │ Serie Variable │ Article Title │ Artitle Desc

SERIE NAME 1 │ Serie Variable │ Article Title │ Artitle Desc

SERIE NAME 1 │ Serie Variable │ Article Title │ Artitle Desc

SERIE NAME 2 │ Serie Variable │ Article Title │ Artitle Desc

SERIE NAME 2 │ Serie Variable │ Article Title │ Artitle Desc

SERIE NAME 2 │ Serie Variable │ Article Title │ Artitle Desc

SERIE NAME 2 │ Serie Variable │ Article Title │ Artitle Desc

 

With a LIMIT 0,2

 

SERIE NAME 1 │ Serie Variable │ Article Title │ Artitle Desc

SERIE NAME 1 │ Serie Variable │ Article Title │ Artitle Desc

 

but I want LIMIT 0,2 to show all the data. See my problem?

Link to comment
Share on other sites

LIMIT 0,2 means limit the query results to 2 rows starting from row 0.

 

You canot LIMIT on a specific table - it applys to the whole dataset.

 

Hmm... so maybe I should instead first do a query selecting all the serie ids and then for each serie do a query? That could however mean that I do 20 queries on one page. Although they are processing the same data, does it not make the page load slower?

Link to comment
Share on other sites

why are you using a left join?

 

Well, the problem is that I am trying to join two tables.

 

Table series looks like this:

Serie 1Serie DescriptionDate updatedetc, etc

Serie 2Serie DescriptionDate updatedetc, etc

Serie 3Serie DescriptionDate updatedetc, etc

Serie 4Serie DescriptionDate updatedetc, etc

 

Table articles looks like this:

Article idSerie 1Article descetc, etc

Article idSerie 1Article descetc, etc

Article idSerie 2Article descetc, etc

Article idSerie 2Article descetc, etc

Article idSerie 2Article descetc, etc

Article idSerie 2Article descetc, etc

Article idSerie 2Article descetc, etc

Article idSerie 3Article descetc, etc

Article idSerie 3Article descetc, etc

Article idSerie 3Article descetc, etc

Article idSerie 4Article descetc, etc

 

I thought LEFT JOIN was the best way to combine the two...

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.