Jump to content
xisto Community
Sign in to follow this  
Inspiron

How To Check If Incrementing Misses A Number

Recommended Posts

Might want to consider that given the nature of the task, there may be instances where the number range of the missing Invoices is greater than the example you give.

ie: Results[0]=1001Results[1]=1002
Results[2]=1024
Results[3]=1070

You may want to cover this possibility by checking the range of missing numbers and echoing the start and end numbers instead of each individual number on the screen. Wouldn't take long to fill a screen or create a mass of output which isn't really required.

Share this post


Link to post
Share on other sites

Might want to consider that given the nature of the task, there may be instances where the number range of the missing Invoices is greater than the example you give. You may want to cover this possibility by checking the range of missing numbers and echoing the start and end numbers instead of each individual number on the screen. Wouldn't take long to fill a screen or create a mass of output which isn't really required.


That's even easier than displaying all the numbers in between. I leave it up to the original poster to decide what they want.

Share this post


Link to post
Share on other sites

Might want to consider that given the nature of the task, there may be instances where the number range of the missing Invoices is greater than the example you give. You may want to cover this possibility by checking the range of missing numbers and echoing the start and end numbers instead of each individual number on the screen. Wouldn't take long to fill a screen or create a mass of output which isn't really required.


We cannot rule out that possibility. Thanks for voicing out. However, chances are slim that voice numbers missed are greater than those that were entered in the database. Usually when a company misses an invoice number, it would most probably be that the order of the invoice has been broken such that the particular invoice number is being cancelled. It can also be that the invoice is torned or destroyed upon natural disasters such that a new invoice is being issued.

But anyway, that a very good point voiced. Now another question. How to check for invoice numbers for the point voiced by jlhaslip?

Share this post


Link to post
Share on other sites

For (i=0,i<Count(Results)-1,i++) {  If ((Results[i+1]-Results[i])>1) {	For (c=1,c<(Results[i+1]-Results[i]),c++) {	  echo Results[i]+c }}}
It worked! I'm quite surprised that you said you didn't test the code. A very big thank you to you.

But now I've another problem. It seemed easy again, but I took hours to use your codes and re-edit them to suit the SQL statement when the invoice numbers are arranged in decending order. Your code only works in acsending order, perfectly.

 

Another Question

Do you know how display those invoice numbers when the SQL statement is

"SELECT * FROM Table ORDER BY InvoiceNumber DESC" ?

 

Thanks again for being such a great help.. You saved me and my brain cells and helped me from going crazy.

Share this post


Link to post
Share on other sites

Why don't you just allow MySQL to arrange the output in ascending order for the Invoice ID, then run a PHP code to check whether it is running in order within a specified value?Example:<?php// Connect to DB$invoiceidmin = 1000;$invoiceidmax = 1054;$counter = $invoiceidmin;$result = mysql_query('SELECT * FROM table ORDER BY invoiceid ASC');while ($row = mysql_fetch_array($result) && $invoiceidmax != $counter) { if ($row["invoiceid"] != $counter) { $missing[] = $counter; } $counter++}$csvmissing = implode(",", $missing);print $csvmissing;?>

Edited by X155 (see edit history)

Share this post


Link to post
Share on other sites

It worked! I'm quite surprised that you said you didn't test the code. A very big thank you to you.

But now I've another problem. It seemed easy again, but I took hours to use your codes and re-edit them to suit the SQL statement when the invoice numbers are arranged in decending order. Your code only works in acsending order, perfectly.

 

Another Question

Do you know how display those invoice numbers when the SQL statement is

"SELECT * FROM Table ORDER BY InvoiceNumber DESC" ?

 

Thanks again for being such a great help.. You saved me and my brain cells and helped me from going crazy.

 


I'm not sure why you need to do it in ascending order because it doesn't matter. If you simply want to display the missing invoice numbers in the reverse order, simply change the echo statement that displays the missing invoice number to assign them into an array. Then manipulate the array anyway you like.

 

As for the other question, I'm not sure what you are asking... What do you mean? Another thing, if you are just manipulating invoicenumbers, you don't need to SELECT * --- Just need to SELECT InvoiceNumber

Share this post


Link to post
Share on other sites

Check out sort(), asort(), rsort(), arsort(), and ksort() at http://php.net/.

I thought it would work. I tried out but it failed. It displayed nothing out. I've actually tried to integrate rsort() with the codes provided by no9t9. But it wasn't possible.

I'm not sure why you need to do it in ascending order because it doesn't matter. If you simply want to display the missing invoice numbers in the reverse order, simply change the echo statement that displays the missing invoice number to assign them into an array. Then manipulate the array anyway you like.
As for the other question, I'm not sure what you are asking... What do you mean? Another thing, if you are just manipulating invoicenumbers, you don't need to SELECT * --- Just need to SELECT InvoiceNumber

In my script, I actually use the "SELECT" SQL statements to retrieve all the data from the database first. Then I store the total number of entries in the database in the array. With that array, I then used your codes which you've posted earlier on. Because initially I used the SQL statement "SELECT * FROM Table ORDER BY InvoiceNumber ASC", the Invoice Numbers extracted from the database are in accending order in the array as well. Hence your codes would work since it compares the current element in the array with the next element in the array. Your algorithm, let's call it a "+1" type, meaning it only compares the data in the element with the next (+1) element. However your codes cannot compare the current element with the previous element.

Currently, I'm extracting the data from the database in decending order, with the SQL statement as "SELECT * FROM Table ORDER BY InvoiceNumber DESC". Because the SQL statement is now in decending order, the new array that it stored the invoice numbers are also ordered in decending order. From then, the codes that you had provided is not possible to detect the missing invoice numbers, since your codes are the "+1" type as I've defined above. I believe you will need to edit the codes to become a "-1" type instead to work. But I don't know how.

I've also tried the suggestion from jlhaslip by using the rsort() function. I was trying to use the rsort() function to re-arrange the array order, which was then stored the invoice numbers in decending order with the SQL statement as "SELECT * FROM Table ORDER BY InvoiceNumber DESC". The rsort() function that I've used attempted to re-sort it back within the array itself, such that your previous codes can be used, using the "+1" type. However it failed.

This was what I've did, trying to use the rsort() function with the codes you've provided
					 $query = "SELECT * FROM Table ORDER BY InvoiceNumber DESC";					 $result = mysql_query($query);					 $num = mysql_numrows($result);					 $i = 0;					 $tempinv[] = "";					 while ($i < $num)					 {						$tempinv[$i] = mysql_result($result, $i, "InvoiceNo");						$i++;					 }						   rsort(tempinv);						   for ($i = 0; $i < count($tempinv) - 1; $i++)						   {							  if (($tempinv[$i+1] - $tempinv[$i]) > 1)							  {								 for ($c = 1; $c < ($tempinv[$i+1] - $tempinv[$i]); $c++)								 {									echo $tempinv[$i]+$c." ";								 }							  }						   }
It did not worked. I believe the codes which you've provided earlier on should be changed to a "-1" type, such that it can compare the current element in the array with the element of invoice number smaller than the current one. In another words, the codes should now do the opposite.
How do you do that? Let me know if you are using the rsort() function or not as well. Thanks..

Share this post


Link to post
Share on other sites

rsort should work. If you have copied your code directly out of your test page, it is not working because the variable you are using for the rsort function is missing the $.Try that. It should work.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.