Jump to content


Photo

Noobie Stuff: Very Basics Explained Easily


  • Please log in to reply
117 replies to this topic

#1 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 31 July 2006 - 07:51 PM

RIGHT!!

It Has Been A Year Since I Started Trying To Learn PHP And I Have Had Enough Of Saying Im A Noob Needing Help N Then Getting A oad Of Technical Talking Thrown Down My Gob Like Im So Pro.

I Have Also Seen Alot Of People In My Position-Being Given Code To Use But Never Understanding It.

IT STOPS HERE!

I Have Made This Topic So That Noobs Like Me Can Get Basic Things In Php Explained To Us In The Most Simple Way They Can.

I Am Asking Everyone Out There To Help Us Noobs By Explaining Things In Very Simple Terms-To Help Us Understand Things Easier And Stop Us Having To Ask People For Coding Help.

Firstly-I Would Like To Know What These Are In The Simplest Way Possible.

Arrays
Strings
How To Store Cookies In A Browser For A Log In Script (Which Time Out After Inactivity On The Particular Site).
when , should be used and why
when () should be used and y
when {} should be used and y
when " should be used and why
when ' should be used and why (i know its a string thing but thats all)

Please If You Are A Noob Or Not But Need Help-Explain What You Need Help With.

If You Are Here To Explain-Please Keep It Simple-I Feel If This Topic Goes As Planned-Alot Of People Will Be Helped.

Thank You All

Pudgemeister
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#2 maxic0

maxic0
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 31 July 2006 - 07:57 PM

Very well said. Yeah i would like those explained aswell please.

#3 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 31 July 2006 - 08:05 PM

Unfortunately, what you are asking are the very basics of PHP. (And in a lot of cases, other programming languages.) Now, if you have spent 1 year learning PHP, and do not know when "{" should be used, or what Arrays are...then you have not applied yourself. I believe your lack of understanding, is due to an "I want to learn quick with no work" approach to things. This might not be accurate but, is true most of the time. What those things do, can be learned by doing no more than 30 mins of research and reading.

Please visit: http://www.php.net

It's a great resource and there's more than enough there to learn those things you are asking about. Being a newbie is all well and good...but a lot of us here learned what we did via lots of work and time invested.
PHP Ninja

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 31 July 2006 - 08:11 PM

Arrays: Groups of items (numbers, characters, strings, etc).  The reason we use arrays is so we can loop through items quickly and process them faster.  If I didn't use an array, i'd be doing something like this:

$myvar1 = 1;
$myvar2 = 2;
$myvar3 = 3;

With an array, you can do this:
$myvar = array(1,2,3);
or
<?php
for($i=0;$i<10;$i++)
  $myvar[] = $i;
print_r($myvar); // prints out the array values
?>

Then you have access to all those values through the same variable.

Strings:
Strings are just groups of characters put together to form words.  I'm not sure what the question is here, but this could be very broad.  Maybe you can elaborate on what you want?  There's not much typecasting in PHP, so the topic is vague.

setcookie()
I recommend looking it up in the manual.  I don't think anyone can explain it any easier.  www.php.net

operators
, - Not sure why you're using them... usually to seperate lists.  I can't think of much else!?
() - Their use is usually optional.  I know some people that use them around echo/print statements, but you don't need to.  They are required when making a call to a function.
{} - necessary if using an if or a loop statement that contains more than one line.  Most people use them regardless as good coding practice, but they're not absolutely required unless you're going beyond one line.
quotes - Use double quotes in an echo if you want to just put your variables straight in there (e.g. echo "this is my $var";)  Use single quotes if you're using HTML tags just to make it easier (e.g. echo '<img src="here.gif" alt="test">';)

There are a bunch of other examples I could throw out, but I'll let someone else add to this post.

Info: PHP Manual


#5 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 31 July 2006 - 08:14 PM

Arrays
Strings
How To Store Cookies In A Browser For A Log In Script (Which Time Out After Inactivity On The Particular Site).
when , should be used and why
when () should be used and y
when {} should be used and y
when " should be used and why
when ' should be used and why (i know its a string thing but thats all)

------------------

1. Arrays are a group of variables which share the same name.  Each element is accessed by a numerical or associative key:  $array[0] or $array['banana'], forexample
2. A string is a block of text, to put it basically.  "This is a string"
3. Don't use cookies, use sessions.  Read the phpfreaks session articles for more details.
5. Commas seperate parameters and loop arguments.
5. Parentheses set off various information, such as function parameters, loop conditions, etc:  function newFunction(parameter1, parameter2)
6. Braces are used to block off if/else statements, functions, loops, and other things.  if(statement=true){run the code inside the braces if the statement is true}

Quotes are more complex than what I'm about to write, but in general the confusion between the two is this:

7. Double quotes are used for interpolation in strings, which means variables can be placed inside the string and it will still be processed: $variable = red; echo "My car is $variable" will output "My car is red".
8. Single quotes are used in strings for concatenation, which means the above example would return "My car is $variable" without processing the PHP inside the single quotes.  You must concatenate instead with single quotes:  'My car is' . $variable  (The period serves as glue and joins the two value types together into one string.)

That was typed very fast and may be a bit sloppy.  However, if you are unfamiliar with any of the vocab in that, you need to learn it because you can't just avoid the "technical" side of PHP... you will see/hear those terms for as long as you code.  Another suggestion is to look up these topics on the phpfreaks site.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#6 akrytus

akrytus
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 31 July 2006 - 08:21 PM

I too have been learning PHP for about 1 year.  Although I have background in various programming languages, the online help is so helpful.  

