does anyone have good links for PHP tutorials?
cwncool
14-04-2006 11:28:56
(yes I have used google already) so Does anyone know any good links for PHP tutorials. I've read a few tutorials so I already know the BASIC basics. Thanx!
Armstrong
14-04-2006 11:55:47
http//www.w3schools.com
FreeOffersNow
14-04-2006 12:03:11
http//www.htmlite.com/PHPintro.php - Pretty basic, but it's a nice intro to PHP
http//www.php.net - Always a good resource
t.money
14-04-2006 12:13:54
php.net is absolutly fantastic when it comes to very freakin' function and technique you could imagine, but its only good when you need something on the fly.
If you're looking for a great resource, (I hope this doesn't break rules by offsite linking) I'd check out this thread on Newgrounds.com - its got some pretty fucking fantastic PHP tutorials (all user submitted)
http//newgrounds.com/bbs/topic.php?id=372890&page=8
fcpman3
14-04-2006 12:19:24
[quotefbafe9edaf="FreeOffersNow"]http//www.htmlite.com/PHPintro.php - Pretty basic, but it's a nice intro to PHP
http//www.php.net - Always a good resource[/quotefbafe9edaf]
I learned from PHP.net and it's really great for anything.
good2speed
14-04-2006 12:20:29
have a few pdf's regarding PHP(Wileys I think). Havent checked it out much as I havent needed to use that technology as of yet. Drop me a PM if interetsted and Ill see what I can do to get you some docs
FreeOffersNow
14-04-2006 13:10:47
Oh yea...I almost forgot, I have the SAMS PHP & MySQL Development ebook, too ;)
PM me to discuss
cwncool
14-04-2006 17:08:42
thanx for those tuts.... can someone explain to me though... i know how to make a form using html and PHP and the GET command so the url of "form.php" will display cat or something if "form.php?name=cat" or whatever, but how can I make it so when links throughout my site are like that?
EX
Main pages link is index.php
Main page has a link to "Cats"
Cats page link is index.php?page=cats and it has it's own unique content but without the "page=cats" or similar after "index.php" it is just index and there can be other "page=... " things ? Sort of like in the forums where there is "viewforum.php?f=8" and that has it's own content and "viewforum.php?f=4" and that has it's unique content... Does anyone understand? Thanx!
t.money
14-04-2006 17:19:10
This script is off the top of my head, but here goes
[code12c0475e6c3]
<?PHP
if($_GET['page']=='') {
echo 'index content - no page selected';
}else if($_GET['page']=='cats') {
echo 'cats content';
}
?>
[/code12c0475e6c3]
And so on. There are much better ways of going about this (arrays) but this is the most secure, down and dirty way.
cwncool
14-04-2006 17:25:55
that seems logical. i guess i just didn't know you could use GET without a form. hmm. ill try it! thanx!
cwncool
14-04-2006 17:41:12
it didn't work completly..... the code I used is...
[code1d16d8c81d9]
<?php
if($_GET['p']=='') {
echo 'this is the index';
if($_GET['p']=='cats') {
echo 'this is the cats page';
}
?>
[/code1d16d8c81d9]
now, if i view "mysite/ptest.php?p=", it echos correctly without errors.
if i enter "mysite/ptest.php?p=cats", it also echos correctly. if i just put "mysite/ptest.php" it shows the index text, but displays an error too. this is the complete text it shows if I only enter "mysite/ptest.php" without the "?p= ..."
[code1d16d8c81d9]
this is the index
Notice: Undefined index: p in c:\program files\easyphp1-8\www\ptest.php on line 3
[/code1d16d8c81d9]
can someone please tell me why?
cwncool
14-04-2006 17:46:23
ooooooh. lol. i figured it out. i had to add a if GET == NULL
this is the code I got to work.
[code1b12d4180a9]
<?php
if($_GET==NULL) {
echo 'this is the index';
}else if($_GET['p']=='') {
echo 'this is the index';
}else if($_GET['p']=='cats') {
echo 'this is the cats page';
}
?>
[/code1b12d4180a9]
t.money
14-04-2006 17:46:39
you need to close the curley bracket, friend.
I've fixed your script
[code12000d37887]
<?php
if($_GET['p']=='') {
echo 'this is the index';
}
else if($_GET['p']=='cats') {
echo 'this is the cats page';
}
?> [/code12000d37887]
t.money
14-04-2006 17:47:00
Oh, that too. Sorry I was slow (
theysayjump
14-04-2006 17:48:14
How easy is PHP to learn for an absolute beginner like myself?
I was thinking of learning it just for sake of learning it. Knowledge is power.
cwncool
14-04-2006 17:58:55
t.money
14-04-2006 18:07:39
PHP is fantastic. Unless you are a unix junkie (then perl might be more up your alley - a bit more flexibility) its a great all around language and has a very gradual learning curve.
Admin
14-04-2006 19:20:27
[quoteaf48ff633b="cwncool"]ooooooh. lol. i figured it out. i had to add a if GET == NULL
this is the code I got to work.
[code1af48ff633b]
<?php
if($_GET==NULL) {
echo 'this is the index';
}else if($_GET['p']=='') {
echo 'this is the index';
}else if($_GET['p']=='cats') {
echo 'this is the cats page';
}
?>
[/code1af48ff633b][/quoteaf48ff633b]
Here's how I'd do it
[code1af48ff633b]
if(!isset($_GET['p']) || empty($_GET['p']))
{
echo "Index content";
}
elseif($_GET['p'] == 'cats')
{
echo "Cat content";
}
[/code1af48ff633b]
If you're going to stick with this method and have a lot of different content pages, you might want to implement a switch()
[code1af48ff633b]
if(!isset($_GET['p'])) $_GET['p'] = ""; //ensure it's set
switch($_GET['p'])
{
case "cats": echo "Cats content."; break;
case "dogs": echo "Dogs content."; break;
case "":
default: echo "Index content."; break;
}
[/code1af48ff633b]
ajasax
14-04-2006 19:34:05
I recommend against using this type of script to load many pages from one page. A user could enter a URL for the "page" variable and possible screw things up. Besides, your script will get pretty dirty and unorganized once you start adding lots of content to each "page".
However, I also recommend w3schools for tutorials as well as other misc. sites you can find by doing a Google search.
@TSJ It shouldn't be too hard....I learned to script w/ PHP when I was about 13. Good luck!
cwncool
14-04-2006 22:29:00
[quote8f48e54ab2="Admin"][quote8f48e54ab2="cwncool"]ooooooh. lol. i figured it out. i had to add a if GET == NULL
this is the code I got to work.
[code18f48e54ab2]
<?php
if($_GET==NULL) {
echo 'this is the index';
}else if($_GET['p']=='') {
echo 'this is the index';
}else if($_GET['p']=='cats') {
echo 'this is the cats page';
}
?>
[/code18f48e54ab2][/quote8f48e54ab2]
Here's how I'd do it
[code18f48e54ab2]
if(!isset($_GET['p']) || empty($_GET['p']))
{
echo "Index content";
}
elseif($_GET['p'] == 'cats')
{
echo "Cat content";
}
[/code18f48e54ab2]
If you're going to stick with this method and have a lot of different content pages, you might want to implement a switch()
[code18f48e54ab2]
if(!isset($_GET['p'])) $_GET['p'] = ""; //ensure it's set
switch($_GET['p'])
{
case "cats": echo "Cats content."; break;
case "dogs": echo "Dogs content."; break;
case "":
default: echo "Index content."; break;
}
[/code18f48e54ab2][/quote8f48e54ab2]
ill try that. thanx!
kyks17
15-04-2006 18:02:35
dmorris68
15-04-2006 18:36:50
If you want a free full-featured PHP IDE, download Eclipse and the PHPEclipse plugin. I use Eclipse and Eclipse-based tools in my job every day for Java development, and have recently started playing around with the PHPEclipse plugin. Very nice.
http//www.eclipse.org
http//www.phpeclipse.de/tiki-view_articles.php
kyks17
15-04-2006 18:42:04
hot damn theres a php eclipse plugin? i friggin love eclipse, ill have to try it out
EatChex89
15-04-2006 19:47:01
just buy a book
fashionjunkee
15-04-2006 21:32:26
[quote58c025bf9e="cwncool"]thanx for those tuts.... can someone explain to me though... i know how to make a form using html and PHP and the GET command so the url of "form.php" will display cat or something if "form.php?name=cat" or whatever, but how can I make it so when links throughout my site are like that?
EX
Main pages link is index.php
Main page has a link to "Cats"
Cats page link is index.php?page=cats and it has it's own unique content but without the "page=cats" or similar after "index.php" it is just index and there can be other "page=... " things ? Sort of like in the forums where there is "viewforum.php?f=8" and that has it's own content and "viewforum.php?f=4" and that has it's unique content... Does anyone understand? Thanx![/quote58c025bf9e]
Tutorials here[=http//codegrrl.com/!/tutorials/view/dynamic_includes/]Tutorials here
cwncool
16-04-2006 12:01:29
can someone tell me how to echo a random picture? I tried this, but all the page shows is "1" . Just like that. all it echos is the number 1....
[code1f7ce2814ec]
<?php
$cat = "<img src = http://www.clock.org/~ambar/cats/jpgs/cory-kitten.gif>";
$puppy = "<img src = http://www.sendthisnow.com/blog/hello/10/2920/640/pups4wks_097a.2.jpg>";
$random = "$cat" || "$puppy";
echo "$random";
?>
[/code1f7ce2814ec]
that's what i tried....
mpj31
16-04-2006 12:42:49
See Below
Admin
16-04-2006 15:35:29
[quotee8525598b4="mpj31"]
What you are saying with
$image = $puppy || $cat;
is if $puppy == NULL then $image = $puppy...
but since u defined puppy then it isnt null 100% of the time.[/quotee8525598b4]
Not really, no. What that code does is evaluate the boolean expression ($puppy || $cat) - since both $puppy and $cat are defined and not empty, $image gets assigned boolean 'true'. when you echo a boolean variable, it displays 1 if true and 0 if false, which is why he was getting a 1.
mpj31
16-04-2006 18:08:28
yea thats what i meant...if it returns 0 it 'breaks' or doesnt go any further on and therefore $cat is never reached if $puppy is 0. Since puppy was clearly defined and is never going to be 0 then $cat is never echoed.
cwncool
16-04-2006 18:09:51
ugg. i tried this...
[code1cf871d040e]
<?php
$n = rand(0,1);
$img[0] = "img/cat.gif";
$img[1] = "img/pup.jpeg";
$image = "img/'.$img[$n].'";
echo "$n";
?>
[/code1cf871d040e]
but it doesn't work now. it either displays a 0 or a 1.....
mpj31
16-04-2006 18:21:41
Delete me.
cwncool
16-04-2006 19:00:34
thanx, but im getting some crap. it cant locate my image. it's working, but it shows me this...
[code17dd4d1016e]
img/'.img/cat.gif.'
Debug Menu
$n: 0
$img[$n]: img/cat.gif
$image: img/'.img/cat.gif.'
[/code17dd4d1016e]
and the image is a little "broken image" square. the script is in the root directory and the pics are in "/img" directory. help?
btw. i replied to your PM
compuguru
16-04-2006 19:03:16
You add the image directory twice, once when you define the images, and a second time when you output the image.
cwncool
27-08-2006 07:12:33
[quote0c68255154="Admin"]
If you're going to stick with this method and have a lot of different content pages, you might want to implement a switch()
[code10c68255154]
if(!isset($_GET['p'])) $_GET['p'] = ""; //ensure it's set
switch($_GET['p'])
{
case "cats": echo "Cats content."; break;
case "dogs": echo "Dogs content."; break;
case "":
default: echo "Index content."; break;
}
[/code10c68255154][/quote0c68255154]
sorry to bring up an old thread, but it was my thread and this is relevant.
could instead of echoing all of the content on the one page, because that would be very large, could I use this code and just include the pages with the content for each of those cases?
[code10c68255154]
if(!isset($_GET['p'])) $_GET['p'] = ""; //ensure it's set
switch($_GET['p'])
{
case "cats": include 'cat.php' ; break;
case "dogs": include 'dogs.php' ; break;
case "rabbits": include 'rabbits.php' ; break;
default: include 'index_content.php' ; break;
}
[/code10c68255154]
ajrock2000
27-08-2006 08:30:02
Yes, of course you can.