prw Posted February 23, 2011 Share Posted February 23, 2011 I'm somewhat new to OOP PHP, and I'm still learning, but basically I want searchcolumns() to set which MySQL columns that it'll search inside but I don't know where to go from what I've already coded. Here's the basic input to be sent to my classes file: $getusers = new database; $getusers->search($_GET['search']); $getusers->searchcolumns('username','account','email'); And to put it simple, I need my $where variable to output this: $where .= "(username LIKE '%$search%' OR account LIKE '%$search%' OR email LIKE '%$search%')"; Except replacing the already set columns with the ones that I assigned in the searchcolumns() array, and then adding an OR string if there's more than 1 column set. Here's the code as I have it at the moment, for obvious reasons, it doesn't work how I want it to: // Search columns function searchcolumns($columns) { $this->column = explode(", ", $columns); } // Search results function search($search) { $search = ($_POST['search']); if (isset($_GET['search']) && strlen($_POST['search']) > 1) { $searchresult = explode(" ", $search); $where = "WHERE"; foreach ($searchresult as $key => $search) { $where .= "($this->column LIKE '%$search%')"; if ($key != (sizeof($searchresult) - 1)) $where .= " AND "; } $this->where = $where; } } Sorry if this has been somewhat confusing to explain, but hopefully someone understands what I'm trying to achieve. Quote Link to comment https://forums.phpfreaks.com/topic/228574-setting-an-array-of-columns-to-search-in/ Share on other sites More sharing options...
trq Posted February 23, 2011 Share Posted February 23, 2011 You would be better of actually passing an array to searchcolumns() and calling it using $getusers->searchcolumns(array('username','account','email')) or using [man]func_get_args[/m] to turn your arguments into an array of args. Quote Link to comment https://forums.phpfreaks.com/topic/228574-setting-an-array-of-columns-to-search-in/#findComment-1178558 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.