#1
  1. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    Okay, here goes nothing.

    the scenario:
    Database contains the data of "2" types:
    Type A
    Type B

    Type A's data is displayed on a document, on only type A's, with a "Previous" and "Next" link at the bottom of the page.

    Now, since the database table contains both type and a and b information, this is where my delimma comes in.

    TO setup those back/next links, I must obtain the ID value for the back/next rows. And these values should only be a row which contains the data for, in this example, Type A data.

    How do I pull this off?

    Naturally I would have to find all the rows which contain type A data. Then obtain their row Numbers.

    Let's just say for argument sake, there are 5 rows of data.

    1 - Type A
    2 - Type B
    3 - Type A
    4 - Type A
    5 - Type B

    I enter viewing record number 3, my next
    button should be for row 4, and my previous should link to row 1.

    Since those are the previous and next rows containing "TYPE A" data.

    Any ideas?

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Robert,

    i think one small sql statement is enough to solve this problem..

    "SELECT * FROM tablename WHERE TYPE='A' order by fieldname DESC LIMIT $offset,$limit";

    //this will return only type 'A' records .then you can navigate next |previous record using LIMIT clause.just pass values to $offset and $limit variable.



    1 - Type A
    2 - Type B
    3 - Type A
    4 - Type A
    5 - Type B

    I enter viewing record number 3, my next
    button should be for row 4, and my previous should link to row 1.


    In this case previous record should get issuing following sql query.

    "SELECT * FROM tablename WHERE ID<3 AND TYPE='A'";

    //use DESC,ASC or LIMIT clauses if required..

    Next record should be:

    "SELECT * FROM tablename WHERE ID>3 AND TYPE='A'";

    --------------





    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    I solved my problem with the following string
    of code.

    $sql = "SELECT member_id FROM members WHERE member_type = 'I'";
    $result = mysql_query($sql);
    $count = mysql_num_rows($result);

    $i = 0;
    while ($myrow = @mysql_fetch_array($result)) {
    $member_id = $myrow[0];
    $members_id[] = $member_id;
    $i++;
    }

    $i = 0;
    while ($i < count($members_id)) {
    if ($members_id[$i] == $view) {
    $c_rec = $members_id[$i];
    //check the count
    $check = $i + 1;
    if ($check >= count($members_id)) { $n_rec = $c_rec; }
    else { $n_rec = $members_id[$i+1]; }
    //check the count
    $check = $i - 1;
    if ($check <= 0) { $p_rec = 1; }
    else { $p_rec = $members_id[$i-1]; }
    }
    $i++;
    }

    So far this has tested out just fine..

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.

Similar Threads

  1. Mysql problem.
    By Nik in forum MySQL Help
    Replies: 54
    Last Post: December 21st, 2006, 07:02 PM
  2. Extracting link from mysql into html as jpg using php
    By necropsy in forum PHP Development
    Replies: 8
    Last Post: December 21st, 2003, 09:59 PM
  3. Upgrade from access to mysql
    By karib1 in forum ASP Programming
    Replies: 7
    Last Post: December 16th, 2003, 01:35 PM
  4. Upgrade from access to mysql
    By karib1 in forum MySQL Help
    Replies: 1
    Last Post: December 16th, 2003, 01:27 AM

IMN logo majestic logo threadwatch logo seochat tools logo