Jump to content


Photo

mysql query problem


  • Please log in to reply
2 replies to this topic

#1 natalieG

natalieG
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 08 March 2006 - 01:32 AM

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", but
mysql_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) or
die ('Did Not Connect');
mysql_select_db(DB_NAME) or
die ('Cannot Set Database');
$RESULTS=mysql_query($PARTQUERY) or
die ('Invalid PartSelect Operation');
print mysql_num_rows($RESULTS);

#2 greycap

greycap
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 08 March 2006 - 02:51 AM

[!--quoteo(post=352705:date=Mar 7 2006, 07:32 PM:name=natalieG)--][div class=\'quotetop\']QUOTE(natalieG @ Mar 7 2006, 07:32 PM) View Post[/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) or
die ('Did Not Connect');
mysql_select_db(DB_NAME) or
die ('Cannot Set Database');
$RESULTS=mysql_query($PARTQUERY) or
die ('Invalid PartSelect Operation');
print mysql_num_rows($RESULTS);
[/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.

#3 natalieG

natalieG
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 10 March 2006 - 05:00 PM

[!--quoteo(post=352712:date=Mar 7 2006, 10:51 PM:name=greycap)--][div class=\'quotetop\']QUOTE(greycap @ Mar 7 2006, 10:51 PM) View Post[/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 compare
with a test on the magnitude of the diofference. If you have two float numbers a,b then you need
a "where absolute(a-b) < delta, where is less tghan q LSB of the numbers.

Natalie




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users