You're a great teacher!!! Keep up with the good work! Thank you for making this free course! I wish to see more about OOP and Mysqli together, PHP is such a beautiful language...
I see things are getting tougher and tougher as I go in depth with PHP, but I'm glad that at the end of the day, at least I've learned something new all thanks to you. For example now I know I can use the console logs to identify errors in my code. So thanks man...
This was really helpful! I've been learning PHP and now I'm learning AJAX and advanced javaScript stuff, and this was eaxctl what I needed, learning how to bridge the two together. Looking forward to seeing your video on how to do the same with MySQL =) Thanks a ton man. I'll make sure I check out more of your stuff too.
This was a nice stretch and overall Challenge. I'm glad I understand enough of the fundamentals to pick up what was taught during this lesson. This is my first time working with AJAX and live Server Response/Request Cycles. I really picked up a lot. Not sure if I could do it on my own, but I was able to follow exactly what you did, and could definitely adapt the code to another set of data and tweak things. Thank you for this. You've help me immensely!
if anyone has issues understanding what's going on in suggest.php. I suggest you, debug the code. Set the variables in debug watch and you will know what are the values as it loops through the array. Keep in mind the functionality of substr() and stristr() functions. I set two variables like below inside the loop and set these variables in debug watch to check values of these variables. $substr = substr($person, 0, $length); $stristr = stristr($q, $substr); Debugging the code will give you a thorough understanding of how it works
Another great video, Brad. I think it would've been helpful to explain your PHP conditional logic a bit more. I was okay with the AJAX since I'd covered it in a different course recently. I will pause the video, look at your code and try to figure out how it's all working. Edit: Took me about 5 minutes to look up the PHP functions/methods and figure out the conditional logic! :-)
All of this is really cool and I wish i could even aspire to be able to come up with stuff like this on my own but for now it just goes way over my head.
To anyone having trouble getting their code to work, I would suggest you check all your conditionals and make sure your using the right operators, For example I had been using '==' in the suggest.php where I should have been using '==='
Ok, you completely lost me here, Brad! I have been able to follow your tutorials and understand the code until now but this video was totally out of my depth! I'll try to re-watch it again and also move on to the next video, hoping some things will click eventually.
You are probably confused by the JavaScript. Take a break and do some JavaScript. It is basically the code that runs in the browser or 'front-end'. It goes inside the tags. What the JavaScript code is doing is making a request to the 'back-end', which is the .php file on the server. The server handles the request and sends it back to the 'front-end'/web-browser. :)
You can get that on easiest way! inside php file put the simple Array with the $names = array("name1", "name2", "name3"); and use php to loop true the names. One simple if inside with in_array() method to check is mached with the names in the array, else return no-suggestion matches. Its simple code with 5 lines of code. 😕 php is easier than JS.
If you have in your array of people names like Jim and Jimmy add these lines to your code: if ($q===strtolower($person)){ $suggestion=$person; } Because if you type Jimmy you still get Jim as a suggestion
I found out that it's a good idea to add if (strlen($q) > strlen($user)) { continue; } in the beginning of the foreach loop to stop suggesting names which don't match.
I think that Brad's suggest solution is confusing. We can use substring function and check if that part is same as query, but first we convert both to lower string. foreach ( $people as $person ) { if ( strtolower ( substr ( $person, 0, $len ) ) === strtolower ( $q ) ) { if ( $suggestion === "") { $suggestion = $person; } else { $suggestion .= ", $person"; } } }
Okay, this is reassuring. I also thought/figured out that this might be another solution (comparing the values directly instead of using stristr() ). However, the benefit of stristr() is that it's already case-insensitive, so perhaps that's why Brad used it.
hii , thanks for all effort at this series .. but i tried it but didn't work without any error , it don't show the suggestions ! i think there are a problem at the connection or at getting the request , can any one help !? thanks..
You should really consider learning Javascript first before learning PHP. A whole new world opens up with Javascript and a server-side language like PHP.
Yep, it was tough for me too. I have javaScript knowledge but very little. I would suggest printing the codes to the paper and analyzing the code, adding arrows etc just to understand what or where was those particular code was targeting. Sorry if my English is not that good though but I hope this one helps. Good luck to all!
i know this is pretty old but i cant get your code link to go anywhere.. i seem to have everything correct but i guess not because im getting the correct suggestions back in the response, i can see from the network tab, but its not outputting to the DOM...
Is there a 16.zip ? I went back over surrounding zips and it jumps from 15 to 17. I admit I haven't read the threads so please forgive me if someone has pointed out the file ...
first they say u can get a job with html,css and a little bit of javascript knowledge. But then suddenly php happens..we learned this. Now they're saying you have to know node.js,dom,react.js, Ajax, php frameworks ,,css frameworks,Mysql,,,algorithm.but still you can't get a job.You need to know more..But still not get a job..and one day we will die.....But still we need to learn new technologies..But don't expect job.
I'm having issue with this.. Failed to construct 'XMLHttpRequest': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
Did you use the correct syntax for this line: var xmlhttp = new XMLHttpRequest(); ? Make sure you're referencing xmlhttp in the commands below it, and not xhttp.
Can you post the code? My code isn't working and i have been trying to find out why... when i type it's saying i have an error in my suggest.php file outside of my php tags...Can you fix the link in the description please...Thank you Brad.
Brad I like your videos and they have taught me a lot. I have however found a subtle BUG in your code in the suggest.php code. CHANGE THIS CODE if (stristr($q, substr($person, 0, $len))){ TO THIS CODE if (stristr(substr($person, 0, $len), $q )){ The order of comparison is significant. if you don't then be prepared to get weird behaviour once the list that is suggested gets wittled down as you continue to type in characters. I find that if I TYPE in XXXXyyy and get suggestions like XXXXyy and XXXXyyyb, it wil still keep on displaying XXXXyy even though the last character I type was a 'y'. It seems to not properly compare the item typed against the list. By the time you type in XXXXyyyb, your're stil sitting with XXXXyy in the list. I tested this on a list of a few thousand string items. It works excellent once the bug is removed. I think you worked on a short list for the video, so you probable have not found the bug, but it does become annoying. I changed the order passed to the 'stristr' function to: Searched string as first param and SearchedFor (which they call the needle) as the second.. problem solved... Hope it helps someone. I know I am a few years late, but this is what it is. Thanks for great videos.
Hi, I am having a small problem here. Nothing is showing when I typed in the box and when I pressed f12 to trace the error, it showed showSuggestion is not defined. I know for sure I have defined it and followed the instruction just as taught in this video. What do you think the problem could be? Thanks
Finally found the problem. Believe it or not, it was because I put xmlhttp.open("GET", "suggest.php?q="+str, true); xmlhttp.send(); side by side with the closed braces instead of at the bottom of it.
I'm impressed. No importing libraries, setting routes, exposing variables… Just a single plain php file with a nested if block and an echo. Bravo!👏👏👏
You're a great teacher!!! Keep up with the good work! Thank you for making this free course! I wish to see more about OOP and Mysqli together, PHP is such a beautiful language...
I see things are getting tougher and tougher as I go in depth with PHP, but I'm glad that at the end of the day, at least I've learned something new all thanks to you. For example now I know I can use the console logs to identify errors in my code. So thanks man...
This was really helpful! I've been learning PHP and now I'm learning AJAX and advanced javaScript stuff, and this was eaxctl what I needed, learning how to bridge the two together. Looking forward to seeing your video on how to do the same with MySQL =)
Thanks a ton man. I'll make sure I check out more of your stuff too.
Use PDO! :)
This was a nice stretch and overall Challenge. I'm glad I understand enough of the fundamentals to pick up what was taught during this lesson. This is my first time working with AJAX and live Server Response/Request Cycles. I really picked up a lot. Not sure if I could do it on my own, but I was able to follow exactly what you did, and could definitely adapt the code to another set of data and tweak things. Thank you for this. You've help me immensely!
if anyone has issues understanding what's going on in suggest.php. I suggest you, debug the code. Set the variables in debug watch and you will know what are the values as it loops through the array. Keep in mind the functionality of substr() and stristr() functions. I set two variables like below inside the loop and set these variables in debug watch to check values of these variables.
$substr = substr($person, 0, $length);
$stristr = stristr($q, $substr);
Debugging the code will give you a thorough understanding of how it works
It's SO nice to see SOMEONE finally using VanillaJS instead of stupid jQuery. Nearly all employers seem to favor VanillaJS. Thank you!
So glad I found your channel! Thank you!
Another great video, Brad. I think it would've been helpful to explain your PHP conditional logic a bit more. I was okay with the AJAX since I'd covered it in a different course recently. I will pause the video, look at your code and try to figure out how it's all working.
Edit: Took me about 5 minutes to look up the PHP functions/methods and figure out the conditional logic! :-)
Once again, you're the man brad
This is exactly what I've been looking for to get a filter system for my website, thanks Brad!
Best Tutorial vids on UA-cam keep up the great work bro
My two favorite UA-cam TEACHERs are Brad Traversy and Tim Buchalka from "The Learn Programming Channel"
after spending 30 minutes wondering why my code wasn't working, I realized the "s" in this.readystate wasn't capitalized.
Thank you.
After reading your comment, I realized that I have added a 's' in 'readyState'... So, thank you so much for unintentionally helping me...
Now you will remember this for a long time :)
lol, same here
Thanks man
All of this is really cool and I wish i could even aspire to be able to come up with stuff like this on my own but for now it just goes way over my head.
Awesomeness has been redefined! this is great! Ajax is god!
Thanks Man have been waiting for days for the next video
Lifesaver Brad
To anyone having trouble getting their code to work, I would suggest you check all your conditionals and make sure your using the right operators, For example I had been using '==' in the suggest.php where I should have been using '==='
I wish I could like your videos 100000000000000 times
All your tutorials are very interesting, continue more than this. Thank you...>
Thank so much for the tutorial. You are the best!
This is exactly what I needed right now! Thanks!
Ok, you completely lost me here, Brad! I have been able to follow your tutorials and understand the code until now but this video was totally out of my depth! I'll try to re-watch it again and also move on to the next video, hoping some things will click eventually.
don't worry its easy you will get it
yeah he shouldnt have added the javascript when intoducing the topic for the first time, kinda overcomplicated the whole process.
@@bentaylor10 ajax start and end with javascript dear
php is only used in url section of ajax
You are probably confused by the JavaScript. Take a break and do some JavaScript. It is basically the code that runs in the browser or 'front-end'. It goes inside the tags. What the JavaScript code is doing is making a request to the 'back-end', which is the .php file on the server. The server handles the request and sends it back to the 'front-end'/web-browser. :)
Nice video. A question: is JSON.parse the same as this.responseText? When to use either?
Wow Brad thank you this is great!
Great tutorial. Looking forward to the MySQL PDO example, based on PDO delusions db connection using OOP.
Love and respect for ma man brad
You can get that on easiest way! inside php file put the simple Array with the
$names = array("name1", "name2", "name3");
and use php to loop true the names. One simple if inside with in_array() method to check is mached with the names in the array, else return no-suggestion matches. Its simple code with 5 lines of code. 😕 php is easier than JS.
Great work, cheers !
big ups to this guy👌
Great Series ! Thank you !
very useful stuff.
Awesome. Did you by any chance hook this up to database.
thanks again
If you have in your array of people names like Jim and Jimmy add these lines to your code:
if ($q===strtolower($person)){
$suggestion=$person;
}
Because if you type Jimmy you still get Jim as a suggestion
Where exactly to add this code?
I found out that it's a good idea to add
if (strlen($q) > strlen($user))
{
continue;
}
in the beginning of the foreach loop to stop suggesting names which don't match.
Why do you add bootstrap to your code? Is it necessary? I don't know anything about bootstrap!
I think that Brad's suggest solution is confusing. We can use substring function and check if that part is same as query, but first we convert both to lower string.
foreach ( $people as $person ) {
if ( strtolower ( substr ( $person, 0, $len ) ) === strtolower ( $q ) ) {
if ( $suggestion === "") {
$suggestion = $person;
} else {
$suggestion .= ", $person";
}
}
}
Okay, this is reassuring. I also thought/figured out that this might be another solution (comparing the values directly instead of using stristr() ). However, the benefit of stristr() is that it's already case-insensitive, so perhaps that's why Brad used it.
if you want use fetchApi implement below
function showSuggestion(str) {
if (str.length === 0) {
document.getElementById('output').innerHTML = '';
} else {
fetch(`suggest.php?q=${str}`, {method: 'GET'})
.then(res => res.text())
.then(text => document.getElementById('output').innerHTML = text)
.catch(err=>console.log(err))
}
}
ty sir
Nice!
Way over my head. But thanks anyway. Appreciated as always.
Trying to do it with fetch API is a pain in the ass, is it still commonly used with AJAX ?
I'm gonna use fetch or axios instead
hii , thanks for all effort at this series .. but i tried it but didn't work without any error , it don't show the suggestions !
i think there are a problem at the connection or at getting the request , can any one help !? thanks..
This part was really tough for me. I guess because I don't know javascript.
Yeah I figured it would be. I just wanted to do something with Ajax. It was a little hard to explain though.
Actually, I'm new to web development that's why I don't know javascript.
But seriously Brad, you are doing great. (Y)
You should really consider learning Javascript first before learning PHP. A whole new world opens up with Javascript and a server-side language like PHP.
Yep, it was tough for me too. I have javaScript knowledge but very little. I would suggest printing the codes to the paper and analyzing the code, adding arrows etc just to understand what or where was those particular code was targeting. Sorry if my English is not that good though but I hope this one helps. Good luck to all!
Need more content
Stop the course here, and start to learn JS
))
can someone explain how the this.value works ? Is value a property ?
What about this example in CodeIgniter?
I did all along the full course Back to Front tutorials .. but this one is really confusing and not work for me as well.
i know this is pretty old but i cant get your code link to go anywhere.. i seem to have everything correct but i guess not because im getting the correct suggestions back in the response, i can see from the network tab, but its not outputting to the DOM...
jk 😅 i didnt capitalize the S in this.readyState...
Is there a 16.zip ? I went back over surrounding zips and it jumps from 15 to 17. I admit I haven't read the threads so please forgive me if someone has pointed out the file ...
Hi can we have this connect to db fetch db from MySQL
first they say u can get a job with html,css and a little bit of javascript knowledge. But then suddenly php happens..we learned this. Now they're saying you have to know node.js,dom,react.js, Ajax, php frameworks ,,css frameworks,Mysql,,,algorithm.but still you can't get a job.You need to know more..But still not get a job..and one day we will die.....But still we need to learn new technologies..But don't expect job.
I wrote the same code but in output the hole array after a first letter name
after i made the request i am getting undefind values
I'm having issue with this.. Failed to construct 'XMLHttpRequest': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
Did you use the correct syntax for this line:
var xmlhttp = new XMLHttpRequest();
?
Make sure you're referencing xmlhttp in the commands below it, and not xhttp.
Can you post the code? My code isn't working and i have been trying to find out why... when i type it's saying i have an error in my suggest.php file outside of my php tags...Can you fix the link in the description please...Thank you Brad.
Check the details
Brad I like your videos and they have taught me a lot. I have however found a subtle BUG in your code in the suggest.php code.
CHANGE THIS CODE if (stristr($q, substr($person, 0, $len))){
TO THIS CODE if (stristr(substr($person, 0, $len), $q )){
The order of comparison is significant. if you don't then be prepared to get weird behaviour once the list that is suggested gets wittled down as you continue to type in characters. I find that if I TYPE in XXXXyyy and get suggestions like XXXXyy and XXXXyyyb, it wil still keep on displaying XXXXyy even though the last character I type was a 'y'. It seems to not properly compare the item typed against the list. By the time you type in XXXXyyyb, your're stil sitting with XXXXyy in the list. I tested this on a list of a few thousand string items. It works excellent once the bug is removed. I think you worked on a short list for the video, so you probable have not found the bug, but it does become annoying.
I changed the order passed to the 'stristr' function to: Searched string as first param and SearchedFor (which they call the needle) as the second.. problem solved...
Hope it helps someone. I know I am a few years late, but this is what it is. Thanks for great videos.
Thanks Brad. I rewrote this code easiest and simple modern way. To download:
www.mediafire.com/file/d40pxh3b42v9xyz/ajax_search.zip/file
Can anyone tell me when to use cookies while creating a website?
from javascripter point of view, this was difficult to understand, the way PHP create API very easily it is not usual in javascript
I missed a "=" and the whole thing almost didn't work.
please someone should help me out........
I dont understand how $len is working here...
When the child started crying at 11:25 I thought that my baby was crying...
ben gerizekalı mıyım
First
Hi, I am having a small problem here. Nothing is showing when I typed in the box and when I pressed f12 to trace the error, it showed showSuggestion is not defined. I know for sure I have defined it and followed the instruction just as taught in this video. What do you think the problem could be?
Thanks
Finally found the problem. Believe it or not, it was because I put xmlhttp.open("GET", "suggest.php?q="+str, true);
xmlhttp.send(); side by side with the closed braces instead of at the bottom of it.
good to know you resolved your problm
Awesomeness has been redefined! this is great! Ajax is god!
Nice!