Get data from database using AJAX, Javascript, PHP, MySQL

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • Get data from database using AJAX, Javascript, PHP, MySQL
    Source files:
    adnan-tech.com...

КОМЕНТАРІ • 161

  • @amitgahatraj4
    @amitgahatraj4 2 роки тому +5

    This is by far on of the best tutorial I've ever seen. Short but includes each and every possible information.
    Thanks a lot.

  • @arminharper510
    @arminharper510 4 роки тому +3

    finally a tut on AJAX+mysql+vanilla JS.
    everyone is teaching this using jQuery, but i don't need to use the entire library just for it's AJAX methods.
    i'm trying to build a live chat app and am going to try it using the info here. THANK YOU.

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому

      You're welcome. Good luck with your live chat app. I have already created a tutorial for live chat app, below is the link:
      ua-cam.com/video/Ozrm_xftcjQ/v-deo.html

  • @JESR-og2xc
    @JESR-og2xc 3 роки тому +1

    After hours of searching and nearly giving up, you showed me how it to do it. Thanks a lot, this video was very helpful.

  • @zichunzhang6121
    @zichunzhang6121 4 роки тому +1

    Dude, i have no idea what to say. It's just like magic. I am now a fan of ajax now. what a beautiful way to interact with the database! Ty so much!

  • @seilasan4894
    @seilasan4894 3 роки тому +1

    you are saving me now. thank you from Phnom Penh Cambodia. :)

  • @MovieHeretic
    @MovieHeretic 3 роки тому +2

    Absolutely brilliant, been looking for an ajax tutorial that handles arrays and finally someone goes a step beyond the normal simple data examples. New subscriber bro.

  • @raphaelsefakoradinkrah6533
    @raphaelsefakoradinkrah6533 4 роки тому +4

    This tutorial actually saved my Ass, thank you Adnan Afzal

  • @jumpman23nith
    @jumpman23nith 2 роки тому

    This is the best AJAX tutorial by far. Thank you for this.

  • @alexgraham1199
    @alexgraham1199 5 років тому +2

    Thanks so much for this. I needed a really simple and pragmatic approach to get data and this simple solution came at the end of 5 hours of faffing.

  • @robinr2336
    @robinr2336 5 років тому +4

    👍
    This was good! But for a noob to PHP, audio explanations would have made this perfect. Even though a book is silent, one can still read code explanations and details.

    • @AdnanAfzal565
      @AdnanAfzal565  5 років тому +1

      Yes, audio will be added soon.

    • @relife476
      @relife476 4 роки тому +1

      @@AdnanAfzal565 Please, and thanks you.

  • @eliasbinde2629
    @eliasbinde2629 4 роки тому +1

    Thank you! Straight to the point and easy to follow.

  • @timow6929
    @timow6929 5 років тому +1

    THANK YOU! The only easy to understand and to use tutorial out in this trash internet

  • @shontzu
    @shontzu 3 роки тому

    This is so understandable. Had to send this to my peers...! thank you

  • @ryuta4754
    @ryuta4754 4 роки тому +1

    That's it I've been looking for !!
    Thank you !!

  • @jesusromero2046
    @jesusromero2046 4 роки тому

    Thanks dude, not exactly what I was looking for but shed a enough light to resolve my problem...btw after a lot of hours surffing on Internet

  • @pankajclasses9569
    @pankajclasses9569 4 роки тому +1

    Excellent.....Made my life easier

  • @DineshNairMumbai
    @DineshNairMumbai 5 років тому +1

    wonderful and different from the way we normally do.

  • @joydeepbhattacharjee5305
    @joydeepbhattacharjee5305 4 роки тому +1

    awesome tutorial thank u sir

  • @mdnasimralitsoft9488
    @mdnasimralitsoft9488 4 роки тому

    Very nice activity .....

  • @rehmansarwar8392
    @rehmansarwar8392 4 роки тому +1

    great Effort and magnificent method.

  • @yannik8271
    @yannik8271 2 роки тому

    Bro this was so helpful. Thank you man!

  • @wrzq
    @wrzq 5 років тому +4

    Brilliant, thank you Adnan for this tutorial.

  • @ralitsoft8204
    @ralitsoft8204 4 роки тому +1

    Great Video Get helpful

  • @oantoniolima
    @oantoniolima 3 роки тому

    Hello there, can you help me? I want to use that "data" array in an if to check is a certain column is set to 0 or to 1, i defined var data = {} outside of the function but It's not working, I'm doing an if (data["article_flag(the column)"] == 1) { function to execute }

    • @AdnanAfzal565
      @AdnanAfzal565  3 роки тому

      In javascript, you need to use data.article_flag, dot.

  • @arminaebrahimsulaiman738
    @arminaebrahimsulaiman738 4 роки тому

    Excellent!!!

  • @rajeshmaurya681
    @rajeshmaurya681 6 років тому +1

    Thank you so much really helpful superb....

  • @christofermunoz5564
    @christofermunoz5564 4 роки тому

    I had to change mysqli_fetch_assoc to mysqli_fetch_array in the .php file and it worked, thx

  • @rijovg
    @rijovg 6 років тому

    how is the where condition using passing parameter ?

  • @RadiantX917
    @RadiantX917 2 роки тому

    If you modify the table in background does it reflect the change without loading of page ?

    • @AdnanAfzal565
      @AdnanAfzal565  2 роки тому

      No, for realtime update, you need to check our Socket IO tutorial:
      ua-cam.com/video/56_k1botx9M/v-deo.html

  • @manojjangir1154
    @manojjangir1154 5 років тому +1

    nice explanation

  • @imtiyazahmad617
    @imtiyazahmad617 6 років тому +2

    thank you so much really helpful superb only sound is required

    • @AdnanAfzal565
      @AdnanAfzal565  6 років тому

      Thank you. Yes, sound will be added in future tutorials.

  • @neetpg9035
    @neetpg9035 4 роки тому +1

    You are awesome bro, thank you so much

  • @DevangBhattDev
    @DevangBhattDev 4 роки тому

    How to get any specific lines of data ?
    If I want to display data for only 1 Employee ??

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому

      You can add a WHERE clause in the query, for example:
      SELECT * FROM users WHERE id = 3;

  • @FranklinmsZa
    @FranklinmsZa 5 років тому

    Well done, Thank you for this video

  • @judanetwork
    @judanetwork 6 років тому +1

    hi nice video, so the code to read the employees table is
    $result = mysql_query($conn, "SELECT * FROM employees");
    right?

  • @georgemendle5587
    @georgemendle5587 4 роки тому

    Intro kamal

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому +1

      Thanks.
      Let me know if you want to have one with your name and logo.

  • @leecravens1184
    @leecravens1184 4 роки тому

    This is a new language for me, as I have been writing in pure PHP for years. I was able to follow this video and retrieve all rows from my db where a column had a specific value. The problem is, that when I add a new row in the db that has the same value at from my WHERE clause, the new row never shows up. I still have to force a refresh (F5). This is the same scenerio in multiple web browsers, so I'm thinking it is in the code (probably my fault, I am sure!)
    Any thoughts on why this would not show the new rows? The table I am querying will be INSERT only, no UPDATE or DELETE, to maintain data integrity. I just edited one of the rows directly from the database (not yet live, it is in the testing phase) to see if the changes would show on existing rows that are being displayed on my test page, and they don't show updates either! What am I missing?!?

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому

      You need to insert the record using AJAX. You can follow this:
      ua-cam.com/video/UDmAlpYVwbU/v-deo.html
      When the response is received from this AJAX, you can send ajax the AJAX to get all records.

  • @Gustablealves
    @Gustablealves 6 років тому +1

    Nice tutorial

  • @vishnus2567
    @vishnus2567 4 роки тому

    I added a Button. So that the result is displayed only after pressing the button. But the problem is that the result are displayed multiple times on button press. How to clear this?

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому

      Check if the function is being called multiple times.

  • @HongKong1842
    @HongKong1842 3 роки тому

    what is the benefit of bringing in Json, while the record row can actually be printed directly?

    • @AdnanAfzal565
      @AdnanAfzal565  3 роки тому +1

      If you directly print the data using PHP, then it will increase your page load time. Also, if there is any error in PHP, then it will crash your page.

    • @HongKong1842
      @HongKong1842 3 роки тому

      @@AdnanAfzal565 Thank you. I know only php mysql. If I add this feature, in average how much time it saves for a general page with perhaps 20 fields to be printed?

    • @AdnanAfzal565
      @AdnanAfzal565  3 роки тому +1

      It depends on server. May be 1-2 seconds.

    • @HongKong1842
      @HongKong1842 3 роки тому

      @@AdnanAfzal565 how come php echo will crash more easily?

    • @AdnanAfzal565
      @AdnanAfzal565  3 роки тому +1

      Simple code will work fine. But if you have a very complex sql query, are performing certain operations on arrays and objects. Or using 3rd party library, then it is a possibility.

  • @ReubenMRU
    @ReubenMRU 4 роки тому

    Hello, Thanks a lot for this...
    Doing just that i seem to be limited to retrieving only 150 rows... if i try to retrieve more, i get an empty string instead...
    I'm on Xampp/mariaDB - I tried to set the post_max_size to 0 in the php.ini file, to no avail... even restarted the server afterwards... still limited... any thoughts?

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому +1

      Check if there is any limit in query. Or in loop.

    • @ReubenMRU
      @ReubenMRU 4 роки тому

      @@AdnanAfzal565 Thanks for getting back to me so quickly - turns out it was accents.. the 151st row had an accent and because of that the query returned an empty set... been trying to fix this but none of the solutions i found online are helping so far :/

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому +1

      @@ReubenMRU Try following before running the query:
      mysqli_set_charset($connection, "utf8");

    • @ReubenMRU
      @ReubenMRU 4 роки тому

      @@AdnanAfzal565 thanks, still doesn't work unfortunately :/
      Getting this:
      SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
      Also converted my DB, Table and column to utf8mb4 - to try and fix this... doesn't seem to work at all

    • @ReubenMRU
      @ReubenMRU 4 роки тому +1

      @@AdnanAfzal565 Thanks I got it to work - not sure what exactly did it though, lol...

  • @mygrof
    @mygrof Рік тому

    In my case it stores html into json, is it bcs I am using Smarty?

    • @AdnanAfzal565
      @AdnanAfzal565  Рік тому

      Yes. Smarty template might be doing the conversion.

  • @hannesmann1000
    @hannesmann1000 5 років тому +1

    Good video I subscribred!

  • @beticohernandez8039
    @beticohernandez8039 6 років тому +1

    Hello, if the file of the array I have it in a hostin I would read the data tabien, that list can show it in list like jquery mobile?
    Thank you.

    • @AdnanAfzal565
      @AdnanAfzal565  6 років тому

      Yes, you need to call AJAX in order to do that.

  • @shivamgarg8398
    @shivamgarg8398 3 роки тому +1

    love you mannn

  • @futuretechx5754
    @futuretechx5754 5 років тому +1

    Searching for days, and found this. Absolutely amazing. Best is so many other sites don't have code download, thanks for that. The mysqlsampledatabase.sql to create the database couldn't be better. Thank you so much for this, from a beginner who has learnt so much from you.

  • @josellecallora08
    @josellecallora08 Рік тому

    Thanks for this!! Beeen searching for pure js live data.. anyway, is it possible for me to put a button at the end of the table? hope you could recommend me a video that includes an action at the end of the table where the user could delete or edit the column.. thank you!

    • @AdnanAfzal565
      @AdnanAfzal565  Рік тому +1

      Sure. You can follow this:
      ua-cam.com/video/qYbkQpSI9_o/v-deo.html

    • @josellecallora08
      @josellecallora08 Рік тому

      @@AdnanAfzal565 wow, you are active until now. thank you! btw, i liked and subscribed.

    • @AdnanAfzal565
      @AdnanAfzal565  Рік тому

      Thank you.

  • @adrianoldchannel2494
    @adrianoldchannel2494 6 років тому +1

    Lovely video. Click

  • @beticohernandez8039
    @beticohernandez8039 6 років тому +1

    With the tuturial code you can do that

  • @snjvthakur24
    @snjvthakur24 4 роки тому

    can i use it for fetch data from wordpress database and use data in javascript

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому

      Not using this tutorial. But you can follow this:
      premium.wpmudev.org/blog/using-ajax-with-wordpress/

  • @kuodong
    @kuodong 5 років тому

    Hi, may I ask why convert array into JSON AND again convert JSON back to array. ??

    • @AdnanAfzal565
      @AdnanAfzal565  5 років тому

      Hi.
      Because if you have a lot of data then it would be difficult to send as PHP objects. So we send them as JSON string. Now data will be sent as string not objects.

  • @Cheffak
    @Cheffak 6 років тому +3

    Is that a Python programmer in your intro? :O

  • @markystudio14
    @markystudio14 3 роки тому

    Thank you dude 😊 but I have a problem why my data is duplicated ? 1 user
    1 user
    2 user2
    2 user2
    Where is my problem ?

    • @markystudio14
      @markystudio14 3 роки тому

      I figured out that the problem is In array_push statement.
      Array_push($data, $row);
      I tried to delete the $row var in array_push statement and the result is not duplicated. Inshort the problem is finally solved. But still I don't know the conflict after I removed this.
      But I still wonder why my data is duplicated output, while in your case is not?
      I didn't understand yet what is the main purpose of array_push.

    • @AdnanAfzal565
      @AdnanAfzal565  3 роки тому

      @@markystudio14 array_push insert the data in array. Check if you are receiving duplicate data from database. May be the problem is not in PHP code, but in MySQL query.

  • @shahmasumzaman4647
    @shahmasumzaman4647 6 років тому +1

    Thanks U Helped me

  • @simaopacheco4529
    @simaopacheco4529 4 роки тому

    is this save to use? since javascript is a cliente side? which can be "easily" manipulated by client?

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому

      Yes, all the database credentials are at server side. So no worries.

    • @simaopacheco4529
      @simaopacheco4529 4 роки тому

      @@AdnanAfzal565 ok, thnx for the tutorial, consider talking when writting it helps us to understand the code better instead of just copying from you

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому +1

      @@simaopacheco4529 Okay, thank you. Next time I will keep that in mind.

  • @albertolizarraga98
    @albertolizarraga98 4 роки тому +1

    Thanks!

  • @林宜賢-k7w
    @林宜賢-k7w 4 роки тому

    thank you for your video!

  • @desirocker9099
    @desirocker9099 5 років тому

    Can you please make a video for fetching only when there is new data using long polling method, because as I have heard, this method would put a strain on the server.

    • @AdnanAfzal565
      @AdnanAfzal565  5 років тому +1

      Yes, it requires Socket IO, I will do that tutorial and will let you know.

    • @desirocker9099
      @desirocker9099 5 років тому

      @@AdnanAfzal565 Can we implement socket.io with php and apache back end?

    • @AdnanAfzal565
      @AdnanAfzal565  5 років тому

      @@desirocker9099 Yes, you can use Ratchet PHP API for sockets.

  • @protip2950
    @protip2950 4 роки тому

    The best

  • @chapulinazulado7717
    @chapulinazulado7717 4 роки тому

    porque nao usou o
    setInterval(function(){ajax();}, 1000);
    ?

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому

      It will send the request to server every second. You can use Node JS to get realtime data.
      ua-cam.com/video/sMPayYZFodE/v-deo.html

  • @hasagine3479
    @hasagine3479 5 років тому +2

    thanks bro

  • @jasonking1284
    @jasonking1284 5 років тому

    Hmmm..... That could be achieved in pure PHP in a couple of lines.... I suppose if you have an adfested page where you want to only update the 3 square inches of actual information of value without loading all the ads again, JavaScript is useful.
    Still.. at least a video showing Ajax WITHOUT using JQuery. Good.

  • @anshitamakode6097
    @anshitamakode6097 4 роки тому

    Not worked...actually it is not showing array in console

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому

      It means there is an error on server side. Double check the variables and make sure database connection is right.

  • @renecabuhan1675
    @renecabuhan1675 2 роки тому

    Thanks 😊

  • @gyurmesherpa3965
    @gyurmesherpa3965 6 років тому +1

    Wow...

  • @martins.8349
    @martins.8349 3 роки тому

    idk i had same code and it just returned myentire html page

  • @DineshNairMumbai
    @DineshNairMumbai 5 років тому

    pls send a link if available where we can write into a table using a similar ajax script

    • @AdnanAfzal565
      @AdnanAfzal565  5 років тому

      This is already displaying in format.

    • @DineshNairMumbai
      @DineshNairMumbai 5 років тому

      @@AdnanAfzal565 Sorry... not format but database=> table

    • @AdnanAfzal565
      @AdnanAfzal565  5 років тому

      @@DineshNairMumbai Okay. That will be just designing thing.

  • @kisme01
    @kisme01 5 років тому +1

    very hard to find. thank you

  • @Rahulsharma-el6fs
    @Rahulsharma-el6fs 2 роки тому

    Thanks

  • @CJ_YT
    @CJ_YT 3 роки тому

    Is it refeshing data without refeshing website?

    • @AdnanAfzal565
      @AdnanAfzal565  3 роки тому

      Yes.

    • @CJ_YT
      @CJ_YT 3 роки тому

      @@AdnanAfzal565 I have to use timer or something like this to refresh data on website ? When I am changing data in database now, website displays the same data like before (are unchanged). When I refresh website only by F5 - data is changing. What's wrong with me ?

    • @AdnanAfzal565
      @AdnanAfzal565  3 роки тому

      You can follow this:
      ua-cam.com/video/sMPayYZFodE/v-deo.html

  • @riteshpandey694
    @riteshpandey694 4 роки тому +1

    liked for Welcome scene

  • @arupduttabappy3284
    @arupduttabappy3284 4 роки тому

    👍💜

  • @samirpatel7141
    @samirpatel7141 5 років тому

    Can i get the source code of this please

    • @AdnanAfzal565
      @AdnanAfzal565  5 років тому

      Yes, will upload and send you link soon.

    • @AdnanAfzal565
      @AdnanAfzal565  4 роки тому +1

      Sorry for very late reply, but here is the source code:
      adnan-tech.com/tutorial/get-data-from-database-using-ajax-javascript-php-mysql

  • @danzzeidan4412
    @danzzeidan4412 Рік тому

    next time please link your file :(
    but thanks anyways

    • @AdnanAfzal565
      @AdnanAfzal565  Рік тому

      You are welcome. The link to files is already mentioned in the description of this video.

  • @armuc6941
    @armuc6941 4 роки тому

    Bizarre !!