I collected an id and wanted to make links for them to go back / forward. How can I do that? Here in this example, $id contains 24 23 20 18 87 6 :

 $idcontent = $this->article->getAllArticlesName($_GET["login"]); for($i = 0;$i < count($idcontent); $i++){ $id = $idcontent[$i]["id"]; print_r($id); } 
  • Provide more information on your subject, in particular, tell us what you mean by "make links for them to go back and forward." More attention, and most importantly - answers, collect those questions that were asked competently, exhaustively, so that you would not have to ask again and clarify the details in the comments. - neluzhin
  • This variant only adds id +1, and the transition to the next one is underway, BUT now it's netak - Shamil Shakirov
  • $ sr ["next"] = $ this-> config-> address. "? view = article & amp; id =". ($ sr ["id"] - 1); $ sr ["prev"] = $ this-> config-> address. "? view = article & amp; id =". ($ sr ["id"] + 1); - Shamil Shakirov
  • This is the id of the pages of a particular user, somehow the switch should go in this order 24 23 20 18 87 6: - Shamil Shakirov
  • $ sr ["next"] address url - Shamil Shakirov

1 answer 1

To get news with id greater than 3, 5, 9, we need:
Place identifiers in an array.

Go through the loop through the array, and find the nearest id, which is higher than the current one, while placing each new found news in the array.

After that, we can do with the array what we want.

 $array = ['3', '5', '9']; foreach($array as $q) { $nextNews[] = mysqli_fetch_assoc(mysqli_query($connect, "SELECT * FROM news WHERE id > $q LIMIT 1")); } var_dump($nextNews); 
  • Please try to write more detailed answers. I am sure the author of the question would be grateful for your expert commentary on the code above. - Nicolas Chabanovsky
  • This is your advice is very harmful. Offer in a cycle to hammer a base with queries where one is enough? - Vorobyov Alexander
  • At least something in two days. I understand that it is harmful, and there are more good solutions, for example, the same WHERE IN, but I have not yet understood how to make a WHERE IN (15.20.30> current ida.). - sasha_t
  • Well, surely this id sample (in question) is already a sequence of news following one after another. Therefore, it is necessary to determine only the previous for the first and the next for the last ... - Vorobyev Alexander