drumhrd Posted June 11, 2009 Share Posted June 11, 2009 building test DB for some stuff..put some test data in and did a simple query. SELECT bandname FROM BANDS WHERE band_number = 25; +-----------------+ | bandname | +-----------------+ | Metal Militia | +-----------------+ 1 row in set (0.00 sec) Thought ok great..lets do the reverse and get the band_number where the bandname = "Metal Militia" I get empty set SELECT band_number FROM BANDS WHERE bandname = "Metal Militia"; Empty set (0.00 sec) Quote Link to comment https://forums.phpfreaks.com/topic/161773-solved-why-is-query-returning-empty-set/ Share on other sites More sharing options...
warhead2020 Posted June 11, 2009 Share Posted June 11, 2009 SELECT band_number FROM BANDS WHERE bandname = "Metal Militia"; try this... SELECT band_number FROM BANDS WHERE bandname = 'Metal Militia' try use single quote instead of double quote Quote Link to comment https://forums.phpfreaks.com/topic/161773-solved-why-is-query-returning-empty-set/#findComment-853598 Share on other sites More sharing options...
drumhrd Posted June 11, 2009 Author Share Posted June 11, 2009 It's a no go SELECT band_number FROM BANDS WHERE bandname = 'Metal Militia'; Empty set (0.00 sec) It seems to be doing this for everything..here is another piece of the test data doing the same thing mysql> SELECT bandname FROM BANDS WHERE band_number = 28; +------------------------+ | bandname | +------------------------+ | Guitars and Tractors | +------------------------+ 1 row in set (0.00 sec) mysql> SELECT band_number FROM BANDS WHERE bandname = 'Guitars and Tractors'; Empty set (0.00 sec) Quote Link to comment https://forums.phpfreaks.com/topic/161773-solved-why-is-query-returning-empty-set/#findComment-853601 Share on other sites More sharing options...
warhead2020 Posted June 11, 2009 Share Posted June 11, 2009 mysql> SELECT band_number FROM BANDS WHERE bandname = 'Guitars and Tractors'; try this... SELECT band_number,bandname FROM BANDS WHERE bandname = 'Guitars and Tractors'; add one more column in the select column statement.... Quote Link to comment https://forums.phpfreaks.com/topic/161773-solved-why-is-query-returning-empty-set/#findComment-853602 Share on other sites More sharing options...
PFMaBiSmAd Posted June 11, 2009 Share Posted June 11, 2009 How was your data entered into the database? It might have white-space/non-printing characters either before or after (probably new-line characters) the names. Quote Link to comment https://forums.phpfreaks.com/topic/161773-solved-why-is-query-returning-empty-set/#findComment-853605 Share on other sites More sharing options...
drumhrd Posted June 11, 2009 Author Share Posted June 11, 2009 nope still not working mysql> SELECT band_number,bandname FROM BANDS WHERE bandname = 'Guitars and Tractors'; Empty set (0.00 sec) here is how I added data to the DB..don't laugh..it's just test data. INSERT INTO BANDS (bandname, email, myspace, facebook, bio, genre, image, css_file) VALUES (" Metal Militia "," mailto:someband1@someplace.com "," http://www.myspace.com/something "," http://www.facebook.com/someband "," Metal Milita We stole our name from Metallica, because we are posers. We really play polka, but we want to be known as a metal band…yeha I like country..woo hoo..your momma's fat "," metal "," https://www.artists2you.com/images/ "," https://www.artists2you.com/css/221.css ") The only think I can do is use a LIKE clause to find it SELECT band_number FROM BANDS WHERE bandname LIKE '%Metal Militia%' ; +-------------+ | band_number | +-------------+ | 25 | +-------------+ 1 row in set (0.00 sec) Quote Link to comment https://forums.phpfreaks.com/topic/161773-solved-why-is-query-returning-empty-set/#findComment-853607 Share on other sites More sharing options...
PFMaBiSmAd Posted June 11, 2009 Share Posted June 11, 2009 I see excessive white-space both before and after the quotes - " Metal Militia " In programming, " Metal Militia " and "Metal Militia" are two completely different pieces of data because computers only do exactly what their code and data tells them to do. Quote Link to comment https://forums.phpfreaks.com/topic/161773-solved-why-is-query-returning-empty-set/#findComment-853608 Share on other sites More sharing options...
drumhrd Posted June 11, 2009 Author Share Posted June 11, 2009 well after really thinking about the input method..I realized I have leading and trailing spaces mysql> SELECT band_number FROM BANDS WHERE bandname = ' Metal Militia '; +-------------+ | band_number | +-------------+ | 25 | +-------------+ 1 row in set (0.00 sec) ANY IDEA ON HOW TO STRIP THEM OUT? THANKS FOR THE HELP GUYS Quote Link to comment https://forums.phpfreaks.com/topic/161773-solved-why-is-query-returning-empty-set/#findComment-853609 Share on other sites More sharing options...
PFMaBiSmAd Posted June 11, 2009 Share Posted June 11, 2009 Don't put the extra spaces in when the data is inserted, that wastes storage space and slows down any operation that accesses the data. Quote Link to comment https://forums.phpfreaks.com/topic/161773-solved-why-is-query-returning-empty-set/#findComment-853610 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.