I have a table with several columns, I am trying to retrieve nid where a certain value is in found in the serialized data of column data.

So far, without luck I am trying.

<?php
$prod_nid = db_query("SELECT nid FROM {uc_cart_products} WHERE data LIKE %d", 44);
print db_result($prod_nid);
?>

44 is located in the data serialized data array.. This returns nothing. All help greatly apprecited!

Comments

tpainton’s picture

Ahh found it in another module.. whew

$result = db_query("SELECT * FROM {uc_cart_products} WHERE data LIKE '%%\"node_checkout_nid\";i:%d;%%'", $nid);
nevets’s picture

The where clause, data LIKE %d should look like data LIKE '%%%d%%', you need the quotes because the stored value is a string. The '%%' after passing through db_query becomes a '%', the final query passed to mysql will have WHERE data LIKE '%44%' for the where clause.