1

This is my query

SELECT * from status_votes where vote = 'like' and status_id = 1 and item_poster = 'LUcase'

It returns 0 rows, but when I view the table there are rows which match my query phpmyadmin displaying the row

Please let me know where I am going wrong...

2
  • please provide table structure... Commented Feb 26, 2012 at 8:26
  • check Abhay answer.. it should solve your problem... Commented Feb 26, 2012 at 8:36

3 Answers 3

3

My assumption is that perhaps there are leading or trailing spaces in your data that aren't visible looking at the values in phpMyAdmin. Can you please try to edit a record in phpMyAdmin and see if it actually contain spaces.

Please try running this query:

SELECT *
FROM status_votes
WHERE TRIM(vote) = 'like'
AND status_id = 1
AND TRIM(item_poster) = 'LUcase';

If that doesn't work, can you please share your table structure?

Sign up to request clarification or add additional context in comments.

5 Comments

i edited the record and the field shows LUcase���������� Why is this?
@MarshallMathews, I can't actually comment, for certain, on this. It depends on where the data is being inserted into the field. But my guess is that item_poster contains some special characters, which phpMyAdmin isn't able to render correctly. If possible, perhaps you can try running the select query in the MySQL command-line client.
ok im doing a 2 way encryption using mcrypt and that causes the weird characters.. is there a better way for 2 way encryption
This is weird. If you are encrypting your data, it is obvious that item_poster = 'LUcase' will never give a match. You will have to either decrypt the column before doing the comparison or encrypt "LUcase" before passing it into the query
yes i am decrypting it before doing the query and it gave the empty spaces, well nevermind. I used base64 encode/decode and it worked fine :)
3

Try reducing your query to see which WHERE clause is causing problems:

Try these ONE line at a time:

SELECT * from status_votes where vote = 'like' and status_id = 1 and item_poster = 'LUcase'
SELECT * from status_votes where vote = 'like' and status_id = 1 and item_poster = 'Lucase'
SELECT * from status_votes where vote = 'like' and item_poster = 'LUcase'
SELECT * from status_votes where status_id = 1 and item_poster = 'LUcase'
SELECT * from status_votes where vote = 'like' 
SELECT * from status_votes where status_id = 1 
SELECT * from status_votes where item_poster = 'LUcase'
SELECT * from status_votes 

It shouldn't be hard to isolate the problem...

2 Comments

Any query with item_poster returns 0 rows, this is weird.
So item_poster is your problem. Find out if there are any spaces around it. Try item_poster like '%LUcase%'
0

Try the following query:

SELECT * FROM `status_votes`
 WHERE `vote` = 'like'
   AND `status_id` = '1'
   AND `item_poster` = 'LUcase' 

2 Comments

are you trying it from phpmyadmin? or from your php script?
phpmyadmin, like i commented in the other answer Anything without item_poster in the where clause returns rows :( STUPID MYSQL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.