1

I need some help. Goal is to get IDs for next and previous ID by "Open" Status.

  1. I have all records in grid listing in a status called "Open".
  2. When click record link and view record, I have added 2 buttons (previous and next)
  3. I want to be able to see the next and previous IDs in "Open" status.
  4. URL looks like this localhost/my_crm/index.php/projects/view/5
  5. Next URL should look like localhost/my_crm/index.php/projects/view/7 (since record view/6 is in Closed status)
  6. Logic should follow (if project status ID is in Open status, get next ID in Open status.)

My code works, but lists previous and next sequentially (due to id+1 and id-1). Button code does not call the previous or next ID in Open status. Here's example of my next button.

Please help.

<a href="<?php if ($project_info->status->id == "open") {

             echo $project_info->status->id+1;
         }

         ?>">Next </a>
</button>

I am new to PHP and codeigniter so any help is appreciated. Mario

Jan Černý
  • 1,268
  • 2
  • 17
  • 31
  • `$project_info->status->id` can never be equal to the string `open` if it's an integer. You'll likely wan't to query for all projects with the status of open, and then go about building your markup off that. – Ryan Kozak May 21 '18 at 19:59
  • For more specification, how would the result be echo'd out? – Mario G. Rojas May 21 '18 at 20:09
  • Comparing integers to strings can be tricky. The result may be true, but it's not true for the reasons you're intending. This question provides more detail on PHP integer to string comparisons https://stackoverflow.com/questions/672040/comparing-string-to-integer-gives-strange-results. – Ryan Kozak May 21 '18 at 20:12

0 Answers0