Solved

creating next and back button

Posted on 2006-06-12
4
239 Views
Last Modified: 2013-12-12
hello,

I have a page of results, each results links to a second page which displays the details of all the results, so I want to have a next and back button to scroll through the results, I have no idea where to start and wasted 3 hours now looking for tutorials online.

The first page sends the team_id(id) and team_type(id2) to the details page, my first recordset displays based on team_id, so i need a query that will start at team_id(id) and go to next record based on team_type(id2).

My first query is this...
$colname_Recordset1 = "1";
if (isset($_GET['id'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_mine, $mine);
$query_Recordset1 = sprintf("SELECT * FROM team WHERE team_id = %s", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $mine) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

So i decided to create a new query based on id2, and i want to make an array.... then go into my array, compare to id and select the next record... so far my echo dumps a 1 on the page and the word array..


$colname_Recordset3 = "1";
if (isset($_GET['id2'])) {
  $colname_Recordset3 = (get_magic_quotes_gpc()) ? $_GET['id2'] : addslashes($_GET['id2']);
}
mysql_select_db($database_mine, $mine);
$query_Recordset3 = sprintf("SELECT * FROM team WHERE team_type = %s", $colname_Recordset3);
$Recordset3 = mysql_query($query_Recordset3, $mine) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 = mysql_num_rows($Recordset3);

do {
  $pages[] = $row_Recordset3['team_id'];
  //  do stuff with other column
  //  data if we want
} while ($row_Recordset3 = mysql_fetch_assoc($Recordset3));

echo $pages;
0
Comment
Question by:jblayney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:aminerd
ID: 16888136
You could...

Previous:

SELECT team_id FROM team WHERE team_type = 'TYPE' AND team_id < ID LIMIT 1;

Next:

SELECT team_id FROM team WHERE team_type = 'TYPE' AND team_id > ID LIMIT 1;

And I'd probably recommend a combined index on team_type and team_id (i.e., ALTER TABLE `team` ADD UNIQUE INDEX idx_team_id_type (team_id, team_type)).
0
 
LVL 1

Author Comment

by:jblayney
ID: 16888396
Hello,

Tx for the help,

it works except when i get to the first or last record, then the query has no result an my links die, so how would i make it so that if I am on record #1, it will select the highest id?
0
 
LVL 1

Author Comment

by:jblayney
ID: 16888515
i notice something else, my back button always goes to first record...

this is my code...

BACK BUTTON

<td width="53%">
             
                <?
              $colname_Recordset4 = "1";
if (isset($_GET['id2'])) {
  $colname_Recordset4 = (get_magic_quotes_gpc()) ? $_GET['id2'] : addslashes($_GET['id2']);
}

$id3 = $_GET['id'];

mysql_select_db($database_mine, $mine);
//$query_Recordset3 = sprintf("SELECT * FROM team WHERE team_type = %s", $colname_Recordset3);
$query_Recordset4 = sprintf("SELECT team_id, team_type FROM team WHERE team_type = %s AND team_id < $id3 LIMIT 1", $colname_Recordset4);
$Recordset4 = mysql_query($query_Recordset4, $mine) or die(mysql_error());
$row_Recordset4 = mysql_fetch_assoc($Recordset4);
$totalRows_Recordset4 = mysql_num_rows($Recordset4);

             
              ?>
             
              <a href="team_details.php?id=<?php echo $row_Recordset4['team_id']; ?>&id2=<?php echo $row_Recordset4['team_type']; ?>">Back</a>
             
              </td>

NEXT BUTTON


<td width="14%">
              <?
              $colname_Recordset3 = "1";
if (isset($_GET['id2'])) {
  $colname_Recordset3 = (get_magic_quotes_gpc()) ? $_GET['id2'] : addslashes($_GET['id2']);
}

$id3 = $_GET['id'];

mysql_select_db($database_mine, $mine);
//$query_Recordset3 = sprintf("SELECT * FROM team WHERE team_type = %s", $colname_Recordset3);
$query_Recordset3 = sprintf("SELECT team_id, team_type FROM team WHERE team_type = %s AND team_id > $id3 LIMIT 1", $colname_Recordset3);
$Recordset3 = mysql_query($query_Recordset3, $mine) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 = mysql_num_rows($Recordset3);

             
              ?>
             
             
             
              <a href="team_details.php?id=<?php echo $row_Recordset3['team_id']; ?>&id2=<?php echo $row_Recordset3['team_type']; ?>">Next</a></td>
        </tr>
0
 
LVL 5

Accepted Solution

by:
aminerd earned 250 total points
ID: 16888739
"i notice something else, my back button always goes to first record.."

You're correct, sorry about that. Change to:

SELECT team_id, team_type FROM team WHERE team_type = %s AND team_id < $id3 ORDER BY team_id DESC LIMIT 1
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question