natalieG Posted March 7, 2006 Share Posted March 7, 2006 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;Any idea what we are doing wrong? Thanks,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); Quote Link to comment https://forums.phpfreaks.com/topic/4281-query-problem/ Share on other sites More sharing options...
kenrbnsn Posted March 7, 2006 Share Posted March 7, 2006 How are your fields defined in the database?In your "or die" clauses, you should (at least during the debug stage), output the query that caused the error and the text sent my mysql_error().[code]<?php$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, error:' . mysql_error());mysql_select_db(DB_NAME) or die ('Cannot Set Database, error:' . mysql_error());$RESULTS=mysql_query($PARTQUERY) or die ('Invalid PartSelect Operation, query:' . $PARTQUERY . '<br />' . mysql_error());echo mysql_num_rows($RESULTS);?>[/code]BTW, you can write your query as:[code]<?php$PARTQUERY="SELECT * FROM $PARTTABLE WHERE PARTNUM = '$PARTNUM'";?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/4281-query-problem/#findComment-14905 Share on other sites More sharing options...
natalieG Posted March 7, 2006 Author Share Posted March 7, 2006 [b]The field PARTNUM is defined as float(12,5);[/b][!--quoteo(post=352352:date=Mar 6 2006, 10:18 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 6 2006, 10:18 PM) [snapback]352352[/snapback][/div][div class=\'quotemain\'][!--quotec--]How are your fields defined in the database?In your "or die" clauses, you should (at least during the debug stage), output the query that caused the error and the text sent my mysql_error().[code]<?php$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, error:' . mysql_error());mysql_select_db(DB_NAME) or die ('Cannot Set Database, error:' . mysql_error());$RESULTS=mysql_query($PARTQUERY) or die ('Invalid PartSelect Operation, query:' . $PARTQUERY . '<br />' . mysql_error());echo mysql_num_rows($RESULTS);?>[/code]BTW, you can write your query as:[code]<?php$PARTQUERY="SELECT * FROM $PARTTABLE WHERE PARTNUM = '$PARTNUM'";?>[/code]Ken[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/4281-query-problem/#findComment-15088 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.