5 Replies - 228 Views - Last Post: 22 April 2020 - 03:08 PM Rate Topic: -----

#1 testmetestyou   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 19-July 16

How to create "Next story" link what is in every article diffe

Posted 22 April 2020 - 01:47 PM

I want create button what gives every "Next Story" link unique link ID from database and doesnt duplicate.

I have only button "Next story" what should give me next story page. At the moment my code is checking if there is higher ID than this post and then you can click "Next story".

I didn't find any snippet from google how to create link with ID what doesn't duplicate later.

$row = Db::run()->pdoQuery('SELECT c.name AS name, p.id AS id, p.created AS created, p.title AS title, p.body AS body, p.cover AS cover FROM projects AS p INNER JOIN categories AS c ON p.category = c.id WHERE p.id ="' . $id . '";')->results(); //this gves current story data

$nrow = Db::run()->pdoQuery('SELECT 
	(SELECT MIN(id) AS id FROM projects WHERE id > p.id) as next_id, 
	(SELECT title FROM projects WHERE id > p.id) as next_title,
	(SELECT cover FROM projects WHERE id > p.id) as next_cover,
	(SELECT c.name AS name FROM projects AS a INNER JOIN categories AS c ON a.category = c.id WHERE a.id > p.id) AS next_name
FROM projects p WHERE p.id = "' . $id . '"')->results(); //this gives "Next story" data


$tpl->data = $row;
$tpl->next = $nrow;


My front:
<div class="next-project" data-dsn-footer="project">
    <div id="dsn-next-parallax-img" class="bg w-100">
        <div class="bg-image cover-bg" data-overlay="2"
            data-image-src="<?php echo SITEURL . '/uploads/projects/'  . $this->next[0]->next_name . '/' . $this->next[0]->next_cover; ?>"></div>
    </div>

    <div id="dsn-next-parallax-title" class="project-title">
        <a href="<?php echo SITEURL . '/p/' . $this->next[0]->next_id; ?>" class="effect-ajax" data-dsn-ajax="next-project">
            <div class="title-text-header">
                <div class="title-text-header-inner">
                    <span><?php echo $this->next[0]->next_title; ?></span>
                </div>
            </div>
            <div class="sub-text-header">
                <h5>Next Story</h5>
            </div>
        </a>
    </div>
</div>


Image of front view:
Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: How to create "Next story" link what is in every article diffe

#2 Splashsky   User is offline

  • D.I.C Addict
  • member icon

Reputation: 9
  • View blog
  • Posts: 565
  • Joined: 25-August 13

Re: How to create "Next story" link what is in every article diffe

Posted 22 April 2020 - 01:48 PM

So long as it's an indexed integer that auto increments, there will never be a duplicate ID.
Was This Post Helpful? 0
  • +
  • -

#3 testmetestyou   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 19-July 16

Re: How to create "Next story" link what is in every article diffe

Posted 22 April 2020 - 01:56 PM

View PostSplashsky, on 22 April 2020 - 01:48 PM, said:

So long as it's an indexed integer that auto increments, there will never be a duplicate ID.


Its possible if you click "Next story" and then new article pops up and there is new "Next story" button and has previous story ID. Or if possible like latest "Story" - ID 50 and then no more stories in database and it should start over where is first "Story" - ID
Was This Post Helpful? 0
  • +
  • -

#4 Splashsky   User is offline

  • D.I.C Addict
  • member icon

Reputation: 9
  • View blog
  • Posts: 565
  • Joined: 25-August 13

Re: How to create "Next story" link what is in every article diffe

Posted 22 April 2020 - 01:57 PM

I mean, as long as when you load the article, you're feeding the Next Story button the next ID, that won't be a problem. If there's no next ID, start over at 1.
Was This Post Helpful? 0
  • +
  • -

#5 testmetestyou   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 19-July 16

Re: How to create "Next story" link what is in every article diffe

Posted 22 April 2020 - 02:03 PM

View PostSplashsky, on 22 April 2020 - 01:57 PM, said:

I mean, as long as when you load the article, you're feeding the Next Story button the next ID, that won't be a problem. If there's no next ID, start over at 1.

How I should do that? little snippet if I dont know which is first Story ID (Its not always 1 if there is deleted stories, possible like lowest ID)
Was This Post Helpful? 0
  • +
  • -

#6 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2757
  • View blog
  • Posts: 8,059
  • Joined: 15-January 14

Re: How to create "Next story" link what is in every article diffe

Posted 22 April 2020 - 03:08 PM

Use ORDER BY and LIMIT in the SQL query. Order by the ID and limit to 1 result.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1