/    Sign up×
Community /Pin to ProfileBookmark

Getting the next record using php

Say i’m on a page in my website:

[B]page.php?story_id=1[/B]

and I get that information out for that id (1)

But say I want to get the next record in the databases information, how could I do that in a query. ie?

[code=php]
$story_id = $_GET[‘story_id’];
$query_one = “Select * from stories WHERE story_id = “.$next_story.””;
[/code]

I know I could make $next_story = $story_id+1, but the next record in my databases story_id = 8 (ie several have been deleted), so that would not work?

Any suggestions?

Thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@DaiLaughingJul 29.2009 — WHERE story_id>$story_id

To get the ones higher than the current

ORDER BY $story_id ASC

That will sort them so the next one is at the top

LIMIT 1

That means give me just the one.
Copy linkTweet thisAlerts:
@MindzaiJul 29.2009 — You should also be sure to clean user input before using it in a query like that. You are open to SQL injection otherwise.
×

Success!

Help @chrisb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...