sorry can’t seem to get this into the formatted code for some reason… But here is my ugly code so far. Its pretty complicated as users can search for a beach where beach name or county is like their search criteria or if it matches a postcode in my postcode table it returns everything within a radius (haven’t included postcode table query)
//Postcode table checked for match and will return the example lat/longs in the query below if they exist
if($total_num_of_postcodes >0) {
$specify = ", beaches.latitude,beaches.longitude, ( 3959 * acos( cos( radians('57.138') ) * cos( radians( beaches.latitude ) ) * cos( radians( beaches.longitude ) - radians('-2.092') ) + sin( radians('57.138') ) * sin( radians( latitude ) ) ) ) AS distance"; $specify_order="HAVING distance < '10' ORDER BY distance";
} else {
$specify_order = "Order by beaches.cust_id";
}
//Lets do a query based on the search criteria
$query = "Select beaches.beach_name,beaches.mcs_id,beaches.url,beaches.county,beaches.description,beach_type.bay, beach_type.cove, beach_type.harbour, beach_type.estuary,
beach_type.sand,beach_type.shingle, beach_type.pebbles, beach_type.rock, beach_type.mud, beach_type.marsh, beach_type.marina $specify
From beaches LEFT JOIN beach_type ON beaches.mcs_id = beach_type.mcs_id Where beaches.beach_name like ? OR beaches.county like ? $specify_order $specify_limit";
// Setup parameter to be bound into query
//we've already set this in the above query
// Get instance of statement
$stmt = $gbgconn->stmt_init();
// Prepare Query
if ($stmt->prepare($query)) {
// Bind Parameters [s for string]
$stmt->bind_param("ss",$search_name, $search_name);
// Execute statement
$stmt->execute();
// Store the result (to get properties)
$stmt->store_result();
// Get the number of rows
$num_of_rows = $stmt->num_rows;
// Bind result variables
if($total_num_of_postcodes >0) {
$stmt->bind_result($beach_name,$mcs_id, $beach_url, $county, $description, $btype_bay, $btype_cove, $btype_harbour,$btype_estuary,$btype_sand,$btype_shingle,$btype_pebbles,$btype_rock,$btype_mud,$btype_marsh,$btype_marina,$latitude,$longitude,$distance);
} else {
$stmt->bind_result($beach_name,$mcs_id, $beach_url, $county, $description, $btype_bay, $btype_cove, $btype_harbour,$btype_estuary,$btype_sand,$btype_shingle,$btype_pebbles,$btype_rock,$btype_mud,$btype_marsh,$btype_marina);
}