Malachi0944 Posted June 14, 2007 Share Posted June 14, 2007 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; } Quote Link to comment https://forums.phpfreaks.com/topic/55600-insert-into-enters-list-in-reverse-help-please/ Share on other sites More sharing options...
Illusion Posted June 14, 2007 Share Posted June 14, 2007 check your MySQL query , you are using SET in INSERT statement it doesn't work.Check the syntax for INSERT statement. Quote Link to comment https://forums.phpfreaks.com/topic/55600-insert-into-enters-list-in-reverse-help-please/#findComment-274702 Share on other sites More sharing options...
Malachi0944 Posted June 14, 2007 Author Share Posted June 14, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/55600-insert-into-enters-list-in-reverse-help-please/#findComment-274707 Share on other sites More sharing options...
kenrbnsn Posted June 14, 2007 Share Posted June 14, 2007 Using the "Set" format is an acceptable alternative in the Insert statement in MySQL. I use it all the time. Ken Quote Link to comment https://forums.phpfreaks.com/topic/55600-insert-into-enters-list-in-reverse-help-please/#findComment-274716 Share on other sites More sharing options...
Illusion Posted June 14, 2007 Share Posted June 14, 2007 This also enters the values reversed - any other ideas? what is it means. Quote Link to comment https://forums.phpfreaks.com/topic/55600-insert-into-enters-list-in-reverse-help-please/#findComment-274729 Share on other sites More sharing options...
Nhoj Posted June 14, 2007 Share Posted June 14, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/55600-insert-into-enters-list-in-reverse-help-please/#findComment-274731 Share on other sites More sharing options...
Malachi0944 Posted June 14, 2007 Author Share Posted June 14, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/55600-insert-into-enters-list-in-reverse-help-please/#findComment-274735 Share on other sites More sharing options...
Nhoj Posted June 14, 2007 Share Posted June 14, 2007 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; } Quote Link to comment https://forums.phpfreaks.com/topic/55600-insert-into-enters-list-in-reverse-help-please/#findComment-274748 Share on other sites More sharing options...
Malachi0944 Posted June 14, 2007 Author Share Posted June 14, 2007 Thanks, I've tried this and it does work, however, then the echo statement outputs the list in reverse. Bryan Quote Link to comment https://forums.phpfreaks.com/topic/55600-insert-into-enters-list-in-reverse-help-please/#findComment-274758 Share on other sites More sharing options...
Nhoj Posted June 14, 2007 Share Posted June 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/55600-insert-into-enters-list-in-reverse-help-please/#findComment-274760 Share on other sites More sharing options...
Malachi0944 Posted June 14, 2007 Author Share Posted June 14, 2007 Won't this just sort the $Octet array? - I just tried it and it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/55600-insert-into-enters-list-in-reverse-help-please/#findComment-274785 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.