Current location: Hot Scripts Forums » Other Discussions » Database » Mysql query problem


Mysql query problem

Reply
  #1 (permalink)  
Old 04-01-11, 07:02 AM
anjum015 anjum015 is offline
New Member
 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb Mysql query problem

Hi,
I've a database currently with 400 rows. When I query anything (from frontend,localhost) beyond 125 results are not returned. I'm using WAMP .

My query is very simple based on primary key I'm just doing SELECT * FROM tablename WHERE pid='variable';


The database will contain at least a 5000 rows. I'm not sure how to query.
Reply With Quote
  #2 (permalink)  
Old 04-01-11, 08:24 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
How many results are returned when you say:
"SELECT * FROM tablename" ?
__________________
Jerry Broughton
Reply With Quote
  #3 (permalink)  
Old 04-01-11, 09:41 AM
sqlhjalp sqlhjalp is offline
New Member
 
Join Date: Apr 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Explain

Did you confirm all that you have in the table?


mysql> SELECT count(pid) as cnt FROM tablename group by pid

Then you can at least confirm what all you have. Maybe you have different values that you think?
Reply With Quote
  #4 (permalink)  
Old 04-01-11, 11:10 AM
nafirici nafirici is offline
Newbie Coder
 
Join Date: Mar 2011
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
some tools automatically limit the number of results. Check the preferences of the tool you're using to run the query. If you're having trouble finding this in preferences, you can order by asc then order by desc and see if the first record when you do desc was the same as the last record in asc.
Reply With Quote
  #5 (permalink)  
Old 04-01-11, 11:57 PM
anjum015 anjum015 is offline
New Member
 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for quick reply. When I displayed the entire table all the records are being displayed.
A few things I dint mention before pid datatype is VARCHAR .

After a lot of trials what I observed is some values beyond 125 also get displayed. I'm not sure what is happening. My database content mostly ( mostly name, address) are in UTF8.

The following weird things I experienced.
When I query from frontend dev using PHP, if I enter say 150 I don't get any result.
my query in php is mysql_query("SELECT * FROM customerdb WHERE PID='$_POST[pid]'");
It dint give any result.
Just to try instead of using $_post [pid] I directly gave number. It worked at that time.
I'm not sure what the problem is.

I need to figure it out asap please help.
Reply With Quote
  #6 (permalink)  
Old 04-02-11, 12:11 AM
anjum015 anjum015 is offline
New Member
 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,
I think the problem was with the way it was getting stored as at the client's desktop they use a different software to input UTF8 characters.
I changed the query and queried using LIKE it is working fine now.
Thank you, I just panicked .
Thanks a lot everyone.
Reply With Quote
  #7 (permalink)  
Old 04-02-11, 10:48 AM
nafirici nafirici is offline
Newbie Coder
 
Join Date: Mar 2011
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Please also make sure that you sanitize your data to help prevent sql injections:
PHP: mysql_real_escape_string - Manual
Reply With Quote
  #8 (permalink)  
Old 04-02-11, 06:12 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
It is possible that $_POST[pid] is not returning a value because it should probably be $_POST["pid"].
So after making that correction, try it like this:
PHP Code:

mysql_query("SELECT * FROM customerdb WHERE PID='".$_POST["pid"]."'"); 

__________________
Jerry Broughton
Reply With Quote
  #9 (permalink)  
Old 04-05-11, 02:42 AM
anjum015 anjum015 is offline
New Member
 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,
The problem was with the way it was getting stored. Pid values were storing even '\t' while entering from the front end.
Reply With Quote
Reply

Bookmarks

Tags
limit, mysql, select, wamp


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Help for a complex mysql Query. subuntug PHP 6 11-17-10 06:42 PM
[SOLVED] Mysql query error xEX3CUT1ONx PHP 3 02-02-10 05:11 PM
MySQL Problem NationVoice Database 2 04-29-08 05:26 AM
mySQL - DISTINCT Query mcrob Database 9 02-07-07 12:22 PM
MySQL Expert Required!! Advanced Query Problem bluey_the_punch PHP 1 02-28-04 01:37 PM


All times are GMT -5. The time now is 05:15 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.