I have found the hardest part of programming is figuring what it is you want.  This is up to you!  

Then when you have figured that out, then finding out what the php functions are available to you to accomplish the task.  For that you can come here.  Most of these guys if not all have run into that or know about it and can point you in the right direction of what functions to use.  

Now you know what you want and what to use.  Now it is time to figure out how those functions work.  It is up to you to look them up in the manual.  They tell you the syntax and what the function does.  Even better they give plenty of examples of using the function in real code that is usually well documented.  

Once you learn what the function does, apply it.  When it doesnt work, come back here and ask why!  

One step at a time, and you will catch on quickly.  Quit using the code people give you and paste into your code.  Figure out what it does and why!  This is how I learned and I think I caught on rather quickly.  It's a lot of work, but worth it!

#7 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 31 July 2006 - 08:28 PM

$myvar1 = 1;
$myvar2 = 2;
$myvar3 = 3;

With an array, you can do this:
$myvar = array(1,2,3);
or
<?php
for($i=0;$i<10;$i++)
  $myvar[] = $i;
print_r($myvar); // prints out the array values
?>


The For Loop:
In this case you are starting the loop off by setting i=0, you are looping until i reaches 10, after each loop add 1 to i (You can also use $i = $i + 1, or if you are taking one away you can use $i-- or $i = $i - 1)

Anything in the body of the loop is the stuff that is getting processed.

Programming can be very dry or very creative and a lot of fun.

if($php == "dry"){
  $outcome = "You aren't having enough fun.";
}elseif($php == "interesting" && $php == "inspiring"){
  $outcome = "You are having fun!";
}else{
  $outcome = "You might be having fun, you might not...read the manual!";
}

just a little example for the hell of it  8)

-Chris

#8 griffon

griffon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 31 July 2006 - 08:36 PM

I'm almost the newest PHP newbie with all of five days experience and I found a simple little book called PHP with MySQL by Nat McBride ISBN: 0340905565.  It cost me £10 in Oxford, UK and it's a great little introduction to the subject.  Now I know there's lots of info on the net but sometimes it's nice to sit down away from the PC and look over a book because, when you're starting out, it's good to have an overview of a subject rather than diving into the detail of a particular problem.  I know there are more technical books on the subject, and probably better ones overall, but this little paperback covers most of the things you asked about I think.  

#9 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 31 July 2006 - 08:46 PM

You can also look around the internet and find some well written and documented tutorials. Once you know what you want and what you are looking for it should be pretty easy.

Just remember that Ebay, Amazon, and whoever else...wasn't built in a few days...be patient and focused and everything will come.

-Chris

#10 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 01 August 2006 - 06:22 AM

that is acytually y i am getting into php.

i am hoping to within a few years to have written a php script that drives a text based rpg (like ogame.org).

thankfully i am starting college this year and will be doing it for 4 years learning php in parts of these years.

i am then thinking to help this little game i have got here i could go onto college to do a coding course-just dont know (if ne) what ones there are yet.

neway keep the basics coming people-theres alot of satisfaction in this topic

Pudgemeister
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#11 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 01 August 2006 - 12:23 PM

i need to know how to say

if (this thing is unequal to this thing(not equal))
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#12 pedrobcabral

pedrobcabral
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 01 August 2006 - 12:28 PM

http://pt.php.net/operators.comparison have you tryed to search?

#13 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 01 August 2006 - 12:32 PM

if( $x != $y)

This is basic programming, not just basic PHP but basic C and Javascript too. If you are just starting out learning PHP this forum should not be your first port of call. I recommend getting hold of a book like PHP and MySQL for Dynamic Web Sites by Larry Ullman, or if you're feeling a bit more confident, PHP and MySQL Web Development by Welling and Thomson. I have these beside me always, especially the latter - books like these are your bible when getting started.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#14 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 01 August 2006 - 12:40 PM

if ($X != 1) {
// do this
}

or

if ($X != 1) {
// do this
} else {
// do this if it is equal to 1!
} // end if/else statement

I have been doing php for 2 months? with prior html experience and I have already made a basic forum system with user registration, login/logout, posting threads, posts, edit posts, where the user is on the board, profile view, memberlist, etc.

Although this I would like to know how to do:
How To Store Cookies In A Browser For A Log In Script (Which Time Out After Inactivity On The Particular Site).
Or make sessions time out after inactivity.

#15 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 01 August 2006 - 12:48 PM

So what's with everyone capitalizing the first letter of every word?

Anyway, use sessions.  Do a php.net or phpfreaks search and you'll find some great references.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#16 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 01 August 2006 - 03:20 PM

I Think The Letter Capitalisation Was Started By Me. :D

Sorry-Looked Good Is All HeHeHeHe
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#17 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 01 August 2006 - 03:48 PM

ne1 else got nething to know or offer?
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#18 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 01 August 2006 - 08:16 PM

right i have now.

i need to know how to add a minimum character limit to a password field so that the minimum password length is as much as i want it to be.

also-i need to know how to make it so the code only processes the passord if it has alphanumeric vailue inputted by the person registering.

thanx people-will read tomorow.

Pudgemeister
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#19 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 01 August 2006 - 09:01 PM

if (strlen($pass) < 8) { // if length of string for password is less than 8 digits
echo 'Password must be 8 characters or more.';
}


#20 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 04 August 2006 - 10:10 AM

aha! thank u very much!

ne1 help me with making it only accept the password when it only has alphanumeric values?

i know its an if else-i just dont know the alpha numeric command(s)

Pudgemeister
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users