Reputation: 133
I have a page on my site
site.com/leads/id=1
It loads data with the following query
$id = $_GET['id'];
$lead = $this->db->get_where("leads", ["leadid" => $id]);
$lead = $lead->row();
I have a column in my leads table called USERID
.
Lets imagine the current page they are on the USERID
is set to 9.
How can I get the next and the previous ID from the database WHERE username is 9?
Hope this makes sense
Upvotes: 0
Views: 121
Reputation: 308
If you can do it in separate queries, the next will be
$this->db->get_where("leads", ["leadid" > $id, "username" => 9]);
and the previous will be
$this->db->get_where("leads", ["leadid" < $id, "username" => 9]);
Upvotes: 1
Reputation: 21899
You are overwriting your $lead
variable so with the first row of the data source, so that you cannot load the next row.
$id = $_GET['id'];
$lead = $this->db->get_where("leads", ["leadid" => $id]);
$firstRow = $lead->row();
$secondRow = $lead->row();
$thirdRow = $lead->row();
Upvotes: 0