July 31st, 2000, 02:52 PM
-
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.
July 31st, 2000, 09:58 PM
-
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..."
August 1st, 2000, 12:46 AM
-
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.