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 Like 14 Dislike
Previous forums Next forums
Other forums

How could I combine these arrays??
Hello.. I'm trying to figure out a way to combine these first two arrays to get the last array..

Mysql query, two times?
Hello to all,

I'm new to php coding and i like it alot. I need help with some noob stuff.

Using CSS to format MySQL query
Hi,

If i want to have a news page on my site, which displays all records of a table in descen

Big O & time complexity ???
can you help me how to calculate the Big O & time complexity for any algorithm and c++ program pleas

Windows Authentication
I have a website which is windows authenticated.
now i want something more on this application.<

Using Microsoft Exchange Server with PHP
Hi,

I wanted to know if its possible to fetch email attachments from the exchange server usin

Typedef struct vs just struct
Anyone know the rationale for using typedef for structs when a struct is itself a typedef? I have s

start new row of pictures
on my site www.budstreasureauctions.com there is a featured auctions box that users will pay to get

Open browser page depending on XML results
Hello,

I have some PHP code that sends webbased from data to an external url ( in the form of

how to easy edit text, with box? Help.
Hi.
I have a little problem. I'm doing a webpage for my aunt and I would like to make it as easy

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash