Jump to content

mysql query problem


natalieG

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]
Link to comment
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.
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.