3: Get data from a database without refreshing the browser using AJAX - Learn AJAX programming

  Рет қаралды 597,425

Dani Krossing

Dani Krossing

Күн бұрын

Пікірлер: 486
@willmurphy7656
@willmurphy7656 7 жыл бұрын
Hi mmtuts, is there a way to replace the existing comments with the new comments instead of loading new comments (or in my case an image) onto the existing ones? This would help me immensely on the website I'm creating. Thanks for the tutorials!
@Dani_Krossing
@Dani_Krossing 7 жыл бұрын
Here is how :) In the AJAX code, add a second variable under "$commentNewCount", which has the current starting row nr from your database. So the variable will look like this, "$commentCurrentCount = 0;" because we load comment row 1 and 2 when we load the page. Then we also need to add 2 to our new variable, as we did to the $commentNewCount, and we do that the same place inside the click() function. Then afterwards you need to add the new variable in the AJAX "load()" function, together with the other data we passed to the PHP script, to make sure we can use it in load-comments.php. In the PHP script that runs after the AJAX call, change your LIMIT parameter in the SQL statement so it looks as follows. $sql = "SELECT * FROM comments LIMIT $commentCurrentCount, $commentNewCount;"; What happens in the new SQL statement, is that by adding another number to our LIMIT, we tell it not only where to end, but also which row the query should start at. Now it should work! Extra note: If you want to change the number of results that pop up when you load more comments, for example from 2 to 8, make sure you change the number both places inside your click() function when you add to your variables.
@marcusriemschneider
@marcusriemschneider 6 жыл бұрын
How can I refresh the comments automatic?
@chukwubuikemchukwudi9900
@chukwubuikemchukwudi9900 6 жыл бұрын
Will Murphy Hi. Thanks for the tutorial. I am display 1 result at a time but its not removing the first result when I click show more comments.
@paulszewczyk1662
@paulszewczyk1662 5 жыл бұрын
Its all in the Select * from table order by date "acceding or descending" Something like this. Just use the same Select statement each time.
@amanmittal9595
@amanmittal9595 5 жыл бұрын
@@Dani_Krossing can you please make a video on this
@TheGrandmaster1
@TheGrandmaster1 4 жыл бұрын
This dude is like an entire Udemy by himself. He deserves 9 Million Subs.
@Kodeispoetry
@Kodeispoetry 4 жыл бұрын
True. when we start earning we must pay him back.
@TheGrandmaster1
@TheGrandmaster1 4 жыл бұрын
@@Kodeispoetry If I ever get out of my rut, every have a nice car again, a decent job, my own place (I used to have these things but went through a very very very bad time and lost everything) then I shall donate generously to his patreon or whatever his platform of choice is.
@Kodeispoetry
@Kodeispoetry 4 жыл бұрын
@@TheGrandmaster1 Indeed sir may you get back to prosperity.
@definitely138T
@definitely138T 3 жыл бұрын
@@Kodeispoetry Agreed!
@nirankarnathsingh7161
@nirankarnathsingh7161 Жыл бұрын
You started earning ?? @@Kodeispoetry
@DaedalusDM
@DaedalusDM 10 ай бұрын
Excellent video with a very patient explanation that doesn't make the common programming "teaching" error of assuming that the viewer has so much background knowledge that the lesson has no actual value to them.
@vandamieespadero6633
@vandamieespadero6633 4 жыл бұрын
You can shows all data from database by one click of a button instead of pressing it for many times, and replacing show more comment button into less comment button after showing all data. Thanks for this video man, it helps.
@connorbeales1554
@connorbeales1554 4 жыл бұрын
For anyone looking for the SQL query code: 'insert into comments (author, message) value ('Daniel', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet non orci sit amet rutrum. Vivamus tristique iaculis justo. Curabitur arcu tortor.'); insert into comments (author, message) value ('John', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet non orci sit amet rutrum. Vivamus tristique iaculis justo. Curabitur arcu tortor.'); insert into comments (author, message) value ('Daniel', 'Justi curabitur arcu tortor.'); insert into comments (author, message) value ('Jane', 'Vivamus tristique iaculis justo. Curabitur arcu tortor.'); insert into comments (author, message) value ('Connor', 'Consectetur adipiscing elit. Praesent aliquet non orci sit amet rutrum. Vivamus tristique iaculis justo. Curabitur arcu tortor.'); insert into comments (author, message) value ('Joe', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet non orci sit amet rutrum. Vivamus tristique iaculis justo. Curabitur arcu tortor.');'
@turboromy
@turboromy 7 жыл бұрын
Not sure if I watched this before. Ajax seemed not as important or difficult as php, sql, javascript, etc. But then, I found myself not progressing with Ajax for lack of good materials. Good thing that I found you AGAIN. Thank you Daniel.
@matheussd93
@matheussd93 6 жыл бұрын
Simply perfect. I've always hated js and now it seems easier to understand.
@how-to.224
@how-to.224 Жыл бұрын
still very relevant in 2023
@janvierz1465
@janvierz1465 5 жыл бұрын
There's still a way to replace $result = mysql_query with $result= $con->query($sql); I had trouble retrieving data from phpMyadmin by working with the first part but I knew how to do with the second one already! Thanks @mmtus for this tutorial. Very helpful. I've been looking for this way too long
@alirezakhaksar9964
@alirezakhaksar9964 3 жыл бұрын
The best KZbin channel Thank you In Persian بهترین پیچ یوتیوب خیلی ممنون
@kjragg1099
@kjragg1099 3 жыл бұрын
Thank you Dan you're an actual life saver, this is exactly what I needed. Being able to pass variables into the AJAX function is so helpful
@DanyV1
@DanyV1 5 жыл бұрын
I don't even need to learn this right now and I loved the tutorial! Will for sure come back later when I need it! :D Keep it up
@nhloniphoxaba6763
@nhloniphoxaba6763 Жыл бұрын
Thank you so much for all the tutorials you've put out !!
@jaringantani5656
@jaringantani5656 4 жыл бұрын
Clear Clean Screen.. excellent..
@basseyotudor
@basseyotudor 4 жыл бұрын
I don't usually comment or like youtube videos but mmtuts is in my opinion the best channel to learn from. I used to face difficulties in web dev but after following his tutorials. I learn so so much and I now ace every exam in PHP and JavaScript. Please would you mind teaching Laravel?
@HARUN-AKSU
@HARUN-AKSU 3 жыл бұрын
The video was very helpful to me. I understood everything even thought I don't speak or understand english very well. Thank you so much.
@RobotsAndMagicPowers
@RobotsAndMagicPowers 5 жыл бұрын
Very cool video easy to understand and replicate!
@jitendraasole5827
@jitendraasole5827 4 жыл бұрын
Great tutorial. Thanks for the information
@ashikurrahmanshad4525
@ashikurrahmanshad4525 6 жыл бұрын
Thanks elder brother. I am highly benifitted from this video. For the first time I successfully use the ajax to load mysql table. Keep it up. Best of luck from my side. Sorry for my poor English condition.
@dr.umeshdutta5868
@dr.umeshdutta5868 3 жыл бұрын
Amazing work! 18 min 48 sec and you get to know so much! Connecting everything together is tricky and Dani explained it so nicely. Respect!
@johnderrickelajot6352
@johnderrickelajot6352 2 жыл бұрын
where can i download the code for mysql in 4:13? reply asap, thanks
@mvaldesme
@mvaldesme 7 жыл бұрын
pure gold man, keep doing these kind of tutorials!
@muhammadsumair1086
@muhammadsumair1086 5 жыл бұрын
Bashaho tusi great o. Fantastic bro
@goldorackconceptionwebmark4319
@goldorackconceptionwebmark4319 4 жыл бұрын
thank alot !!!! its well explained. i like the way you explain every move, been on this for days until iv found youre video ! great work !
@batumanav
@batumanav Жыл бұрын
You could’ve used limit and offset to load 2 more comments each time instead of gradually increasing the limit and loading all the comments again and again. Great tutorial for creating a perspective for a ajax beginner tho. Thanks!
@SeniorGif30001
@SeniorGif30001 4 жыл бұрын
THANKS THIS TUTORIAL SAVED ME
@douglasduran9251
@douglasduran9251 4 жыл бұрын
Daniels thanks for this video you are an amazing teacher
@johntsimgr
@johntsimgr 2 жыл бұрын
Great Video, really helpful. Thanks!
@neil5137
@neil5137 7 жыл бұрын
you're so professional even your "mistakes" seem professional to teach us something
@KingOfTheRedSkulls
@KingOfTheRedSkulls 6 жыл бұрын
You should do this again with PDO. Thanks
@swayamabhiram
@swayamabhiram 4 жыл бұрын
your coding standard helps me a lot. thank u?
@isharaperera419
@isharaperera419 4 жыл бұрын
You are a genius teacher! Thank you very much!
@benjosolanor
@benjosolanor 2 жыл бұрын
Hi! thanks for the helpful video, but where is the stylesheet you talked about in the description?
@letsgocamping88
@letsgocamping88 4 жыл бұрын
Top notch explanation.
@myfreedata
@myfreedata 6 ай бұрын
Bro, I think PHP is still the best backend for web 2024-2025
@jihanearfi3795
@jihanearfi3795 3 жыл бұрын
Sehr gute Videos und gute Erklärung
@zainrana9117
@zainrana9117 5 жыл бұрын
Mannnnn... I was so annoyed every time I tried to follow a video it didn't work at the end. Its my first website and I was so pissed coz I dont't like JS but you made things look so simple 😍 and easy to understand.. Thanks a lot bro 🙌🙏 u just made my day 😊
@DarrenC_1024
@DarrenC_1024 3 жыл бұрын
simple and clear, thanks a lot!
@micheljosephhoude1319
@micheljosephhoude1319 3 жыл бұрын
Thank, very clear explanations
@roj1512
@roj1512 5 жыл бұрын
Thank you from the KRG.
@web3361
@web3361 Жыл бұрын
thanks for your useful and helpful video
@raizudu5813
@raizudu5813 Жыл бұрын
Hey dani I love your tutorial. That's why learned the php from you. I hope you notice me. I hope you next tutorial will be creating a crud usin REST api using vanilla javascript.
@richardwilkins5241
@richardwilkins5241 2 жыл бұрын
Just Brilliant! You put so much effort into clarifying everything and it has helped me enormously. Thank you.
@tyscyre2256
@tyscyre2256 2 жыл бұрын
I get how to do so but what about a situation where I want to get the data from the database after every second or 2 and update the page . Won’t there be a lot of requests in my network tab? And if so will there be any side effects from that?
@tyscyre2256
@tyscyre2256 2 жыл бұрын
I mean can there be a way to specify to the ajax call to refetch the data after an amount of time?
@ErodonTV
@ErodonTV 2 жыл бұрын
good stuff, great work
@TechnicalHamzaOfficial1
@TechnicalHamzaOfficial1 4 жыл бұрын
Amazing bro its very easy to understand it on my mind
@MohamedSayed-wl5cj
@MohamedSayed-wl5cj 5 жыл бұрын
fantastic lesson
@Octomovie
@Octomovie 7 жыл бұрын
One of the best tuts!!!!
@shawnflock7297
@shawnflock7297 7 жыл бұрын
Excellent tutorial.
@Gletsher
@Gletsher 5 жыл бұрын
Once again, you're my hero.
@samsar7
@samsar7 5 жыл бұрын
Love you brother ! thank you very much . whenever i search for the php tutorial i see you in the top. im from sri lanka . thank you very much .
@achyutharam1325
@achyutharam1325 6 жыл бұрын
download link is not working
@mohd-obid
@mohd-obid 2 жыл бұрын
Awesome 👍
@thisgamez9491
@thisgamez9491 4 жыл бұрын
Awesome! Thanks
@bryanDevsJS
@bryanDevsJS Жыл бұрын
Great stuff thanks
@melvin9198
@melvin9198 7 жыл бұрын
You're amazing. I've learned PHP, javascript and a little jQuery and AJAX by looking at your videos. Just wanted to say so, have a great day :)
@Dani_Krossing
@Dani_Krossing 7 жыл бұрын
You too :) I'm glad you like the lessons
@Kodeispoetry
@Kodeispoetry 4 жыл бұрын
I like your voice and style.
@Reeder6Wisconsin
@Reeder6Wisconsin 6 жыл бұрын
Great tutorial! At the 16:00 min mark, one thing to consider is changing the code to commentCount += 2; Perhaps the long way is clearer and takes less explanation, but it's not preferred, at least not for the teams I've been coding with. Thanks again!
@Room3102
@Room3102 3 жыл бұрын
Great video. Where can I find the lesson file? The link mmtuts isn't working. Thanks in advance.
@carztendk
@carztendk 4 жыл бұрын
I really needed to understand this, and found this video vey helpful. Thanks a lot :-), og jeg er behørigt imponeret at din engelske udtale. Well Done
@foxmulderqqs
@foxmulderqqs 5 жыл бұрын
I don't know enough English but I understand. You best
@Jeff-pt8sw
@Jeff-pt8sw 3 жыл бұрын
U saved mah life thank u
@majedabdullah1558
@majedabdullah1558 3 жыл бұрын
Awesome man Thanks
@عليالعمامي-ز1ذ
@عليالعمامي-ز1ذ 3 жыл бұрын
Thank you very much, when I studied it from a book, it was so tough ^^. But with your lessons; Sounds so easy, thank you. Continue 🔥
@JamsterJules
@JamsterJules 5 жыл бұрын
Fantastic tutorial. Very clear and simple. Well done !
@fajaana
@fajaana 6 жыл бұрын
Great tutorial! But I have a doubt. Your query has only the LIMIT 2, but no OFFSET value. So will it keep fetch and load all comments right from beginning up to the limit each time? I mean.. When the limit is 2 and on clicking the 'show more comments' button, it is displaying 2 new comments. so totally 4 comments. Is that fetching only the new 3rd and 4th comment? Or it again fetches 1st and 2nd comments as well?
@bm-rf4bc
@bm-rf4bc 5 жыл бұрын
You're correct to question this. The better way to set this up would be to pass a $_POST['offset'] variable and have a hard coded limit and also not use the .load() but rather a $.post('script.php', {offset : $('#comments .comment').length}, function(result, status) { // loop and append to #comments here })); The .comment class would be a new wrapped around the author name and the message output.
@WaymanSings_Codes
@WaymanSings_Codes 4 жыл бұрын
oh my God thanks man i finally managed to run select code through ajax
@kierdanganan1647
@kierdanganan1647 7 жыл бұрын
Well done mate! This helps me a lot thanks!
@robertcoffie8789
@robertcoffie8789 7 жыл бұрын
Man you are a life saver
@thesmuuuuggh
@thesmuuuuggh 7 жыл бұрын
thanks for this. you make me feel less alone in this crazy world of web development.
@Cyber99221
@Cyber99221 4 жыл бұрын
Like always, great video man! I think I'm subscribed to your channel in 3 different accounts
@DavidAshby1
@DavidAshby1 3 жыл бұрын
Hi Dani. If you are in a session can you use the same method. I have several individual forms on one page each with their own submit buttons to update their profile but currently the only way to get the latest data is to log out and back in?
@segunajala8388
@segunajala8388 6 жыл бұрын
Great video! Easy to understand
@danyprasetya1833
@danyprasetya1833 5 жыл бұрын
Cool ! Thanks for the tutorial
@alaminegueye3218
@alaminegueye3218 2 жыл бұрын
Excellent course ! But seems like the assets are not available in the description anymore :/
@nocturnal-chou
@nocturnal-chou 5 жыл бұрын
Great video!
@angelodelacruz9508
@angelodelacruz9508 4 жыл бұрын
Does di src script is required in your code for it to run
@sangambk6053
@sangambk6053 5 жыл бұрын
It was really helpful. Thanks a lot!
@dmitryklimov9706
@dmitryklimov9706 4 жыл бұрын
Hi Murphy. Is it possible to fetch WordPress MySQL db wpstg0_posts table to load a certain page storing in? Thank you!
@danielbuleandra3981
@danielbuleandra3981 2 жыл бұрын
Will you make an API t video in the future? I feel like is a missing pice.
@Alan-yg8wc
@Alan-yg8wc 4 жыл бұрын
Hi mmtuts, I noticed a lot of people use phpmyadmin as their database, but I used mysql workbench 8.0. The way you shown connecting, would it work for mysql workbench database? if not, can you give me some guidance?
@biljanam3458
@biljanam3458 7 жыл бұрын
Great explanation, good example, thank you!
@badreddineikhlef2085
@badreddineikhlef2085 6 жыл бұрын
the link is not working 404 Page Not Found! pliiiz hepl !!
@free_thinker4958
@free_thinker4958 4 жыл бұрын
The same problem for me 😢
@insaneminer
@insaneminer 4 жыл бұрын
having same issue with mmtuts.net/course.php?c=ajax&l=3 but i am getting server not found
@yoosufahmadh3945
@yoosufahmadh3945 3 жыл бұрын
Thank you soo much.
@christophertimosan4657
@christophertimosan4657 2 жыл бұрын
Where's the link?
@samyakjain5015
@samyakjain5015 5 жыл бұрын
You are awesome. Are all Norwegians awesome teachers?
@mibrahim4245
@mibrahim4245 2 жыл бұрын
extremely helpful !! THANK YOU ... I have a side question .. what is the best way to echo a HTML code "for example hello
@Dani_Krossing
@Dani_Krossing 2 жыл бұрын
It really depends on the purpose of what you are trying to output. 🙂 If the HTML should change depending on the PHP data, then echo the HTML out as well like you did in the first example. But if the HTML should remain static, then just echo the data like in example 2. If we talk security, as long as the data doesn’t come from an outside source (since we should never trust our users), then you don’t need to worry too much about it.
@mibrahim4245
@mibrahim4245 2 жыл бұрын
@@Dani_Krossing ooh, the legendary Krossing replied to me ❤ .. Thanks a lot for the knowledge you're sharing .. Thanks ...
@mibrahim4245
@mibrahim4245 2 жыл бұрын
@@Dani_Krossing I don't know also if you'll see this comment.. But I reallly wanted to know how to add html elements from admin page to the main page of our php website.. For example, i have a video playlist, each video with an id.. and I wanted to add another video element with a vid source and id .. so what's the safest way... THANKS IN ADVANCE
@sahil0295
@sahil0295 2 жыл бұрын
How to do the same things with element.... Like when i click on a different link the data should refresh accordingly. For example i have 5 links.. when i click on any link a set of data should comeup related to it... Please Help
@peugeot205gti5
@peugeot205gti5 7 жыл бұрын
Awesome job mate !!
@piamorcozo7240
@piamorcozo7240 3 жыл бұрын
Is there a way to get value of selected row in table and passing it in another php file using ajax?
@clealam9599
@clealam9599 5 жыл бұрын
Thank you so much for your tutorial. Thanks to you, I do not afraid of ajax !
@davidjoseph8400
@davidjoseph8400 3 жыл бұрын
Thank for the lesson, extremely comprehensive Please how can I replace the "load more button" to a scroll function? Such that once the page is scrolled down to the comments keep loading from set limit?
@ibropwns
@ibropwns 6 жыл бұрын
Nice tutorial, clarified a lot of things in a short time. Thanks mmtuts!
@minaamir2648
@minaamir2648 6 жыл бұрын
thanx .. very professional ..
@Abbici
@Abbici 3 жыл бұрын
Hallo... Thank for your help! But how can I use this for refresh the same page putting form?
@martin_and_gina
@martin_and_gina Жыл бұрын
I have a question sorry, would this method work for a html file? i noticed the file format he uses is php
@shinoypb6056
@shinoypb6056 4 жыл бұрын
Your a good teacher.and can i have the playlist link of this series
@robroy4046
@robroy4046 5 жыл бұрын
can i used that kind of syntax to update the scores ? i mean if i will update the record, is it going to update automatically to other browser?
@relaxingmusicandsceneryfor5816
@relaxingmusicandsceneryfor5816 3 жыл бұрын
Hi Dani, thanks for the tutorial. How to connect db using laravel ? do I just need to change the dbname on .env file ? Thanks!!!
@odunladeoluwaseun7880
@odunladeoluwaseun7880 7 жыл бұрын
Thanks for making me overcome my fear for php oop through your series on the subject. You are my best tutor on youtube. please can you create a single page website using bootstrap and php? thank you, I look forward to it.
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,3 МЛН
요즘유행 찍는법
0:34
오마이비키 OMV
Рет қаралды 12 МЛН
How to have fun with a child 🤣 Food wrap frame! #shorts
0:21
BadaBOOM!
Рет қаралды 17 МЛН
5: How to validate a form using AJAX - Learn AJAX programming
35:27
Dani Krossing
Рет қаралды 192 М.
AJAX Crash Course (Vanilla JavaScript)
1:09:43
Traversy Media
Рет қаралды 729 М.
JavaScript Pro Tips - Code This, NOT That
12:37
Fireship
Рет қаралды 2,5 МЛН
Ajax Live Data Search with jQuery PHP MySQL
10:20
WebsiteGeek
Рет қаралды 102 М.
JSON and AJAX Tutorial: With Real Examples
40:45
LearnWebCode
Рет қаралды 1,8 МЛН