Jump to content

Recommended Posts

I have a function that creates a list of IP address and enters them into a table. Most of the enteries are poopulated with enteries from a file with the LOAD data infile command. These are entered into the DB in ascending order.

The below function enters the information info the table, but my problem in that it's entered in reverse order.

 

Can anyone offer any help for this problem?

 

Thanks in advance.

 

function CreateIPlist($ipAddress, $storeNumber, $count)

{

$IPlist[$count];

$networkNamelist[$count];

 

$OctetArray = explode(".", $ipAddress); // Break up the IP address into octets

 

for($i = 1; $i <= $count; $i++) // Loop through and increment last octet by 1.

{

 

$OctetArray[3]++;

$IPlist[$i] = implode('.', $OctetArray);

echo "$networkNamelist[$i] -----> $IPlist[$i] <br> ";

$result2 = mysql_query("INSERT INTO storeip SET storeNumber='$storeNumber', ipAddress='$IPlist[$i]', location='$networkNamelist[$i]'");

}

return $result2;

}

Thanks for the response - I've changed the Insert statement to :

 

$result2 = mysql_query("INSERT INTO storeip VALUE('$storeNumber', '$IPlist[$i]', '$networkNamelist[$i]')");

 

This also enters the values reversed - any other ideas?

Maybe try doing,

 

$OctetArray = explode('.', $ipAddress); // Break up the IP address into octets

$OctetArray = array_flip($OctetArray);

 

I might not be fully understanding the problem tho but that will flip the order of the octet's

This is the normal order in my DB:

 

Store    -   IP

 

55            10.10.10.1

55            10.10.10.2

55            10.10.10.3

55            10.10.10.4 ----> Etc....

 

I have hundreds of entries ordered in this way. However, my function enters new entries like this:

 

56            10.10.11.6

56            10.10.11.5

56            10.10.11.4

56            10.10.11.3

56            10.10.11.2

56            10.10.11.1

 

Not too big a deal except that when I display them to the page the order is reversed - I don't really want to change the function to display the list.

 

Bryan

 

Try flipping the way the for statement runs...

 

function CreateIPlist($ipAddress, $storeNumber, $count)

{

  $IPlist[$count];

  $networkNamelist[$count];

 

  $OctetArray = explode(".", $ipAddress); // Break up the IP address into octets

     

  for($i = $count; $i > 0 $; --$i) // Loop through and increment last octet by 1.

  { 

 

      $OctetArray[3]++;

      $IPlist[$i] = implode('.', $OctetArray);

      echo "$networkNamelist[$i] -----> $IPlist[$i]

";

      $result2 = mysql_query("INSERT INTO storeip SET storeNumber='$storeNumber', ipAddress='$IPlist[$i]', location='$networkNamelist[$i]'");

  }

  return $result2;

}

Tough cookie to crack....Could try doing something like...

 

function CreateIPlist($ipAddress, $storeNumber, $count)

{

  $IPlist[$count];

  $networkNamelist[$count];

 

  $OctetArray = explode(".", $ipAddress); // Break up the IP address into octets

   

  for($i = $count; $i > 0 $; --$i) // Loop through and increment last octet by 1.

  { 

 

      $OctetArray[3]++;

      $IPlist[$i] = sort(implode('.', $OctetArray));

      echo "$networkNamelist[$i] -----> $IPlist[$i]";

      $result2 = mysql_query("INSERT INTO storeip SET storeNumber='$storeNumber', ipAddress='$IPlist[$i]', location='$networkNamelist[$i]'");

  }

  return $result2;

}

 

 

 

If that doesn't work i'm afraid i'm out of ideas lol.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.