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

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

Комментарии • 161

  • @arminharper510
    @arminharper510 5 лет назад +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  5 лет назад

      You're welcome. Good luck with your live chat app. I have already created a tutorial for live chat app, below is the link:
      ruclips.net/video/Ozrm_xftcjQ/видео.html

  • @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.

  • @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. :)

  • @raphaelsefakoradinkrah6533
    @raphaelsefakoradinkrah6533 4 года назад +4

    This tutorial actually saved my Ass, thank you Adnan Afzal

  • @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.

  • @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.

  • @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.

    • @AdnanAfzal565
      @AdnanAfzal565  3 года назад

      Thank you very much. Glad it helped.

  • @jumpman23nith
    @jumpman23nith 3 года назад

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

  • @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

  • @DineshNairMumbai
    @DineshNairMumbai 5 лет назад +1

    wonderful and different from the way we normally do.

  • @joydeepbhattacharjee5305
    @joydeepbhattacharjee5305 4 года назад +1

    awesome tutorial thank u sir

  • @pankajclasses9569
    @pankajclasses9569 5 лет назад +1

    Excellent.....Made my life easier

  • @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

  • @ralitsoft8204
    @ralitsoft8204 4 года назад +1

    Great Video Get helpful

  • @rehmansarwar8392
    @rehmansarwar8392 5 лет назад +1

    great Effort and magnificent method.

  • @christofermunoz5564
    @christofermunoz5564 4 года назад

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

  • @mdnasimralitsoft9488
    @mdnasimralitsoft9488 4 года назад

    Very nice activity .....

  • @wrzq
    @wrzq 5 лет назад +4

    Brilliant, thank you Adnan for this tutorial.

  • @FunKidsTv94
    @FunKidsTv94 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.

  • @manojjangir1154
    @manojjangir1154 5 лет назад +1

    nice explanation

  • @yannik8271
    @yannik8271 2 года назад

    Bro this was so helpful. Thank you man!

  • @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.

  • @chimpionboy
    @chimpionboy 6 лет назад +1

    Lovely video. Click

  • @neetpg9035
    @neetpg9035 4 года назад +1

    You are awesome bro, thank you so much

  • @georgemendle5587
    @georgemendle5587 4 года назад

    Intro kamal

    • @AdnanAfzal565
      @AdnanAfzal565  4 года назад +1

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

  • @arminaebrahimsulaiman738
    @arminaebrahimsulaiman738 4 года назад

    Excellent!!!

  • @vishnus2567
    @vishnus2567 5 лет назад

    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  5 лет назад

      Check if the function is being called multiple times.

  • @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.

  • @rajeshmaurya681
    @rajeshmaurya681 6 лет назад +1

    Thank you so much really helpful superb....

  • @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:
      ruclips.net/video/UDmAlpYVwbU/видео.html
      When the response is received from this AJAX, you can send ajax the AJAX to get all records.

  • @rijovg
    @rijovg 6 лет назад

    how is the where condition using passing parameter ?

  • @judanetwork
    @judanetwork 6 лет назад +1

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

  • @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:
      ruclips.net/video/56_k1botx9M/видео.html

  • @Gustablealves
    @Gustablealves 6 лет назад +1

    Nice tutorial

  • @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.

  • @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.

  • @FranklinmsZa
    @FranklinmsZa 5 лет назад

    Well done, Thank you for this video

  • @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;

  • @beticohernandez8039
    @beticohernandez8039 6 лет назад +1

    With the tuturial code you can do that

  • @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.

  • @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...

  • @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.

  • @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.

  • @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.

  • @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:
      ruclips.net/video/qYbkQpSI9_o/видео.html

    • @josellecallora08
      @josellecallora08 Год назад

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

    • @AdnanAfzal565
      @AdnanAfzal565  Год назад

      Thank you.

  • @shivamgarg8398
    @shivamgarg8398 3 года назад +1

    love you mannn

  • @shahmasumzaman4647
    @shahmasumzaman4647 6 лет назад +1

    Thanks U Helped me

  • @gyurmesherpa3965
    @gyurmesherpa3965 6 лет назад +1

    Wow...

  • @kisme01
    @kisme01 5 лет назад +1

    very hard to find. thank you

  • @riteshpandey694
    @riteshpandey694 4 года назад +1

    liked for Welcome scene

  • @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.

  • @hasagine3479
    @hasagine3479 5 лет назад +2

    thanks bro

  • @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/

  • @desirocker9099
    @desirocker9099 6 лет назад

    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  6 лет назад +1

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

    • @desirocker9099
      @desirocker9099 6 лет назад

      @@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.

  • @林宜賢-k7w
    @林宜賢-k7w 4 года назад

    thank you for your video!

  • @protip2950
    @protip2950 4 года назад

    The best

  • @albertolizarraga98
    @albertolizarraga98 4 года назад +1

    Thanks!

  • @renecabuhan1675
    @renecabuhan1675 3 года назад

    Thanks 😊

  • @hannesmann1000
    @hannesmann1000 5 лет назад +1

    Good video I subscribred!

  • @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.

  • @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.

  • @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.
      ruclips.net/video/sMPayYZFodE/видео.html

  • @martins.8349
    @martins.8349 3 года назад

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

  • @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:
      ruclips.net/video/sMPayYZFodE/видео.html

  • @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.

  • @arupduttabappy3284
    @arupduttabappy3284 4 года назад

    👍💜

  • @armuc6941
    @armuc6941 4 года назад

    Bizarre !!