PHP - Search Type Thingy

Discussion in 'Programming/Scripts' started by Rapid2214, Aug 7, 2010.

  1. Rapid2214

    Rapid2214 New Member

    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 [B] Could give a number like 101.262 or 12.344[/B]
    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
     
  2. falko

    falko Super Moderator ISPConfig Developer

    You could create an array with all distances and then use one of PHP's array sorting functions.
     
  3. Rapid2214

    Rapid2214 New Member

    Indeed, I have been looking around and am not sure how to achive this...
     
  4. falko

    falko Super Moderator ISPConfig Developer

  5. Rapid2214

    Rapid2214 New Member

    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 = :confused:)
    {
    blah
    blah
    }

    Thanks for your help!

    Marty
     
  6. falko

    falko Super Moderator ISPConfig Developer

  7. Rapid2214

    Rapid2214 New Member

    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
     
  8. Rapid2214

    Rapid2214 New Member

    Fixed, thanks for your help!

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

Share This Page