Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the first digit of an input 1

Status
Not open for further replies.

Gojira999

Technical User
Jun 22, 2004
57
GB
Hi all.

I have built a database where the user inputs a postcode (split over two parts) and gets infromation returned.

What I would like to do is write a select statement that only extracts the first digit of the input data for the value used in the query, ie

User inputs - 4BU
The query searches on the value 4.

i have put together the following but it doen't appear to work to well (the value in question is variable $pc2).

Code:
$query = "SELECT
  DISTINCT location.postalcode,
  location.postal,
  venue.VenueType,
  venue.Name
FROM
  location LEFT JOIN venue
    ON location.RegionCode = venue.RegionCode
WHERE
  location.postalcode = '$pc1' AND
  location.postal = ('$pc2'+1) AND
  venue.VenueType = '$pc3'";

Or am I barking up the wrong tree - is this an action that should take place earlier?

Thanks for reading.
 
solved it!!!

it was
Code:
 location.postal = left('$pc2',1)
not
Code:
 location.postal = ('$pc2'+1)

thanks anyway!
 
Thanks for your post. I have been looking for something very similar for my application to build a dynamic menu. I appreciate your posting the answer with code! You've helped me, and saved someone from having to explain it to me!

Support BiJae's AIDS Walk, visit for details!

"Consider how much more you often
suffer from your anger and grief,
than from those very things for
which you are angry and grieved"

-- Marcus Antonius
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top