There is a query in the database to output all the lines. Then in the loop we get all the id.

while($row = $db->get_row($sql_cat)) { $cat .= $row['id']; } 
  • one
    What get_row return? - Naumov

1 answer 1

Well, in the simplest case:

 while($row = $db->get_row($sql_cat)) { if($row['id'] == 15) { continue; } $cat .= $row['id']; } 

Documentation: http://php.net/manual/ru/control-structures.continue.php

Pay attention: it is not always good to do this directly in real applications, since in fact, some constant is hardcoded and the output does not always start with id = 1 or id = 15, it would be more correct to bring the code to the following form:

 $is_first_row = true; while($row = $db->get_row($sql_cat)) { if($is_first_row) { $is_first_row = false; continue; } $cat .= $row['id']; } 

Also, if you are working with a database, you could have filtered the value at an earlier stage (when making a request to the database). It would hardly save much resources, just for a common understanding. Do you work with MySql? Read about LIMIT and OFFSET.

The if option helps to skip any line (at the beginning, in the middle) or several lines with any condition. Using LIMIT + OFFSET you can skip the first line, in the middle it will not work. Plus, I suspect that you want to output " everything except the first" - and for this you need to set a deliberately large number . In general, this "all" in real applications is rarely needed, it is usually put pagination ...

Plus, read for general understanding this question: Skip the first entry in the foreach loop - the options for other cycles are described there.

  • The minus for the "castell" if is not the best option for this, especially since you wrote it. - Naumov
  • @Naumov What exactly do you dislike and what option do you offer? - AK
  • if (id==15) I deleted the record and became the first 16, and the algorithm crashed. But you are right about the limit, so it’s worth asking the author what request? and after answer. - Naumov
  • @Naumov And now I understand what you are saying. Indeed, too lazy. Completed the answer. - AK