Author Topic: Newbie PHPer in Need  (Read 1954 times)

0 Members and 1 Guest are viewing this topic.

Offline !!!!!Topic starter

  • Enthusiast
  • Posts: 68
    • View Profile
Newbie PHPer in Need
« on: December 10, 2006, 12:28:22 AM »
Okay, I am readin a BOOk on PHP and so I am just writing newbie scripts. Why isn't this working?

Code: [Select]
<?php
$outputString 
"Hello world!"
$bus "Thewwra";
$es "Is a great Company"
$or "50";
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">


<html>

<head>
<title>Hi</title>
</head>
<body>

<?php
if ($or 58)
print "58 greater than Variable.";
else
print "58 is less than Variable.";
break;
echo 
"$bus $es";
break;
echo 
"Please join thewwra in our way to sell tons!";
?>


</body>
</html>

Offline fert

  • Devotee
  • Posts: 1,118
    • View Profile
Re: Newbie PHPer in Need
« Reply #1 on: December 10, 2006, 12:35:07 AM »
change
Code: [Select]
<?php
if ($or 58)
print "58 greater than Variable.";
else
print "58 is less than Variable.";
break;
echo 
"$bus $es";
break;
echo 
"Please join thewwra in our way to sell tons!";
?>

to
Code: [Select]
<?php
if ($or 58)
{
print "58 greater than Variable.";
}
else
{
print "58 is less than Variable.";
}
echo 
$bus.$es;
echo 
"Please join thewwra in our way to sell tons!";
?>


Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

Offline !!!!!Topic starter

  • Enthusiast
  • Posts: 68
    • View Profile
Re: Newbie PHPer in Need
« Reply #2 on: December 10, 2006, 12:39:30 AM »
change
Code: [Select]
<?php
if ($or 58)
print "58 greater than Variable.";
else
print "58 is less than Variable.";
break;
echo 
"$bus $es";
break;
echo 
"Please join thewwra in our way to sell tons!";
?>

to
Code: [Select]
<?php
if ($or 58)
{
print "58 greater than Variable.";
}
else
{
print "58 is less than Variable.";
}
echo 
$bus.$es;
echo 
"Please join thewwra in our way to sell tons!";
?>

Umm, that didn't do anything, but thanks for trying. It says: Fatal error: Cannot break/continue 1 level in /home/thewwrac/public_html/mine.php on line 27

Code: [Select]
<?php
$outputString 
"Hello world!"
$bus "Thewwra";
$es "Is a great Company"
$or "50";
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">


<html>

<head>
<title>Hi</title>
</head>
<body>

<?php
if ($or 58)
{
print "58 greater than Variable.";
}
else
{
print "58 is less than Variable.";
}
break;
echo 
"$bus $es";
break;
echo 
"Please join thewwra in our way to sell tons!";
?>


</body>
</html>
still need some fixin', thanks!

Offline fert

  • Devotee
  • Posts: 1,118
    • View Profile
Re: Newbie PHPer in Need
« Reply #3 on: December 10, 2006, 12:41:01 AM »
you need to remove th break; from your code, because you only use that when escaping a loop.

Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

Offline Mr_Pancakes

  • Irregular
  • Posts: 17
  • Gender: Male
    • View Profile
Re: Newbie PHPer in Need
« Reply #4 on: December 10, 2006, 12:42:14 AM »
try this instead:

Code: [Select]
if (count($or) > 58)
print "58 greater than Variable.";
else
print "58 is less than Variable.";

also, you don't need those "break"s in your code. try it - it'll work fine without them. another way to create your if statements is with the { and } characters. you might find this method to be easier to organize and view your code when you start using more than 1 line of code in an if statement.

Code: [Select]
if (count($or) > 58) {
       print "58 greater than Variable.";
       // a second line of code is acceptable when you use { and }
       // and even more lines of code
} else {
       print "58 is less than Variable.";
       // even more code
}

hope this helps.
cheers,
.s
« Last Edit: December 10, 2006, 12:43:57 AM by Mr_Pancakes »

Offline fert

  • Devotee
  • Posts: 1,118
    • View Profile
Re: Newbie PHPer in Need
« Reply #5 on: December 10, 2006, 12:43:55 AM »
count($or) won't work because $or isn't an array.

Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

Offline !!!!!Topic starter

  • Enthusiast
  • Posts: 68
    • View Profile
Re: Newbie PHPer in Need
« Reply #6 on: December 10, 2006, 12:45:53 AM »
count($or) won't work because $or isn't an array.
Okay, it works, but how do I break Echo and Print? Thanks a lot by the way

Offline Mr_Pancakes

  • Irregular
  • Posts: 17
  • Gender: Male
    • View Profile
Re: Newbie PHPer in Need
« Reply #7 on: December 10, 2006, 12:46:44 AM »
actually, upon a second review, count($or) woudn't work regardless because $or is equal to a string while the if statement is comparing to an integer.

try first setting $or equal to an integer as well.

Code: [Select]
$or = 50;

Offline fert

  • Devotee
  • Posts: 1,118
    • View Profile
Re: Newbie PHPer in Need
« Reply #8 on: December 10, 2006, 12:47:07 AM »
echo "<br >";
« Last Edit: December 10, 2006, 12:49:51 AM by fert »

Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

Offline Mr_Pancakes

  • Irregular
  • Posts: 17
  • Gender: Male
    • View Profile
Re: Newbie PHPer in Need
« Reply #9 on: December 10, 2006, 12:49:19 AM »
you can also insert an HTML break as well.

Code: [Select]
echo "blahhhhh <br />";

and if you wanna get picky, you could add a server line break to it all to line feed your code:


Code: [Select]
echo "blahhhhh <br />\n";