Question : Fix code to find repeated numbers in string

Hello Experts!


I have the following code to find repeated numbers in string:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
<?php
				for($i=0; $i<9999; $i++)
                {
				
				$con =mysql_connect("localhost","user","pass");
        		mysql_select_db("db", $con) or die( "Unable to connect with database");
				
                $result = mysql_query("SELECT * FROM tablename WHERE id=$i");
                $row=mysql_fetch_assoc($result);
				
                $NTM=($row['NTM']);
        		$cn=($row['Chart_Number']);

                	preg_match_all('#(\d*[a-z]*)[(-]#i', $NTM, $out);
                    $counted = array_count_values($out[1]);
                    foreach($counted as $key => $val) {
                    	if ($val > 1) { ?>
						<table <?php if ($key == NULL) {echo "style=display:none; visibility:none";} else echo ''; ?> >
						<tr>
                        	<td><?php if ($key == NULL) {echo '';} else echo $cn; ?></td>
                        	<td><?php echo $key; ?></td>
						</tr>
						</table>
						<?php
						}
                    }
				}
?>


It displays this output (example):

1  12
2  45
2  87
3  33

so if for example two numbers are repeated for same Chart_Number (2 in this case), the Chart_Number displays two times.

What I want, is display Chart_Number just once and display repeated numbers comma separated, so I want the following output:

1  12
2  45,87
3  33


In other words, have this:

1  12
2  45
2  87
3  33

want this:

1  12
2  45,87
3  33


Thanks for any help :-)

Answer : Fix code to find repeated numbers in string

Hello :)

In PowerShell make sure that this returns the files you want to remove:


$x = 30 # x days :)
Get-ChildItem "C:\YourFolder" | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-$x) }


If it does, add this onto the end:


Get-ChildItem "C:\YourFolder" | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-$x) } | Remove-Item


If you want to test it with Remove-Item on as well you'd need this:


Get-ChildItem "C:\YourFolder" | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-$x) } | Remove-Item -WhatIf


Remember that files deleted like this won't be going to the recycle bin, so make sure it really only gets what you want first.

HTH

Chris

PS. PowerShell is here if you don't already have it installed: http://support.microsoft.com/kb/968929
Random Solutions  
 
programming4us programming4us