The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Query - LIKE {3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d} - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Documentation (https://userspice.com/forums/forumdisplay.php?fid=30) +--- Thread: Query - LIKE {3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d} (/showthread.php?tid=1018) |
Query - LIKE {3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d} - MattyO_83 - 03-27-2018 i've just started using UserSpice. Enjoying how well it is structured and learning quickly. Some help with this would be great. How would i query rows where column is 'like' or contains part of a string var? Possibly the equivalent to below $item= = 'car'; ("SELECT * FROM table WHERE column LIKE '{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}$item{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}'"); //Most likely for $item I would be using: $item= $ab->items; //Cannot workout how to use $db->query("SELECT * FROM table WHERE column 'LIKE' ?",array($item)); Thanks for your help! Query - LIKE {3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d} - Brandin - 03-27-2018 Although I don't recall if I've tried this or not, this might work with bounded parameters: Code: $db->query("SELECT * FROM table WHERE column LIKE CONCAT('{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}',?,'{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}'),[$item]); I don't have time to test this right now-if it doesn't work you won't be able to bound the parameter, and that is probably something we should work on a function for. You would need to do: Code: $db->query("SELECT * FROM table WHERE column LIKE CONCAT('{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}',$item,'{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}'); Please let me know. Query - LIKE {3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d} - MattyO_83 - 03-28-2018 thanks Brandin, It works great, by calling the built-in UserSpice function Code: $db->query() I could either concatinate the string var with {3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d} Code: $item = '{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}'.$item.'{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}'; Code: $item = '{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}car{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}'; I removed the single quotes (') from LIKE Code: $db->query("SELECT * FROM table WHERE column LIKE ?",array($item)) Query - LIKE {3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d} - Brandin - 03-28-2018 Great, glad to hear it worked well. |