Php search mysql database -


Sorry if I'm already asking answered questions, but I was not able to find my specific set-up.

I have a php file called functions.php, where I store all my tasks and A small example would be as follows:

  function getUsers () {global $ mysqli, $ db_table_prefix; $ Stmt = $ mysqli- & gt; Prepare ("SELECT id, user_name, db_users"); $ Stmt- & gt; Executed (); $ Stmt- & gt; Bind_salt ($ id, $ user); While ($ stmt-> fetch ()) {$ row [] = array ('id' => gt; $ id, 'user_name' = & gt; $ user); } $ Stmt- & gt; Close (); Return ($ line); }  

I want to create a search function with which I can search with option value, such as: id , user_name .

By function. Php I'm already setting up a connection to mysql database, how can I find a database with a search from my '% searchrequest%' ? Php?

Or do you suggest another solution?

Just pass these search values ​​in your current function if nothing is given, then all this Will get the data. If any value has been passed, then it will be filtered based on it.

  function getUsers ($ id = "", $ user_name = "") {global $ mysqli, $ db_table_prefix; $ Query = "SELECT id, user_name, db_users from WHERE 1 = 1"; If (trim ($ id) $ query = "And id = '". $ Id "'"; If (trim ($ user_name)) $ query = "And user_name = '". $ User_name "'"; $ Stmt = $ mysqli- & gt; Ready ($ query); $ Stmt- & gt; Executed (); $ Stmt- & gt; Bind_salt ($ id, $ user); While ($ stmt-> fetch ()) {$ row [] = array ('id' => gt; $ id, 'user_name' = & gt; $ user); } $ Stmt- & gt; Close (); Return ($ line); }  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -