SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL Help Needed - Select Entry Before/After Current Entery

    I'm using PHP/MySQL

    I want to be able to navigate forward and backwards on a Part Number Database, but my queries are not working. Here are the queries:
    PHP Code:
    $back "SELECT * FROM $tID WHERE Part_Number < '$pn' ORDER BY Part_Number DESC LIMIT 1";

    $next "SELECT * FROM $tID WHERE Part_Number > '$pn' ORDER BY Part_Number LIMIT 1"
    I'm positive the problem is using the </> operators in comparing Part_Number to $pn. Part Numbers look something like this: 02-92735, 01-80453-DC-TR, 05-91234.a0d etc..

    Any ideas on how to make these queries work???

  2. #2
    SitePoint Evangelist azizur_rahman's Avatar
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure about PHP ways of doing this but in ASP you'd only create one Record Set using the Select * Form Table then you page through that.. for back and forword... record by record...


    Do some reasearch into record set in Php
    Last edited by azizur_rahman; Jun 21, 2002 at 16:21.
    Azizur Rahman
    Web Application Developer

  3. #3
    SitePoint Addict EvilDoppler's Avatar
    Join Date
    Dec 2001
    Location
    Perth, Australia
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool no recordset in php/mysql

    MySQL does not have the ability to use recordsets and so does not allow you to use commands such as MoveNext, MoveLast etc etc.

    You will have to do the SQL statement differently altogether.

    If your part numbers aren't identical - ie all look relatively the same (01-23456-56, 02-23456-79 etc) then you should look at your database design once more and maybe re-design it. Otherwise it will be nearly impossible to select the correct entry without knowing the details beforehand (kinda makes the entry useless).

    You could look at the data for the database first and categorise it a bit further so that the partnumber isn't the only nominator.

    Biggest problem i've had with mysql is that it doesn't allow you to create foreign keys either and as it isn't a relational database I seriously haven't found much use for it other than intermediate needs.

    One hint to make this work could be to use a different field, like an auto-number, then use that as nominator for your navigation.

    cheers and g'luck with it
    * Due to the last tax raise our prices has risen
    * - answers w/o thought $1 - answers w/ thought $3
    * - correct answers $10
    * - Dumb stares are still free

  4. #4
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm really bummed that MySQL doesn't have a built in feature that allows you to easily move through the record set.

    I solved this problem by dumping the results of a query of all part_numbers in ascending order in an array, using array_flip() and the current part number to get the key, and adding/subtracting from the key to get the next/previous part number.


Bookmarks

Posting Permissions

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