I am trying to create a search form in Codeigniter. I have created a text box where the user can input the title and author of the book that they want to find. This is my code yet, is my code correct or not?
Controller:
Function Search Buttons () {$ postlist ['bookSearch'] = $ this - & gt; View_book_model- & gt; GetSearchBook ($ this-> Input-> Post ('Search')); $ This- & gt; Load-> View ('searchbooks.php', $ postlist); }
Model:
function getSearchBook ($ searchbook) {$ select_query = "Choose from books * 'where title ='. $ SearchBook. ' "; $ Query = $ this- & gt; Db- & gt; Query ($ select_query); Return $ query- & gt; result (); }
See:
& lt; Input type = "text" class = "search box" id = "search box" & gt; & Lt; / Input & gt; & Lt; Input type = "submit" value = "search" class = "btnInput" id = "btnInput" & gt; & Lt; / Input & gt; & Lt; Br> & Lt; Br> & Lt ;? Php echo '& lt; Hr & gt; '; Echo & lt; H3 & gt; Book list & lt; / H3 & gt; '; Echo '& lt; Table id = "maintainable" class = "table" & gt; '; Echo & lt; Th & gt; Book id & lt; / Th & gt; '; Echo & lt; Th & gt; Book Title & lt; / Th & gt; '; Echo & lt; Th & gt; Book writer & lt; / Th & gt; '; Echo & lt; Th & gt; # Copies & lt; / Th & gt; '; Echo & lt; Th & gt; Available copy & lt; / Th & gt; '; Forex Currency ($ Book Search as Row) {echo '& lt; Tr & gt; & Lt; TD & gt; '. $ Rows- & gt; BookID. ' & Lt; / TD & gt; & Lt; TD & gt; '. $ Rows- & gt; Title.' & Lt; / TD & gt; & Lt; TD & gt; '. $ Rows->. Author '& lt; / TD & gt; & Lt; TD & gt; '. $ Rows- & gt; Quantity. ' & Lt; / TD & gt; & Lt; TD & gt; '. $ Rows- & gt; Onhand. ' & Lt; / TD & gt; & Lt; / TR & gt; '; } Echo '& lt; / Table & gt; '; ? & Gt;
I use AJAX to retrieve the input entered by the user in the search box. The problem is that I do not know how to codify my model in the context of the book title and author's search for a user searched for.
If you can use Query Builder, then it will be better:
function getSearchBook ($ searchbook) {if (empty ($ searchbook)) returns array (); $ Result = $ it- & gt; Db- & gt; Like ('title', $ searchbook) - & gt; Or_like ('author', $ searchbook) - & gt; Receive ('books'); Return result $ & gt; result (); }
No comments:
Post a Comment