blunder Posted July 13, 2007 Share Posted July 13, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/59868-split-results-on-multiple-pages/ Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 search forum for "pagination" Quote Link to comment https://forums.phpfreaks.com/topic/59868-split-results-on-multiple-pages/#findComment-297678 Share on other sites More sharing options...
deadonarrival Posted July 13, 2007 Share Posted July 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/59868-split-results-on-multiple-pages/#findComment-297688 Share on other sites More sharing options...
blunder Posted July 13, 2007 Author Share Posted July 13, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/59868-split-results-on-multiple-pages/#findComment-297699 Share on other sites More sharing options...
ToonMariner Posted July 13, 2007 Share Posted July 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/59868-split-results-on-multiple-pages/#findComment-297703 Share on other sites More sharing options...
blunder Posted July 13, 2007 Author Share Posted July 13, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/59868-split-results-on-multiple-pages/#findComment-297709 Share on other sites More sharing options...
ToonMariner Posted July 13, 2007 Share Posted July 13, 2007 why are you using a left join? It owuld be nice to see some of your code/query but from you are sayong a straight forward cross (or .) join is what is needed and just equate the key from table and teh foreign key in table 2. Quote Link to comment https://forums.phpfreaks.com/topic/59868-split-results-on-multiple-pages/#findComment-297710 Share on other sites More sharing options...
blunder Posted July 13, 2007 Author Share Posted July 13, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/59868-split-results-on-multiple-pages/#findComment-297724 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.