Jump to content

Archived

This topic is now archived and is closed to further replies.

natalieG

mysql query problem

Recommended Posts

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');
[b]print mysql_num_rows($RESULTS);[/b]

Share this post


Link to post
Share on other sites
[!--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) or
die ('Did Not Connect');
mysql_select_db(DB_NAME) or
die ('Cannot Set Database');
$RESULTS=mysql_query($PARTQUERY) or
die ('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.

Share this post


Link to post
Share on other sites
[!--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 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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.