Codeigniter 3 Tutorial Part-11: Edit Data | fetch data by id in textbox from database in codeigniter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back so guys in this video we are going to continue our codeigniter series which is about the edit and update data so in previous video as you have seen that how to add the data so after adding that you are fetching those data into this table okay so now in this video we will be clearing with the edit option so when you click on this edit button that time your i it will take this id forward slash as edit forward slash one it will take and then it will go to one form like same as this form and with that id data so with this id number one all its data should be filled in into the input box so guys we will get started with it so let's move to our employee page at this table i mean this form design so i have opened that file guys now done so now as you can see that edit and delete button here which is available over here as you can see this so let's pass the id into it so if you don't know how to fetch this data from your database please watch out the previous video link given into the description so as now as we are viewing this ide over here row id that id only we are going to call so let's first let's uh open php and close php and echo the base url so let's type base url function so this base url function you have to register in your autoload.php so if you don't know please watch out the video of a configuration this okay so now let's continue so as i wanted to create a url called employee forward slash edit forward slash and then the id number so let's copy this as same url and get back and paste it over here so instead of here random generated id will be there okay so that id will fetch from here so that is row of id so let's remove this one and concatenate it so let us give dot and concatenate over here so id number one two three it will be generated right so let us save over here i mean reload the page and you can click on this id one first row i'm just clicking on it so you can see that find id one cool so with the second option two let me click so you can find that id number two so guys now let's create a route for this so let's get back and let's go to our vs code and create a route for it so guys what we have to do we have to go to our config folder inside config folder you can find the routes.php file okay now let's register that over here i mean let's make the route so dollar routier route where inside array function you are going to paste your url so what is that url when you're going to create it where is it our employee so you have given this right so let us copy this and here let's paste it let's send that value and in this you are going to send where i'll send any okay so any means like any number i mean you can accept the alphabet also a number also if you're sure with number then you can use num so right now i will use a and y only and send the data at the controller not single let's push it into single quotes so instead single quote i will pass this controller so i have already done with that controller and let me pass my controller where you will go to employee controller at edit function okay edit method we will create it so let's go to in front-end folder inside that employee controller where we have to create this edit so let's just arrange where is my controller it's over here let's go to front end inside front end employee controller so it's over here so let's just ignore all this part and let's begin with editing so let's create the public function public function of edit okay so whatever we have given into a route so now over here you are going to call the details of it so once you are see as you can see that you are sending something in the route right so if you want to call this you have to pass a variable inside this so let's send that dollar id and inside this id now we will fetch the data inside this function so guys let's load the model for it so dollar this of load hyphen model function okay so inside this model we will get our model so as i have created the model where it is it is over here models so inside that model i have employee model dot php file okay so now we will create a function where to get the details so let's create a function one public function public function where function name will be get not get where we'll fetch okay find employee or you can mention that edit employee so edit employee will be best edit employee function and inside this you all be coding it so before that what we were calling here we will be calling our model name so let us first call that model name and then we will start coding about it so let us call this over here and now we will send the data so over here you can call dollar this of load not load your model name so this model name will be called over here and from here you are going to call the function so edit employee you have just now created that function so let's call this function name over here and inside this you are going to pass the id so what id are going to send so let us send this id dollar id and inside this dollar id function you are going to send this employee model this employee model will go to your employeemodel.php file and inside this it will ask for id so let's send that id and now here you are going to type your database connection thing okay so guys let's uh type this dollar this where database connection db connection of your get method so there are many ways to get the data from your single thing so as by default codeigniters give you some features of a query builder so let's go to database references inside that query builder classes so let's click on that and here you can just see that selecting data looking for similar specific data so let's click on this you can see that where they are telling where function okay so where function will help you to create search all the items right so we have one more function called where get where condition so let me just search that ctrl f get underscore where okay it's here so this is the thing which we are going to use so let us just use this one this is made correctly so whatever things we required we can follow that so let's replace that and now here your table name will be so as you know our table name is employee so let us copy that and paste and these things we don't required now so let's just remove that and inside this array instead of typing like this array will will use with the square array square brackets array and now we have to search the record so id is once you can then print that id in one thing so directly uh codeigniter gives you with the row function so let's stall as dollar query let's paste that hyphen of row function so which means only single row will be returned so let's return that and i will show you one more method things what are all things which we are going to fetch so first let us do the target about edit the data and fetch into the input box so let's get back and once this employee is called and your data will be fetched over here now done so employee data is coming over here and now we have to create this variable as called as data is equal to data or employee so inside this data i'm going to create employee done and now we will return this so let's load the page so we have to create a page called dollar this so we already have done that thing so let us just copy so if you want the design i have already done with this so let's copy that and same thing you're going to paste oops let's paste inside okay so now let's create a edit page for it so this is the create page where we are added and this is the edit page so let's go to our views folder so let me arrange application views inside front end i am going to create a edit page edit dot php now let us check hello i am edit page save this and let's go back to controller where you will fetch that push that data over here so let's push this data dollar data variable you are going to push it over here so why to make mess so let's use this header at the top okay and now inside this you are going to send so let's go over here let's see first the edit page is viewing or what so let's now let's get back on the page reload the page now let's click on edit see let's see what happens click on this okay edit where it's showing one where argument controller so too few arguments edit function okay let's check that what's there let's go to route okay so we didn't pass the what we have to pass the id thing so anything you are passing in the parameters url the time you have to send this okay so make sure you are giving this dollar one okay so this is the method how we declare in codeigniter that's it and let's just check once again so let's refresh it and let me click on it edit one cool i am in hello page so guys now let's uh copy the let's go to edit and here what we want the design so design we have already done in insert form like i will show you the demo over here so this is the form right so i want to get this form only and add it over in edit form over here so let's copy that form so where is it this is the create form let's control ac and ctrl v paste it we don't need this form validation if you required you can do the form validation also so right now we don't need in this so let's remove that or else you can keep it if you're required i'll just paste the form if you have some insert one then you can fetch it so let's change this url this thing you will be needed in next video where we'll be learning about how to update the data okay inside this employee edit page let's save this and as simple we will change this button as update where we will give us info let's go back and reload this page so you can see employee edit page so guys now the main thing of fetching the id1 data over here so let us get back to our controller so you can see that you have fetched the data right so let us insert this data what data you are passing employee so let's copy this employee data and go to edit.php file and now over here in the first name you are going to send value value is equal to where employee not like this you have to is equal to and then this is the shortcut method to display dollar where you are going to fetch give a hyphen arrow first underscore name so because i am giving this because i have created a database where it is first name inside the employee table so let's reload the page you can see that first name is wait as you can see in id number one it is where it's called cool so it's coming fine then same method you can call this for the same last name also so let's paste that as last name and then the phone number so let's copy that and tell phony phone and then final one email and for that email you can call that email also done so once email is done say reload the page you can see that with prakash all five five way that gmail.com data is come over here so let's get back and for om prakash we will just edit this so let's click on it you can find that ohm and its phone number and its email id cool so guys in this video we have completed that how to edit the data from database and fetch that id by it into a text box so now one more method i just wanted to show you like how to show data in another format so that is like once you go in your model over here so you use this as row function okay so one more method is there dollar array oops so dollar a r a y so when you use this row array format so that time you will be fetching your data and not in this format instead you will be fetching the data in this format okay so let's comment this for writing and for time being let's comment this and just check with this only first name so we are declaring this in array format let's save this ctrl r you can see that if you use directly in this format like this you will be getting some error so that incorrect array undefined property of non-object so it is not that correct format so now let us just make it as it was okay so just i wanted to show a demo for you for it to show so let's make this also as row function only let's save it and use the data so guys that's it and now let's continue next video about how to update this data so once you click that updating we will check it so the guys uh here you can see that functions and all so this function will be useful when you update the data so guys let's see the all this details in next video thank you for watching this video please subscribe like and share
Info
Channel: Funda Of Web IT
Views: 11,239
Rating: undefined out of 5
Keywords: fundaofwebit, how to edit data in codeigniter, how to edit and update data into database in codeigniter, how to edit and update in codeigniter, edit and update data in codeigniter, how to fetch data in textbox in codeigniter, how to retrieve data into textbox, how to get data into input box in codeigniter, how to edit data in codeignitor tutorial, updata data into database in codeigniter, how to fetch data by id in codeigniter, how to get url id in codeigniter
Id: OZUUyMtwyXk
Channel Id: undefined
Length: 16min 28sec (988 seconds)
Published: Sat Jan 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.