Hi All,

I know this is me missing something obvious, I just cannot see what. Let me run you through the problem first, bear in mind this is development code at the moment...

$query = "SELECT oid FROM {uc_attribute_options} WHERE aid='".$dst_aid."' AND name='".$form['name']['#default_value']."'";
$result = db_result(db_query("SELECT oid FROM {uc_attribute_options} WHERE aid='%d' AND name='%s'",$dst_aid,$form['name']['#default_value']));

The problem, $result has nothing in it. I know there is something in the table. How do I know this? Simple, I get Drupal to output the query and then enter it into phpmyadmin. The query is:

SELECT oid FROM {uc_attribute_options} WHERE aid='24' AND name='1 7/16inch ORFS Female, Straight'

Obviously I do not use the curly brackets in phpmyadmin. So entering it directly works fine. So this leads me to testing the following code in Drupal:

$query="SELECT oid FROM {uc_attribute_options} WHERE aid='24' AND name='1 7/16inch ORFS Female, Straight'";
$result = db_result(db_query($query));

So I have hardwired the query, and it works. So my question, why did/does the first code not work? I am assuming I may be missing an escape character or other special character but cannot see what, especially if it works hard wired.

Any help would be appreciated.
Regards,
Nick

Comments

nickbits’s picture

Hi,

Adding further to the puzzle l, I have tried another slightly different query, which works:

$query = "SELECT * FROM {uc_attribute_options} WHERE name='".$form['name']['#default_value']."'";
$result = db_query($query);

while($r=db_fetch_object($result)){
    dsm($r);
}

This is almost identical to the original code. The only difference is I am not grabbing a single field. This does work and kicks out the 3 results I expect. So if this works, why doesn't the code (first lot) in my original post?

Regards,
Nick

------------oOo----------------------
Nick Young (www.nickbits.co.uk)

nickbits’s picture

Hi,

Just for reference, nd I would still like to know why this does this, I have got it solved. The problem, in the table one of the entries for name has two spaces in it:

1 7/16inch  ORFS Female, Straight

Removing the extra space works fine. Not sure why this has suddenly become an issue. Anyway, just need to add some code (regexp or similar) to remove multiple spaces) to get

1 7/16inch ORFS Female, Straight

Regards,
Nick

------------oOo----------------------
Nick Young (www.nickbits.co.uk)