473,466 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Selection based on ID number

Hi

I'm trying to write a function that will accept an ID number and
depending on certain criteria (that's what I need help with) it will
return a number between a specified range (lets say 1-10). The thing is
it must return the same number every time so any random functions are
out the window. I was using modulos but that's only good for 2 numbers.

ID's could be any number at all but the most important thing is the
number that is selected from the range must be the same for the ID
every time the function is ran no matter if the range grows. That is if
today I run it with a range of 1-10 and then tomorrow I run it with a
range of 1-20 the number that was returned yesterday for ID=28, for
example, should be the same number that is returned today for ID=28

Hope I've manged to make that clear ;)

Thanks

S66

Jul 17 '05 #1
8 1559
This is some pseudo code that might make it clearer.

GetNumber(23)

function GetNumber(ID){

//this function will return a number within the range specified based
on the ID passed

//define range
$min = 1;
$max = 12;

$retValue = 'do something with the id number so that we can return a
value between the $min and $max values';

return $retValue;

}

Thanks

S66

Jul 17 '05 #2
On 3 Apr 2005 06:38:37 -0700, "sphincter66" <sp*********@hotmail.com>
wrote:
This is some pseudo code that might make it clearer.

GetNumber(23)

function GetNumber(ID){

//this function will return a number within the range specified based
on the ID passed

//define range
$min = 1;
$max = 12;

$retValue = 'do something with the id number so that we can return a
value between the $min and $max values';

return $retValue;

}

Thanks

S66


You could store the first instance of the ID for later use.. something
along the lines of:
function getNumber($id) {
return rand(1, 10);
}
$id = 23;
$num = getNumber($id);
$res = mysql_query("
INSERT INTO " . SOME_TABLE . "
(
id,
num
)
VALUES (
$id,
$num
)
");

[ do rest of SQL validation here ]

Then next time, check to see if id 23 in the DB has a value assigned, if
so, read and use that value, if not, call getNumber() to assign them an
ID.
I hope this is an example of what you're looking for =)

Regards,

Ian
--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #3
Thanks for the response Ian. I guess that would work too. I was kind of
looking for a function that would actually be able to calculate the
return value on the fly.

If I can't come up with that solution this will be my 'fall back' plan.

thanks again

S66

Jul 17 '05 #4
On 3 Apr 2005 06:58:30 -0700, "sphincter66" <sp*********@hotmail.com>
wrote:

Hi S..

Thanks for the response Ian. I guess that would work too. I was kind of
looking for a function that would actually be able to calculate the
return value on the fly.

If I can't come up with that solution this will be my 'fall back' plan.

thanks again

S66

No probs =)

The "solution" I came up with was my initial thinking from the limited
info I had. Could you explain a little more how this will all be used?
Is it member id based based on certain criteria? or something completely
different?

You could write a function that just returns a fixed range of say 0-10,
but I'm not seeing the relevence of feeding it an ID number if you want
the output to be "static". I guess this is due to me not knowing how
you're thinking of implementing it all =)

If you need to return the same number.. I think you will end up having
to use a "marker" of some description.. although there's bound to be
many different ways to achieve this.

Regards,

Ian
--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #5
Hi Ian

The relevance of feeding it the ID is that this is the unique
identifier for the number returned. What I mean is that I need to have
the same number returned from the range specified based on the ID
passed. That is if 23 is passed as the ID and the range is 1-10 the
return may be 3 for example. The next time the function is called I may
have changed the range to 1-25 but if the ID passed is 23 it must still
return 3.

Your solution using a database would work but as I say I was really
hoping to find a solution that would calculate the return value.

Hope that clarifys it a bit.

S66

Jul 17 '05 #6
I've been thinking about this for a few hours and I'm not sure it can
be done. I may have to go with Ians database solution.

S66

Jul 17 '05 #7
I don't think so either, and here's the reason:

You're taking an infinite set of inputs and mapping them to a finite
set of outputs. So, suppose every number you could possibly input gets
mapped to a number between 1 and 25. You send in every single number
in the universe and get your mapping. The next day, you change your
range to 1 - 30. But every number is already mapped to something
between 1 and 25. So there can't be anything that would map to a
number between 26 and 30, since all the mappings have already been
created.

Ian is correct in that you have to "remember" what got mapped to what
(using a database or some other means).

Jul 17 '05 #8
On 3 Apr 2005 07:32:34 -0700, "sphincter66" <sp*********@hotmail.com>
wrote:

Hi S..
Hi Ian

The relevance of feeding it the ID is that this is the unique
identifier for the number returned. What I mean is that I need to have
the same number returned from the range specified based on the ID
passed. That is if 23 is passed as the ID and the range is 1-10 the
return may be 3 for example. The next time the function is called I may
have changed the range to 1-25 but if the ID passed is 23 it must still
return 3.

Your solution using a database would work but as I say I was really
hoping to find a solution that would calculate the return value.

Hope that clarifys it a bit.

S66

Yup, it does.. but as you've since discovered, I don't think there is
going to be a way of doing this without storing a previous value if
assigned. There probably is, using some "extreme" code and lots of
maths, but none that I'm aware of without some major thought.

I know you've already pretty much had this said by Zeldor too.. but I
thought it only polite to at least reply =)

Hope whatever method you do finally use works out ok.

Regards,

Ian
--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: serge calderara | last post by:
Dear all I have an ASP 1.1 application on which my user can filled some selection querry field like : ProductCatergorys (DropDownlist box) Product names (DropDownList) product number (text...
0
by: JS0001 | last post by:
I have inherited an Access database that was written in VBA and am still an amateur when it comes to VBA. I am tasked with computing a selection criteria based on a number of values that have to be...
7
imrosie
by: imrosie | last post by:
Hellol, I'm again in need of your help with my Order processing system.. My Order form is based on (query) of Customer and Order tables (includes a subform for the product data)...has a listbox...
4
by: banderson | last post by:
Hello amazing vba writers, I am trying to make a combo box return a value based on a combo box selection. I have tried a number of the codes posted here and am still having problems. I think it is...
3
by: Venturini | last post by:
I am trying to put together a web page where the customer makes choices of products and is then given a total. I am extremely new to Javascript and have managed to get as far as I have from web...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.