www.webdeveloper.com
Results 1 to 8 of 8

Thread: Limit values from table

  1. #1
    Join Date
    Mar 2012
    Location
    bangalore,india
    Posts
    27

    Smile Limit values from table

    Hi everyone,

    I have nearly 100 questions in my database table so i want to fetch only 10 questions in each page using PHP please suggest me how can i do this ? It should go like this :-> 10 in 1st page , next 10 in 2nd so on.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    My recommendation at this point would be to Google for something like "PHP MySQL pagination" (replacing "MySQL" as appropriate). In a nutshell, most solutions include a "LIMIT" and "OFFSET" in your SQL.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Dec 2012
    Location
    Lubbock Texas
    Posts
    5
    Pass a Post or Get value for each new set of 10 questions and provide a $var to carry it into your query.

    At top of your page place a Get or Post to catch each new $value from pagination links below going back to this same page.

    Add this to the end of your query---- order by q.id asc limit "'.$value.'", 10');

    Now add a value to change the limit for each next set of 10 using a $value variable-------order by q.id asc limit "'.$value.'", 10');

    at the bottom of your page add links for pagination to carry new values--- a href= questions.php?value=10 >2 /a---a href= questions.php?value=20 >3 /a etc.

    the link comming to this page from the start should = value 0 .

  4. #4
    Join Date
    Mar 2012
    Location
    bangalore,india
    Posts
    27

    Talking

    Thanks all .. my problem is solved but can you please tell me how to carry field values to the next page when i click on link ? I dont want to use get .

  5. #5
    Join Date
    Dec 2012
    Location
    Lubbock Texas
    Posts
    5

    Post Method

    The Post method works the same but Your form must have the id= and name= value names set then direct the form link as action to the page that processes the form,, generally this is done on the same page,,,here is a sample.

    PHP Code:
           <?php
    //  if(isset($_POST['show_more']))           // checks if value is set or not,if is do code, if not have it continue to form 
     //       {
     //         $value = $_POST['show_more'];    // we asign it to a variable value is set to ""1""
     //         $result=mysql_query( ------------------ order by q.id asc limit "'.$value.'", 10'); // Place all this script above your data show.
    //          
    //    
    ?>                 // the first value after Limit is 1, 10    second click will be 2, 10   it pulls data as 1st set of ten,,,second as 11-20 etc.
    //
    //<form action="process.php" method="post">
    //<input type="hidden" value="1" name="show_more" id="show_more" />Next 1
    //<input type="hidden" value="2" name="show_more" id="show_more" />Next 2   etc------add more as needed,,,,php can do it auto but it cost,,lol
      // <input type="button" value="submit" />                                                   // submits the value 10 inside assigned show_more
    //   this script will do but you would be the first to use it,, get is used by everyone for single values. Hacker cant do anything with a single num !

  6. #6
    Join Date
    Dec 2012
    Location
    Lubbock Texas
    Posts
    5
    i made a mistake---where input in the form has showmore value=1 then next line has showmore value =2 these two lines cant be together,, they have to have their own form and own buttons,, so create a 3 line form for all or them----> form
    input value=1
    button
    /form
    form
    input value=2
    button
    /end form

  7. #7
    Join Date
    Dec 2012
    Location
    Lubbock Texas
    Posts
    5
    if you are usig get for users you can add one more value to it easier-----profile.php?user=id ?value= next 10 etc..... the browser will hold 2500 characters....and everyone uses it,, especially facebook, google, and yahoo......use md5() function to place 32 bit hashes on all values passed examples below.
    if($result['value']==md5($value) { to parse data and use-------$value = mysql_real_escape_string(md5($_POST['value'])); to insert data.

  8. #8
    Join Date
    Aug 2011
    Posts
    12
    I wouldnt use md5 id use a more better hash such as hash('sha512',$value); also this profile.php?user=id ?value=
    should prob be this profile.php?user=id&value= and for the love of god can people please stop using the mysql set of functions even php.net warns againest this use the mysqli set or PDO

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles