PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tsalexey544
Forum Commoner
Posts: 41 Joined: Thu Jun 22, 2006 11:19 am
Post
by tsalexey544 » Thu Jun 22, 2006 11:21 am
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Can anyone tell me what is wrong with those two scripts??!!Code: Select all
<?
$abc=23
if ($abc>20){
print("abc<20")}
else {print ("abc > 20")}
?>
Code: Select all
<?
$a=23
$b=32
if ($b>$a){
print("b<a")}
else {print ("b > a")}
?>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jun 22, 2006 11:25 am
you're missing semicolons.. lots of them.
noclss2000
Forum Newbie
Posts: 7 Joined: Thu Jun 22, 2006 11:11 am
Post
by noclss2000 » Thu Jun 22, 2006 11:28 am
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]Code: Select all
<?
$abc=23;
if ($abc>20) {
print("abc<20");
} else {
print ("abc > 20");
}//end else
?>
Code: Select all
<?
$a=23;
$b=32;
if ($b>$a) {
print("b<a");
} else {
print ("b > a");
}//end else
?>
There you go
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
tsalexey544
Forum Commoner
Posts: 41 Joined: Thu Jun 22, 2006 11:19 am
Post
by tsalexey544 » Thu Jun 22, 2006 11:31 am
I almot DROPED PHP FOR THE REST OF MY LIFE, but you saved me!!!!! THANKS!
tsalexey544
Forum Commoner
Posts: 41 Joined: Thu Jun 22, 2006 11:19 am
Post
by tsalexey544 » Thu Jun 22, 2006 11:33 am
Code: Select all
<?
$a=23;
$b=32;
if ($b>$a) {
print("b<a");
} else {
print ("b > a");
}//end else
?>
On this script I get "b" printed
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jun 22, 2006 11:37 am
Are you dumping this to a browser? Look at the page source if so.
tsalexey544
Forum Commoner
Posts: 41 Joined: Thu Jun 22, 2006 11:19 am
Post
by tsalexey544 » Thu Jun 22, 2006 11:39 am
in the script I should get "b>a" or "b<a" NOT "b"
Jixxor
Forum Commoner
Posts: 46 Joined: Wed Jun 07, 2006 5:53 pm
Location: Lakeland, FL
Post
by Jixxor » Thu Jun 22, 2006 11:50 am
tsalexey544 wrote: Code: Select all
<?
$a=23;
$b=32;
if ($b>$a) {
print("b<a");
} else {
print ("b > a");
}//end else
?>
On this script I get "b" printed
By the looks of it, your logic is a little screwed.
Try this:
Code: Select all
<?php
$a = 23;
$b = 32;
if ($b > $a)
echo "$b is greater than $a";
else
echo "$b is not greater than $a";
?>
EDIT: Used single quotes instead of doubles.
tsalexey544
Forum Commoner
Posts: 41 Joined: Thu Jun 22, 2006 11:19 am
Post
by tsalexey544 » Thu Jun 22, 2006 11:52 am
And what about this one
Code: Select all
$names[0] = 'John';
$names[1] = 'Paul';
$names[2] = 'Steven';
$names[3] = 'George';
$names[4] = 'David';
$number = 5;
$x = 0;
while ($x < $number); {
$namenumber = $x + 1;
echo "Name $namenumber is $names[$x]";
++$x;
}
Jixxor
Forum Commoner
Posts: 46 Joined: Wed Jun 07, 2006 5:53 pm
Location: Lakeland, FL
Post
by Jixxor » Thu Jun 22, 2006 12:01 pm
tsalexey544 wrote: And what about this one
Code: Select all
$names[0] = 'John';
$names[1] = 'Paul';
$names[2] = 'Steven';
$names[3] = 'George';
$names[4] = 'David';
$number = 5;
$x = 0;
while ($x < $number); {
$namenumber = $x + 1;
echo "Name $namenumber is $names[$x]";
++$x;
}
Try using a for statement:
Code: Select all
<?php
$names = array('John', 'Paul', 'Steven', 'George', 'David');
for ($x = 0; $x < 5; $x++)
{
$namenumber = $x + 1;
echo "Name: {$names[$x]} Key: $namenumber";
}
?>
Last edited by
Jixxor on Thu Jun 22, 2006 12:09 pm, edited 1 time in total.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Jun 22, 2006 12:06 pm
tsalexey544 wrote: And what about this one
Code: Select all
$names[0] = 'John';
$names[1] = 'Paul';
$names[2] = 'Steven';
$names[3] = 'George';
$names[4] = 'David';
$number = 5;
$x = 0;
while ($x < $number); {
$namenumber = $x + 1;
echo "Name $namenumber is $names[$x]";
++$x;
}
Code: Select all
<?php
$names[0] = 'John';
$names[1] = 'Paul';
$names[2] = 'Steven';
$names[3] = 'George';
$names[4] = 'David';
$number = 5;
$namenumber = 0;
$x = 0;
while ($x < $number) {
$namenumber += 1;
echo "Name $namenumber is {$names[$x]}.";
++$x;
}
?>
You could also achieve this using a for loop...
Code: Select all
<?php
$names = array('John', 'Paul', 'Steven', 'George', 'David');
$limit = count($names);
for ($i = 0; $i < $limit; $i++)
{
$namenumber = $i + 1;
echo "Name $namenumber is {$names[$i]}.";
}
?>
tsalexey544
Forum Commoner
Posts: 41 Joined: Thu Jun 22, 2006 11:19 am
Post
by tsalexey544 » Thu Jun 22, 2006 2:24 pm
Everah wrote: tsalexey544 wrote: And what about this one
Code: Select all
$names[0] = 'John';
$names[1] = 'Paul';
$names[2] = 'Steven';
$names[3] = 'George';
$names[4] = 'David';
$number = 5;
$x = 0;
while ($x < $number); {
$namenumber = $x + 1;
echo "Name $namenumber is $names[$x]";
++$x;
}
Code: Select all
<?php
$names[0] = 'John';
$names[1] = 'Paul';
$names[2] = 'Steven';
$names[3] = 'George';
$names[4] = 'David';
$number = 5;
$namenumber = 0;
$x = 0;
while ($x < $number) {
$namenumber += 1;
echo "Name $namenumber is {$names[$x]}.";
++$x;
}
?>
You could also achieve this using a for loop...
Code: Select all
<?php
$names = array('John', 'Paul', 'Steven', 'George', 'David');
$limit = count($names);
for ($i = 0; $i < $limit; $i++)
{
$namenumber = $i + 1;
echo "Name $namenumber is {$names[$i]}.";
}
?>
I can't undestan how to make each name in a different line.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Jun 22, 2006 3:31 pm
On the screen, use this to break up the lines
Code: Select all
<?php
$names = array('John', 'Paul', 'Steven', 'George', 'David');
$limit = count($names);
for ($i = 0; $i < $limit; $i++)
{
$namenumber = $i + 1;
echo "<p>Name $namenumber is {$names[$i]}.</p>";
}
?>
In the output HTML, to put them on their own lines...
Code: Select all
<?php
$names = array('John', 'Paul', 'Steven', 'George', 'David');
$limit = count($names);
for ($i = 0; $i < $limit; $i++)
{
$namenumber = $i + 1;
echo "\n<p>Name $namenumber is {$names[$i]}.</p>";
}
?>
daedalus__
DevNet Resident
Posts: 1925 Joined: Thu Feb 09, 2006 4:52 pm
Post
by daedalus__ » Thu Jun 22, 2006 3:39 pm
This stuff sounds like it's out of a book.
Finish the book and RTFM.