Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7709963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:59:36+00:00 2026-06-01T00:59:36+00:00

The Default code used to LIMIT the results fetched from the MySQL database using

  • 0

The Default code used to LIMIT the results fetched from the MySQL database using PHP is the following,

$sql="SELECT * 
FROM  `tablename` 
WHERE `Type` LIKE '$var1'
LIMIT 0 , 30";

When we need to display results continuously we can alter that code with the following

$start=0; $end=30;
$start=$_GET['start'];
$end=$start+30;
$sql="SELECT * 
FROM  `tablename` 
WHERE `Type` LIKE '$var1'
LIMIT $start , $end";

So I pass the value for the variable start with a link saying Next like this

<a href="something.php?start=<? $start+30 ?>">Next</a>

Everything goes fine when there are more results to display.

Consider this situation: There are 120 Entries in the Database and the PHP file is currently displaying results 91 to 120. So when I click the Next Link now it shows blank. So how can I make the “Next” link to be disabled when it is showing the last set of results? I think that could be possible if we know the total number of entries in the database. But if it is dynamic, how can we calculate it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:59:37+00:00Added an answer on June 1, 2026 at 12:59 am

    If you use a COUNT() function on the result, you can get simple info back.

    For example:

    $total=mysql_fetch_assoc("SELECT COUNT(*) AS `total` FROM  `tablename` WHERE `Type` LIKE '$var1'");
    

    The value returned is the total number of entries that fit the given criteria. So:

    $total['total']==120;
    

    You can then simply do something along the lines of:

    if (($start+30)>=$total['total']) {
        //Greyed out link
    }
    else {
        //Active link
    }
    

    It’s probably also worth mentioning that your SQL conditions are faulty. The way you have it set up, passing a $start value of ’10’ to the file would create the query:

    $sql="SELECT * 
    FROM  `tablename` 
    WHERE `Type` LIKE '$var1'
    LIMIT 10 , 40";
    

    Which grabs 40 results, starting from result 10, not the results between 10 and 40; a common misconception.

    While I’m presuming that’s a cut down version of the code, it’s always worth using *mysql_real_escape_string()* on anything from the outside that goes into your query. People could easily put the $start value as “; DROP TABLE tablename;”, making your query:

    $sql="SELECT * 
    FROM  `tablename` 
    WHERE `Type` LIKE '$var1'
    LIMIT ; DROP TABLE `tablename`;";
    

    Which I’m sure you don’t want 😛

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code DEFAULT_CACHE_SIZE is declared later, but it is used to assign
I have some code using Lucene that leaves the default conjunction operator as OR,
In the following master.cs code: public partial class Default : System.Web.UI.MasterPage { protected void
I have the following code in a web.config file of the default IIS site.
I have the following code: private static void WriteStartupInfo() { Settings settings = Settings.Default;
This code used to work in WSS 3.0 / MOSS 2007 in FeatureReceiver.FeatureActivated: using
i have the following code used to serialize a label's content. When i press
Suggest me, is it a good idea to make changes in default Joomla code
How to set the default style for a type in code-behind e.g. for: <ScaleTransform
The C# code is: DataContext db = new DataContext(MyProject.Properties.Settings.Default.MyString) I am trying to convert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.