#1  
Old 7th August 2010, 21:55
Rapid2214 Rapid2214 is offline
Senior Member
 
Join Date: Jun 2010
Posts: 105
Thanks: 3
Thanked 5 Times in 5 Posts
Question PHP - Search Type Thingy

Hi,
I'm currently working on a project where i need to get some values from a database (easy).
Code:
$query = mysql_query("SELECT * FROM details")
Then i need to work out the distance using eastings & northings from the OS datapack (easy).
Code:
while($details = mysql_fetch_array($query))
{
..code...
$distance = getDistance($u_easting, $u_northing, $c_easting, $c_northing)
}
Code:
$distance  Could give a number like 101.262 or 12.344
I'm getting stuck where i need to order the allowed values (under a certain range) and display them...

Any ideas, all i can think of is reentering them into a temp database and pulling them out in order, but idealy i want to avoid this as it is too time consuming?

Thanks in advance...

Marty
Reply With Quote
Sponsored Links
  #2  
Old 8th August 2010, 20:48
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,735 Times in 2,571 Posts
Default

You could create an array with all distances and then use one of PHP's array sorting functions.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 8th August 2010, 22:18
Rapid2214 Rapid2214 is offline
Senior Member
 
Join Date: Jun 2010
Posts: 105
Thanks: 3
Thanked 5 Times in 5 Posts
Default

Indeed, I have been looking around and am not sure how to achive this...
Reply With Quote
  #4  
Old 9th August 2010, 13:43
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,735 Times in 2,571 Posts
Default

You can add your distances to the array as follows:
Code:
$distance_arr[] = $distance1;
$distance_arr[] = $distance2;
...
And then you could use the sort or rsort functions:
http://www.php.net/manual/en/function.sort.php
http://www.php.net/manual/en/function.rsort.php
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #5  
Old 9th August 2010, 22:44
Rapid2214 Rapid2214 is offline
Senior Member
 
Join Date: Jun 2010
Posts: 105
Thanks: 3
Thanked 5 Times in 5 Posts
Default

Thanks, that seems to work well, how would i display them?

Theres mysql_fetch_array(), would this work with a made up array, i think not?

I would like it to be like

while($row = )
{
blah
blah
}

Thanks for your help!

Marty
Reply With Quote
  #6  
Old 10th August 2010, 16:33
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,735 Times in 2,571 Posts
Default

Take a look here: http://www.developer.com/lang/php/ar...ays-in-PHP.htm
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
The Following User Says Thank You to falko For This Useful Post:
Rapid2214 (10th August 2010)
  #7  
Old 11th August 2010, 12:19
Rapid2214 Rapid2214 is offline
Senior Member
 
Join Date: Jun 2010
Posts: 105
Thanks: 3
Thanked 5 Times in 5 Posts
Default

Ok, i have an array like this:

Code:
Array ( [0] => Array ( [CID] => 14 [distance] => 9.82 )
How can i echo ['distance'] IF CID = 14 ??

I currently have:
Code:
echo $cid_array[14]['distance'];
But this brings back the row 14, which, after sorting is different to the CID...

Thanks

Marty
Reply With Quote
  #8  
Old 12th August 2010, 10:23
Rapid2214 Rapid2214 is offline
Senior Member
 
Join Date: Jun 2010
Posts: 105
Thanks: 3
Thanked 5 Times in 5 Posts
 
Default

Fixed, thanks for your help!

Code:
foreach($cid_array as $column => $result)	
{
	if ($result['CID'] == "$CID")
	{
		echo $result['distance']." Miles<br>";
	}
}
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CP210x USB to UART Bridge Linux VCP Drivers(SILICON Labs) perfectpol7 Kernel Questions 13 9th November 2010 07:30
Problem with services!! banzaiwebstudio.com Installation/Configuration 7 19th May 2010 21:13
Error when install ISPConfig 2 with components built from source X-admin Installation/Configuration 5 30th April 2010 13:22
Unable to install ISPConfig bdonecker Installation/Configuration 21 26th May 2009 08:20
Apache2 Freezes celtic Server Operation 31 28th May 2007 17:18


All times are GMT +2. The time now is 14:19.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.