Jump to content

query problem


natalieG

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

Link to comment
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
Link to comment
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]
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.