Jump to content

Archived

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

natalieG

query problem

Recommended Posts

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

Share this post


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

Share this post


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

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.