php + mysql count consecutive data
Posted on
16th Feb 2014 07:03 pm by
admin
I have a database of values and I want to work out how to display them if the values match a consecutive pattern.
For example, I might have the table "eggs" with the values "1", "2", "3", "4", "6", "7", "8", "9", "10". Now if I were to count these up I'd have 9 total values, this is good. What I want to do is ONLY count the values where they have another 2 consecutive values after them. So for example if the above pattern is what I'm using and I want to check for 2 consecutive values, the following would happen:
1 -> correct, it is followed by "2" and "3".
2 -> correct, it is followed by "3" and "4".
3 -> false, it is followed by "4" but no "5"
4 -> false, it is followed by "6", no"5".
6 -> correct, followed by "7" and "8".
7 -> correct, followed by "8" and "9".
8 -> correct, followed by "9" and "10".
9 -> false, followed by "10" but no "11".
and this would return the total of 7, because 7 of these values are followed by 2 consecutive numbers, therefore are correct.
So my question: How would I go about this? Would it be a matter of a single (albeit complex) mysql query or will I have to do some more advanced stuff after fetching the array? If it's the second I can do that myself, but I'd like to (hopefully) do it in a query!
So, any ideas?
No comments posted yet
Your Answer:
Login to answer
101
14
Other forums
Php Mysql Page Loading Notice
Hi all,
I was wondering if there is a way (Sure there is) of showing a message or an image wh
Filling gaps in dates
So i'm doing a query for sales data and my return array looks like this
('date' => '20
array_combine() trouble w/csv file
I have a problem with a piece of code I wrote to import some records from a csv file into mysql. I h
GET vs SUBMIT Button to show sections on one index.php page?
Just curious if one of these ways is better (i.e. more efficient) than the other.
I have a
help understanding hidden input w/ php
hello i'm doing a tutorial where there are multiple forms for an edit page for a user to update thei
Calling a Procedure with IN & OUT Parameters
Hello,
I usually call my procedures using the following way
declare variable e
Local file browser with php
Halo..
So this is what i want to create. I have a folder that i share and it has many movies.
Pre-Fill out a PHP form...??
This is for work actually (geek squad). We have to fill out this online php form at work over and ov
Bar charts using Graphical Framework.
I am using Graphical Frameworks(GFW) to create a chart Graphic . There is no problem with the data d
Need help with some php code :)
Hey! I'm quite new to this whole thing, so please don't fire me with shait on this one =D
I'm