SQL is evil! help me!

Results 1 to 4 of 4

Thread: SQL is evil! help me!

  1. #1
    Dani Guest

    Default SQL is evil! help me!

    Hi, my name is Dani and I have a terrible problem in SQL (you&#039ll have to excuse my English... :) ).<BR>I have a SQL script that searches inside a database. I want to split the results into pages (10 results per page). To do this I choose the pagenum*10 best results first. That means that if I&#039m on page 3 I&#039ll choose the best 30 results... if I&#039m on page 2 the best 20 and so on. After that I choose the worse (bottom) 10 results.<BR>The problem occurs when the total number of results doesn&#039t divide by 10. for example instead of seeing 3 resutls on the last page, I&#039ll see 10 results - 3 that belong to the last page and 7 that belong to the page before.<BR><BR>Do you have an idea for a solution?<BR>Thank you, and sorry again for my English (I keep having this feeling that I&#039m doing mistakes after each word I write..)

  2. #2
    TonyZag Guest

    Default RE: SQL is evil! help me!

    I assume you&#039re looping through the results, and displaying data from an array of 10 records. Try this: keep a running count of the number of records displayed, and inside the loop, compare the number of the current record against the total no. of records found. If it matches, break out of the loop.<BR>

  3. #3
    dani Guest

    Default I wish I could :)

    I&#039m "pouring" the results of the DB into a content mangement script that put them in templates. Is there a way to do this without changing the content mangement script?<BR>I noticed that when I search AltaVista, there is a variable that has the pagenum*10-10 (p. 3--&#062; 20, page 4 --&#062;30). That gave me an idea. If I can delete the top pagenum*10-10 pages and then select the top 10 results I won&#039t have any problems. Do you know how do I do that?

  4. #4
    Dani Guest

    Default Don't Answer... I found a solution...

    istead of selecting the worst 10, when i&#039m on the last page I&#039ll check: if resultsnum MOD pagenum*10 is 0 then i&#039ll select the worst 10, if not i&#039ll select the worst resultsnum MOD pagenum*10 .<BR><BR>Thanks anyway :)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts