NameSilo

PHP help.

NamecheapNamecheap
Watch

dc1pop

VIP Member
Impact
13
Hi,

Im trying to do a link that when clicked the user will be taken to the next article in the database for example. But articles may not nessacary be 1, 2, 3, 4 etc because some articles may be removed.

So im wondering how i can go about doing this so that the id of the actuall next record is placed into a variable so i can then go to the next record.

Sorry if the above dont make sense.

Thanks for any help.

Regards,
Darren
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Take a look at some of these Pagination tutorials.
http://www.pixel2life.com/search/10/pagination/1/

With some edits, i'm sure you will be able to get what you are achieving...

Or...if you are displaying your articles by a article?=id for example, ($_GET['var'])

Then you could possible have a link in your PHP script like...

$current_article = $_GET['var'];
$next_article = $current_article + 1;
<a href="file.php?var=$next_article">
 
0
•••
Hitch said:
Take a look at some of these Pagination tutorials.
http://www.pixel2life.com/search/10/pagination/1/

With some edits, i'm sure you will be able to get what you are achieving...

Or...if you are displaying your articles by a article?=id for example, ($_GET['var'])

Then you could possible have a link in your PHP script like...

$current_article = $_GET['var'];
$next_article = $current_article + 1;
<a href="file.php?var=$next_article">

Thanks for the pagnation link (i'll need it later). Its moving tot the next article i want to do. However it wont be as simple as adding one to the current article incase one is removed it wont display an article.

For example if i had articles in the database of

1,3,4,5.

If i was looking at article 1 id want the next button to go to article 3 and not 2 as there isnt a 2.

Hope that makes it clearer. Thanks for your help and time.
 
0
•••
PHP:
<?php

// If you use 'id', it will check the variable id in the URL.
$id_variable_name    = 'id';

// If you use 'file.php', the next link would go to: file.php?idvar=NextID
$next_page_file_name = 'file.php';

// Change this to the table name in your MySQL database
$mysql_table_name    = 'table';

$cid    = (int) $_GET[$id_variable_name];
$query  = "SELECT * FROM $mysql_table_name WHERE id > $cid ORDER BY id ASC LIMIT 1";
$result = mysql_query($query);
$row    = mysql_fetch_array($result);
$next   = $row['id'];
echo '<a href="'.$next_page_file_name.'?';
echo $id_variable_name.'='.$next.'">Next</a>';

?>
Just edit the first two variables and paste it where you want the next link to be displayed.

(I had to split the echo up because it was breaking the code with spaces where the lines are too long.)
 
Last edited:
0
•••
Thanks you Dan will test it when i get a change a bit later.

Great help!
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back