Forums: Auto fill a field with next available number - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Auto fill a field with next available number Rate Topic: -----

#1 User is offline   schaet 

  • Member
  • PipPip
  • Group: Members
  • Posts: 12
  • Joined: 25-January 14

Posted 11 October 2018 - 01:31 PM

Hello,
I am trying to get a field to auto-populate based on a couple of criteria:

I have two fields that make up IP Address ranges, IE: range A= 10.10.10.1 - 10.10.10.20, Range B=10.10.10.21 - 10.10.10.30, Range C=10.10.10.31 - 10.10.10.40 and so on. What I am looking to do in auto-populate the IP field with the next available address in a given range based on the selection of the range.

Use case: I am creating a new record for range A. When I click 'Add' I would like the next available unused address in range 'A' to auto-populate the appropriate field.

The way I have my table is I that have a column called 'first_ip' and another called 'last_ip' and the one to auto-populate called 'ip'

I know that I will need to use INET_ATON to convert the IP addresses to a whole number, but I'm stuck on how to query against the 'ip' column and determine what hasn't been used yet and populate in the field.

Thanks!
0

#2 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 16000
  • Joined: 03-February 03

Posted 11 October 2018 - 02:44 PM

Here is an example of checking if specific record already exists. Should point you in the right direction:
https://xlinesoft.co...cord_exists.htm
Best regards,
Sergey Kornilov
0

#3 User is offline   schaet 

  • Member
  • PipPip
  • Group: Members
  • Posts: 12
  • Joined: 25-January 14

Posted 11 October 2018 - 07:04 PM

View Postadmin, on 11 October 2018 - 09:44 AM, said:

Here is an example of checking if specific record already exists. Should point you in the right direction:
https://xlinesoft.co...cord_exists.htm


Thank you. It is a good start on how the logic would work, but I think I would need to do this with the Javascript onload event to already choose a free value? Or am I looking at this the wrong way?
0

#4 User is offline   jadach 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 421
  • Joined: 26-April 08

Posted 11 October 2018 - 08:52 PM

This seems interesting to me. What if you had a view created on the database side that shows last recorded IP per range + 1 not to exceed 20 or whatever the end is? Then you can auto-populate that value.
-jerry
0

#5 User is offline   schaet 

  • Member
  • PipPip
  • Group: Members
  • Posts: 12
  • Joined: 25-January 14

Posted 12 October 2018 - 12:58 PM

jadach,
I see what you're saying, however I'm working with existing data and they are not all contiguous, so that will leave gaps.

I have a query that will breakdown the IP's by ranges that they belong to:

SELECT *
FROM `hosts`, ``
WHERE INET_ATON(ip) BETWEEN INET_ATON(first_ip) AND INET_ATON(last_ip);

This works well. I'm trying to figure out how to add to it to pick a random IP from the 'ip' column based on the select statement. I hope this makes sense.
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic