•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,770 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,531 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 7007 | Replies: 1
![]() |
•
•
Join Date: Feb 2005
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I have this simple script:
[PHP]<?php
// MySQL Connection
mysql_connect($sql['host'],$sql['user'],$sql['pass']) or die("Unable to connect to SQL server");
mysql_select_db($sql['data']) or die("Unable to find DB");
// Getting rows
$select = "SELECT * FROM table WHERE uid = '". $_POST['uid'] ."'";
$data = mysql_db_query($sql['data'], $select) or die("Select Failed!");
// Query results
$row = mysql_fetch_array($data);
$id = $row['uid'];
$type = $row['type'];
print("$id - $type");
?>[/PHP]
This is the simple version. The table has alot of items all having an uid number. Also a type is choosen for each item. When viewing an item i want an 'next' and 'previous' link going to the next item and previous item for the selected type.
Let say i have 5 item with the type "Type1". The 5 items will have the uid numbers: 1, 5, 8, 14 and 15. I want to make a 'next' and 'previous' link, that links to the respective item.
Is there a simple way the get the result from MySQL and is there a simple way to go to the next result and the prevois result??
[PHP]<?php
// MySQL Connection
mysql_connect($sql['host'],$sql['user'],$sql['pass']) or die("Unable to connect to SQL server");
mysql_select_db($sql['data']) or die("Unable to find DB");
// Getting rows
$select = "SELECT * FROM table WHERE uid = '". $_POST['uid'] ."'";
$data = mysql_db_query($sql['data'], $select) or die("Select Failed!");
// Query results
$row = mysql_fetch_array($data);
$id = $row['uid'];
$type = $row['type'];
print("$id - $type");
?>[/PHP]
This is the simple version. The table has alot of items all having an uid number. Also a type is choosen for each item. When viewing an item i want an 'next' and 'previous' link going to the next item and previous item for the selected type.
Let say i have 5 item with the type "Type1". The 5 items will have the uid numbers: 1, 5, 8, 14 and 15. I want to make a 'next' and 'previous' link, that links to the respective item.
Is there a simple way the get the result from MySQL and is there a simple way to go to the next result and the prevois result??
Pass the current row count as a variable to the query.
At each result row add
<? $goin_back = $row_num - 1;
$goin_ahead = $row_num + 1; ?>
<a href="?row_num=<? echo $goin_back;?>">Back</a> ||
<a href="?row_num=<? echo $goin_ahead;?>">Forward</a>
Then your query does a:
SELECT * FROM table LIMIT $row_num , 1
Make sense?
At each result row add
<? $goin_back = $row_num - 1;
$goin_ahead = $row_num + 1; ?>
<a href="?row_num=<? echo $goin_back;?>">Back</a> ||
<a href="?row_num=<? echo $goin_ahead;?>">Forward</a>
Then your query does a:
SELECT * FROM table LIMIT $row_num , 1
Make sense?
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Clean Previous Next Script for MySQL results (PHP)
- Using MySQL with PHP - Tutorial by Herong (MySQL)
Other Threads in the PHP Forum
- Previous Thread: Entering a session without the browser login.
- Next Thread: Am I looking for PHP?


Linear Mode