PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > Missing Nubers
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Missing Nubers

Réponse
 
LinkBack Outils de la discussion
Vieux 11/12/2007, 22h55   #1
Brian
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Missing Nubers

Hi all



Sorry for the cross postings but there may be a simple solution that can be
done in SQL.

I am trying to work out if there are missing numbers in a range stored in a
database table.



The first problem is the number range is prefixed with UR (eg UR12345), what
I need to

try and work out it are there any numbers in the range missing, the range
should be from

UR1000 to UR30000, what the best way to try and work this out?



Thanks



Brian





--------------------------------------------------------------------------------

I am using the free version of SPAMfighter for private users.
It has removed 1005 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!



  Réponse avec citation
Vieux 12/12/2007, 03h48   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Missing Nubers

Brian wrote:
> Hi all
>
>
>
> Sorry for the cross postings but there may be a simple solution that can be
> done in SQL.
>
> I am trying to work out if there are missing numbers in a range stored in a
> database table.
>
>
>
> The first problem is the number range is prefixed with UR (eg UR12345), what
> I need to
>
> try and work out it are there any numbers in the range missing, the range
> should be from
>
> UR1000 to UR30000, what the best way to try and work this out?
>
>
>
> Thanks
>
>
>
> Brian
>
>


This is a bit off target for alt.php. But you could also try a
newsgroup for your database, i.e. comp.databases.(your_rdbms_here).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 12/12/2007, 17h11   #3
J.O. Aho
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Missing Nubers

Brian wrote:
> Hi all
>
>
>
> Sorry for the cross postings but there may be a simple solution that can be
> done in SQL.
>
> I am trying to work out if there are missing numbers in a range stored in a
> database table.
>
>
>
> The first problem is the number range is prefixed with UR (eg UR12345), what
> I need to
>
> try and work out it are there any numbers in the range missing, the range
> should be from
>
> UR1000 to UR30000, what the best way to try and work this out?


As far as I know, you would need to do

for($i=1000;$i<=30000;$i++) {
$query="SELECT count(*) FROM table WHERE column='UR{$i}'";
$res=mysqli->query($query);
if(!$res->num_rows) {
echo "Missing number is UR{$i}\n";
}
}


--

//Aho
  Réponse avec citation
Vieux 12/12/2007, 17h26   #4
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Missing Nubers

"Brian" <brianNOPSPAM@nrwp.co.uk> wrote in message
newszE7j.4685$745.1748@newsfe1-win.ntli.net...

> I am trying to work out if there are missing numbers in a range stored in
> a database table.


SELECT a.Id + 1 Missing
FROM foo a
LEFT JOIN foo b
ON b.Id = a.Id + 1
WHERE b.Id IS NULL

(that's one way...and faster than working over a resultset in php to get the
same result)

> The first problem is the number range is prefixed with UR (eg UR12345),
> what I need to
>
> try and work out it are there any numbers in the range missing, the range
> should be from
>
> UR1000 to UR30000, what the best way to try and work this out?


cast the result of right(a, length(a) - 2) as an integer and plug that into
the query above...changing the names to your appropriate tables and fields.


  Réponse avec citation
Vieux 12/12/2007, 17h27   #5
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Missing Nubers


"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:KaWdnaFtO9yOx8LanZ2dnUVZ_jednZ2d@comcast.com. ..
> Brian wrote:
>> Hi all
>>
>>
>>
>> Sorry for the cross postings but there may be a simple solution that can
>> be done in SQL.
>>
>> I am trying to work out if there are missing numbers in a range stored in
>> a database table.
>>
>>
>>
>> The first problem is the number range is prefixed with UR (eg UR12345),
>> what I need to
>>
>> try and work out it are there any numbers in the range missing, the
>> range should be from
>>
>> UR1000 to UR30000, what the best way to try and work this out?
>>
>>
>>
>> Thanks
>>
>>
>>
>> Brian
>>
>>

>
> This is a bit off target for alt.php. But you could also try a newsgroup
> for your database, i.e. comp.databases.(your_rdbms_here).


it looks like he's well aware of the ot-ishness of the post. can't you take
the whole 30 seconds it takes to write the damn thing! this ain't rocket
science you know.


  Réponse avec citation
Vieux 12/12/2007, 17h43   #6
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Missing Nubers


"J.O. Aho" <user@example.net> wrote in message
news:5saj15F17fsctU1@mid.individual.net...

> for($i=1000;$i<=30000;$i++) {
> $query="SELECT count(*) FROM table WHERE column='UR{$i}'";
> $res=mysqli->query($query);
> if(!$res->num_rows) {
> echo "Missing number is UR{$i}\n";
> }
> }


aho, i'm not going to say that's a crazy way to do it...but, just look at
the resources you're wasting! you really want to run a query for *every*
iteration? even this is more attractive...but butt-ugly:

$sql = array();
for ($i = 1000; $i <= 3000; $i++)
{
$sql[] = "
SELECT 'UR" . $i . " Id ,
COUNT(*) Missing
FROM table
WHERE column = 'UR" . $i . "
";
}
$sql = "
SELECT *
FROM
(
" . implode(' UNION', $sql) . "
)
WHERE Missing = 0
";
$query = mysqli->query($sql);
echo '<pre>' . print_r($query, true) . '</pre>';


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h56.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13274 seconds with 14 queries