Miko Posted April 30, 2009 Share Posted April 30, 2009 Hello, I'm making a script where a user can insert a value of 14 numbers to search a corresponding ID. This value should be broken down in 2 (first 4 numbers and then 10 numbers). I've done this with a substr so here no problem. But now I have to query this value with a BETWEEN. my code/query $parcel_depot = substr($searchterm, 0, 4); $parcel_number = substr($searchterm, 4, 10); $parcel_sql = "SELECT * FROM Number WHERE depot = '$parcel_depot' AND '$parcel_number' BETWEEN 'from' AND 'to'"; But seems that it doesn't work. What am I doing wrong here? Thanks :-) Quote Link to comment https://forums.phpfreaks.com/topic/156248-solved-php-mysql-between-query/ Share on other sites More sharing options...
Maq Posted April 30, 2009 Share Posted April 30, 2009 Well what is from and to? Are they supposed to be variables? Quote Link to comment https://forums.phpfreaks.com/topic/156248-solved-php-mysql-between-query/#findComment-822586 Share on other sites More sharing options...
fenway Posted April 30, 2009 Share Posted April 30, 2009 Yes, echo $parcel_sql Quote Link to comment https://forums.phpfreaks.com/topic/156248-solved-php-mysql-between-query/#findComment-822588 Share on other sites More sharing options...
Miko Posted April 30, 2009 Author Share Posted April 30, 2009 the 'from' and 'to' are the names of the columns Quote Link to comment https://forums.phpfreaks.com/topic/156248-solved-php-mysql-between-query/#findComment-822597 Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 Then don't put quotes around them. If you do, they'll be literals. If you want, use backticks. Quote Link to comment https://forums.phpfreaks.com/topic/156248-solved-php-mysql-between-query/#findComment-822617 Share on other sites More sharing options...
Miko Posted April 30, 2009 Author Share Posted April 30, 2009 hmmm, did not work either :-X. I'm thinking that I'm making a mistake with 'AND' that is between my 2 variables. Could be? Quote Link to comment https://forums.phpfreaks.com/topic/156248-solved-php-mysql-between-query/#findComment-822651 Share on other sites More sharing options...
kickstart Posted April 30, 2009 Share Posted April 30, 2009 Hi AND looks fine. As fenway says, echo out $parcel_sql and lets see what is being passed to MySQL. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/156248-solved-php-mysql-between-query/#findComment-822655 Share on other sites More sharing options...
Miko Posted April 30, 2009 Author Share Posted April 30, 2009 Dit that and got this: SELECT * FROM Number WHERE depot LIKE '0530' AND '7000732032' BETWEEN from AND to Quote Link to comment https://forums.phpfreaks.com/topic/156248-solved-php-mysql-between-query/#findComment-822657 Share on other sites More sharing options...
kickstart Posted April 30, 2009 Share Posted April 30, 2009 Hi Suspect from is confusing things as it has a meaning. Use back tics around the variable names (ie `, not a '). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/156248-solved-php-mysql-between-query/#findComment-822668 Share on other sites More sharing options...
Miko Posted April 30, 2009 Author Share Posted April 30, 2009 I need some sleep ... the table calls Nummer .. not Number .. Changed the name and it's working. D'oh! Thanks anywayz Quote Link to comment https://forums.phpfreaks.com/topic/156248-solved-php-mysql-between-query/#findComment-822683 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.