Re: [PHP-DB] array fill/sort question
Snijders, Mark wrote: hi, no the both sollutions won't work cause: I can't sort within a query cause subnetaddr is a varchar ("10.10.10.10") so it will be ordere like this 10.10.10.10 100.10.10.10 60.10.10.10 and that's not good cause 60 is smaller as 100, so with the function ip2long() i will first make an integer of it the second array solution you gave, won't work, cause I need ALL the query results in the array, and that's the problem I can't handle if I would do it like you said, I can sort it, but then I have a sorted array and for each element I have to do a query again to get the other fields of the table, and that's not good (2500 rows) so can please still somebody help me with this? can you change the database format ? store the address as four ints - then you can concatenate them when you need to, and sort as you wish SELECT s_id, subnet_name, concat(subnetaddr1, '.', subnetaddr2, '.', subnetaddr3, '.', subnetaddr4) as subnetaddr ,subnetmask,dnsdomain, location, contact, ccn FROM subnets ORDER BY subnetaddr1, subnetaddr2, subnetaddr3, subnetaddr4; -- Sean -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] array fill/sort question
Another approach: 1. Load all results from the query in an array 2. Sort the array using a custom-defined user-defined comparison function ( usort() ). Study the example in the PHP manual. Writing your own comparison function is easy: - explode your IP addresses in 4 items each ( explode() ) - compare successively item by item HTH Ignatius _ - Original Message - From: "Snijders, Mark" <[EMAIL PROTECTED]> To: "'Becoming Digital'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, June 11, 2003 8:33 AM Subject: RE: [PHP-DB] array fill/sort question > hi, > > no the both sollutions won't work cause: > > I can't sort within a query cause subnetaddr is a varchar ("10.10.10.10") > > so it will be ordere like this > > 10.10.10.10 > 100.10.10.10 > 60.10.10.10 > > and that's not good cause 60 is smaller as 100, so with the function > ip2long() i will first make an integer of it > > > the second array solution you gave, won't work, cause I need ALL the query > results in the array, and that's the problem I can't handle > > > if I would do it like you said, I can sort it, but then I have a sorted > array and for each element I have to do a query again to get the other > fields of the table, and that's not good (2500 rows) > > so can please still somebody help me with this? > > > > > -----Original Message- > From: Becoming Digital [mailto:[EMAIL PROTECTED] > Sent: dinsdag 10 juni 2003 15:42 > To: [EMAIL PROTECTED] > Subject: Re: [PHP-DB] array fill/sort question > > > I might be overlooking something, but can't you just do this? > > $query = "SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, > location, contact, ccn FROM subnets ORDER BY subnetaddr"; > > > If you can't, you can sort the array like this. > > $query = "SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, > location, contact, ccn FROM subnets"; > $results = mysql_query( $query ); > > while ( $iptable = mysql_fetch_array( $result ) ) { > $iptable['subnetaddr'] = ip2long( $iptable['subnetaddr'] ); > } > ?> > > You can subsequently sort the array for the desired result. > > Edward Dudlik > Becoming Digital > www.becomingdigital.com > > > - Original Message - > From: "Snijders, Mark" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Tuesday, 10 June, 2003 08:55 > Subject: [PHP-DB] array fill/sort question > > > hi, > > I'm working on a ipaddres/subnet programm > > now i have a talbe with a lot of information about ip-addresses > > i'm having this query: > > SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, location, contact, > ccn FROM subnets > > the subnetaddr field looks like this : 100.20.20.1 and is ofcourse a > varchar field > > BUT before displaying it on the screen i have to sort it by subnetaddr and > then show it > > but i have to sort it as integer, so i use the php-function ip2long(); > > so you get a decimal... > > so what i have to do: > > do the query> make a decimal field of the 'subnetaddr' put it in an array, > sort it and display it > > > BUT how can i put ALL of the fields in the query in an array, sort it, and > then display it? > > please help me, I can't work it out :( > > thanks, Mark > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] array fill/sort question
hi, no the both sollutions won't work cause: I can't sort within a query cause subnetaddr is a varchar ("10.10.10.10") so it will be ordere like this 10.10.10.10 100.10.10.10 60.10.10.10 and that's not good cause 60 is smaller as 100, so with the function ip2long() i will first make an integer of it the second array solution you gave, won't work, cause I need ALL the query results in the array, and that's the problem I can't handle if I would do it like you said, I can sort it, but then I have a sorted array and for each element I have to do a query again to get the other fields of the table, and that's not good (2500 rows) so can please still somebody help me with this? -Original Message- From: Becoming Digital [mailto:[EMAIL PROTECTED] Sent: dinsdag 10 juni 2003 15:42 To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] array fill/sort question I might be overlooking something, but can't you just do this? $query = "SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, location, contact, ccn FROM subnets ORDER BY subnetaddr"; If you can't, you can sort the array like this. You can subsequently sort the array for the desired result. Edward Dudlik Becoming Digital www.becomingdigital.com - Original Message - From: "Snijders, Mark" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, 10 June, 2003 08:55 Subject: [PHP-DB] array fill/sort question hi, I'm working on a ipaddres/subnet programm now i have a talbe with a lot of information about ip-addresses i'm having this query: SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, location, contact, ccn FROM subnets the subnetaddr field looks like this : 100.20.20.1 and is ofcourse a varchar field BUT before displaying it on the screen i have to sort it by subnetaddr and then show it but i have to sort it as integer, so i use the php-function ip2long(); so you get a decimal... so what i have to do: do the query> make a decimal field of the 'subnetaddr' put it in an array, sort it and display it BUT how can i put ALL of the fields in the query in an array, sort it, and then display it? please help me, I can't work it out :( thanks, Mark -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] array fill/sort question
I might be overlooking something, but can't you just do this? $query = "SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, location, contact, ccn FROM subnets ORDER BY subnetaddr"; If you can't, you can sort the array like this. You can subsequently sort the array for the desired result. Edward Dudlik Becoming Digital www.becomingdigital.com - Original Message - From: "Snijders, Mark" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, 10 June, 2003 08:55 Subject: [PHP-DB] array fill/sort question hi, I'm working on a ipaddres/subnet programm now i have a talbe with a lot of information about ip-addresses i'm having this query: SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, location, contact, ccn FROM subnets the subnetaddr field looks like this : 100.20.20.1 and is ofcourse a varchar field BUT before displaying it on the screen i have to sort it by subnetaddr and then show it but i have to sort it as integer, so i use the php-function ip2long(); so you get a decimal... so what i have to do: do the query> make a decimal field of the 'subnetaddr' put it in an array, sort it and display it BUT how can i put ALL of the fields in the query in an array, sort it, and then display it? please help me, I can't work it out :( thanks, Mark -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] array fill/sort question
hi, you can add the ip2long() function into your SELECT statement and have an ORDER BY clause at the end like this... SELECT s_id, subnet_name, ip2long('subnetaddr'), subnetmask,dnsdomain, location, contact, ccn FROM subnets ORDER BY subnetaddrr; hope it helps. KD On Tue, 10 Jun 2003, Snijders, Mark wrote: > hi, > > I'm working on a ipaddres/subnet programm > > now i have a talbe with a lot of information about ip-addresses > > i'm having this query: > > SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, location, contact, > ccn FROM subnets > > the subnetaddr field looks like this : 100.20.20.1 and is ofcourse a > varchar field > > BUT before displaying it on the screen i have to sort it by subnetaddr and > then show it > > but i have to sort it as integer, so i use the php-function ip2long(); > > so you get a decimal... > > so what i have to do: > > do the query> make a decimal field of the 'subnetaddr' put it in an array, > sort it and display it > > > BUT how can i put ALL of the fields in the query in an array, sort it, and > then display it? > > please help me, I can't work it out :( > > thanks, Mark > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php