natalieG Posted March 8, 2006 Share Posted March 8, 2006 we posted to the newbie forum, but didn 't get an answer that seemed to add uo and so we qre escalating to here. Hop you can help us:we have the below snippet in a script. we have verified that$PARTNUM=20.0100 does exsist in $PARTTABLE='MSDS_1", butmysql_num_rows returns 0;We did get an answer from newbie forum asking for data foramat of the column PARTNUM and the answwer is PARTNUM float(12,5) and heard no more respomnses. The die results are never printd, so I suppose the syntax is correct. what still happens is that the priont command returns 0, and we should see one row and return 1. we tried this with several other values of PARTNUM which we know are in the data base, annd the same thing happens. mySQL doies not find the records. we went intp Putty and tried to do a select on the same and several different values and it could not find the records either. A select on VARCHAR fields works fine. We noticed in Putty if we SELECT PARTNUM FROM MSDS_1 WHERE MFGR='Atmel' and it returns the right # of rows. If we query in Putty with SELECT PARTNUM FROM MSDS_1; not all the results show. In fact, none of the rows for mfgr=Atnel get retetrieved, but the others do so perhaps this a mySQL question rather than a PHP quesation. Hope you can help us.Natalie Good$PARTNUM=20.01000;$PARTTABLE='MSDS_1';$PARTQUERY="SELECT * FROM $PARTTABLE WHERE PARTNUM = '" . $PARTNUM . "'";$conn=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) ordie ('Did Not Connect');mysql_select_db(DB_NAME) ordie ('Cannot Set Database');$RESULTS=mysql_query($PARTQUERY) ordie ('Invalid PartSelect Operation');[b]print mysql_num_rows($RESULTS);[/b] Quote Link to comment https://forums.phpfreaks.com/topic/4395-mysql-query-problem/ Share on other sites More sharing options...
greycap Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352705:date=Mar 7 2006, 07:32 PM:name=natalieG)--][div class=\'quotetop\']QUOTE(natalieG @ Mar 7 2006, 07:32 PM) [snapback]352705[/snapback][/div][div class=\'quotemain\'][!--quotec--]$PARTNUM=20.01000;$PARTTABLE='MSDS_1';$PARTQUERY="SELECT * FROM $PARTTABLE WHERE PARTNUM = '" . $PARTNUM . "'";$conn=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) ordie ('Did Not Connect');mysql_select_db(DB_NAME) ordie ('Cannot Set Database');$RESULTS=mysql_query($PARTQUERY) ordie ('Invalid PartSelect Operation');[b]print mysql_num_rows($RESULTS);[/b][/quote]Your part num is being treated as a number so it will be truncated to 20.01.change it to:$PARTNUM="20.01000";When in doubt, print out your sql statement as well. Quote Link to comment https://forums.phpfreaks.com/topic/4395-mysql-query-problem/#findComment-15255 Share on other sites More sharing options...
natalieG Posted March 10, 2006 Author Share Posted March 10, 2006 [!--quoteo(post=352712:date=Mar 7 2006, 10:51 PM:name=greycap)--][div class=\'quotetop\']QUOTE(greycap @ Mar 7 2006, 10:51 PM) [snapback]352712[/snapback][/div][div class=\'quotemain\'][!--quotec--]Your part num is being treated as a number so it will be truncated to 20.01.change it to:$PARTNUM="20.01000";When in doubt, print out your sql statement as well.[/quote]The problem appears to be that the data for a float and decimal column ius tored in different formats on different systems. The safest way is to change the field definition to VARCHAR(n); This format is consistent across all platforms. The other way, which we have not tried is to dop the comparewith a test on the magnitude of the diofference. If you have two float numbers a,b then you needa "where absolute(a-b) < delta, where is less tghan q LSB of the numbers.Natalie Quote Link to comment https://forums.phpfreaks.com/topic/4395-mysql-query-problem/#findComment-16164 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.