Jump to content

Mike521

Members
  • Posts

    29
  • Joined

  • Last visited

Everything posted by Mike521

  1. Hi all, I'm using the following PHP / MySQL code to grab zip codes from our database. this is for a "search by zip code" function. Right now the zip field contains only one zip code, but I'd like to make it a comma separated list of zips, and have mySQL search each of the zips, when there is more than one present. Is that possible? Here's the existing statement: [code] $selection = "some columns to select"; $zipcode = "11787"; //this can be any zip code, it's not really hardcoded like this. $low = $zipcode - 2500; //the lowest number we'll consider a close enough match $high = $zipcode + 2500; //the highest number we'll consider a close enough match //the ABS stuff below is just to order the results by the closest to $zipcode $query = "SELECT $selection, ABS(zipcode-$zipcode) AS distance FROM ourDB WHERE zipcode BETWEEN $low AND $high ORDER BY distance"; [/code] so we have $zipcode which is a php variable, and zipcode which is a column in our DB. right now the column only has one zip, but I'd like to have multiple zips and still do the whole search in mysql. the alternative is to have a comma separated list, grab ALL the zipcodes into php, explode, and loop through with php.. what a pain.. any ideas? thanks everyone
  2. works perfect, thanks!! edit: can you point me to some documentation that explains the AS statement you used? i've seen it used a couple of times and looks really useful but I don't quite understand how it works yet hopefully I can read up on it and do things like this with no problem in the future
  3. Hi all, if you have a query ordered by whatever, is it possible to check if a certain item exists, and then move that item to the top of the list?
  4. hi all, is it possible to use htaccess password protection and send a user to a different file depending on their login credentials? so user A would go to admin/userA.php and userB would go to admin/userB.php? Or is it possible to send all users to a php script that simply registers their username in a global variable and then redirects them to "users.php" which then grabs their username and displays material accordingly? Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.