Jump to content

INSERT INTO - enters list in reverse - HELP PLEASE


Malachi0944

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;

}

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.