Jump to content


Photo

query problem


  • Please log in to reply
2 replies to this topic

#1 natalieG

natalieG
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 07 March 2006 - 01:50 AM

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;

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);



#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 07 March 2006 - 02:18 AM

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().

<?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);
?>

BTW, you can write your query as:
<?php
$PARTQUERY="SELECT * FROM $PARTTABLE WHERE PARTNUM = '$PARTNUM'";
?>

Ken


#3 natalieG

natalieG
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 07 March 2006 - 03:43 PM

The field PARTNUM is defined as float(12,5);
[!--quoteo(post=352352:date=Mar 6 2006, 10:18 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 6 2006, 10:18 PM) View Post[/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().

<?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);
?>

BTW, you can write your query as:
<?php
$PARTQUERY="SELECT * FROM $PARTTABLE WHERE PARTNUM = '$PARTNUM'";
?>

Ken
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users