silverglade Posted February 25, 2010 Share Posted February 25, 2010 hi, i have wanted to learn php for a long time. when i go to the tutorial project examples they are too hard. i finished the tutorial at w3schools.com. take this code for example, from a forum tutorial. i barely have an idea of what it means. i understand the code to a shoutbox, a guestbook, but this forum. it is too complicated, and that is hindering my learning, always finding tutorials that are too complicated and i stop learning. here is the code below, i dont need an explanation, i just need someone to give me advice on what i should do when i find tutorials like this that leave me stuck not learning php. any advice GREATLY appreciated because i have been wanting to teach myself with tutorials but always get stuck when they jump in complexity. thanks. derek //Create a class called Users class Users { //This is the function executed when the class is created __construct($Args=array()) //WHAT DOES =ARRAY MEAN { } function Restrict($Args='') //I DONT UNDERSTAND THIS { if(is_array($Args)) { if(in_array($_SESSION['Level'], $Args)) { return 1; } //I DONT UNDERSTAND THIS } else { if($_SESSION['Level'] == $Args) { return 1; } } return 0; } function LoggedIn() { if(isset($_SESSION['ID']) && $_SESSION['Level'] != 0) { return 1; } return 0; } function Login ($Args) //WHAT IS ARGS { $Username = $Args['Username']; //Sanatize inputs by hashing the variable, use a varchar in database of at least 50 $Usernane = mysql_real_escape_string($Username); $Password = $Args['Password']; $Password = mysql_real_escape_string($Password); $Password = md5($Password); $search = mysql_query("SELECT * FROM `members` WHERE `Username`='$Username' AND `Password`='$Password'"); if(!mysql_num_rows($search)) { //Returns a value from function return 0; } else $search = mysql_fetch_array($search); $_SESSION['ID'] = $search['ID']; //I DONT UNDERSTAND THIS $_SESSION['Level'] = $search['Level']; return 1; } } Quote Link to comment Share on other sites More sharing options...
silverglade Posted February 25, 2010 Author Share Posted February 25, 2010 also, i find myself unable to alter the tutorial code to fit my needs because i dont know what im doing. Quote Link to comment Share on other sites More sharing options...
newrehmi Posted February 25, 2010 Share Posted February 25, 2010 i am kinda new (very new) in php too (just a month of learning php).. Firstly, learn the basic. Learn how to echo things. try echo some variable if you dont understand. Example is, <?php echo $args; ?> or put something in a variable and echo it. You will understand. example, $hello = "hello world!"; <==== it mean you put word hello world in those variable. so when you echo $hello; it will give you hello world!.. sorry if its too basic, just trying to figure what do you want to know. secondly, understand from the very beginning of the script. What every function does. (and what {} does, what == does, what . does...) Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 25, 2010 Share Posted February 25, 2010 I would suggest reading up on programming basics - the language is not important. Once you understand loops, functions, conditions, etc. then it is just a matter of learning the syntax of whatever language you are working in. So, if you are confronted with new code that you do not understand, you just need to read the manual - PHP has an excellent one with descriptions and examples at php.net. So, when you come to a command in the tutorial you do not understand read the manual for that command. It will be slow going at first, but as you master each command it becomes easier over time. Quote Link to comment Share on other sites More sharing options...
silverglade Posted February 25, 2010 Author Share Posted February 25, 2010 thanks ya i know echo and variables, control structures, etc, but when it comes time to apply my knowledge , like in the above code , i get lost. i have learned the basic syntax of php, at w3schools.com, but i am unable to progress onto the harder tutorials, or modify them in any way. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 25, 2010 Share Posted February 25, 2010 The answer that I have for you is both simple and frustrating: If a tutorial is too hard and you aren't learning anything from it, then find another tutorial to focus on. A well written tutorial should list upfront the prerequisite knowledge for the tutorial. Example: This tutorial assumes you are familiar with the following: 1) Object basics (constructor, methods, properties, private, protected, and public) 2) Default function arguments 3) Something else... The tutorial should introduce the exact idea it wants to present and it should stick to that. A tutorial on sessions shouldn't sidetrack for 8 pages on how to escape data for a database. The tutorial should then solve, step by step, the problem. It might go as far to show different solutions, each increasing in complexity but also increasing stability and robustness. So my advice is to find a different set of tutorials. Or for the low, low price of $30 or $40 you can buy one of the many great O'Reilly books written by great authors on programming. You can get them even cheaper used on some popular media and auction websites! In place of a book on the subject, you might read the entire PHP manual including the user comments. If you had read the manual, then you would understand perfectly: __construct($Args=array()) And I'm pretty sure the function keyword is not optional when declaring a function. So if your tutorial isn't even presenting valid PHP code...well... Quote Link to comment Share on other sites More sharing options...
silverglade Posted February 25, 2010 Author Share Posted February 25, 2010 WOW mjdamato thank you so much for that idea!! i never thought of doing that i dont know why. i really think that might work. great advice . put this up as a sticky! hehe. jk. i will try that and see how it goes, including deciphering the above code too. thanks. derek Quote Link to comment Share on other sites More sharing options...
silverglade Posted February 25, 2010 Author Share Posted February 25, 2010 great roopurt18, thank you both. im going to copy/paste your posts in a text file and read it over and over when i want to give up. this is GREAT advice. thanks so much. derek Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.