Page 1 of 1

Can anyone tell me what is wrong with those two scripts??!!

Posted: Thu Jun 22, 2006 11:21 am
by tsalexey544
feyd | Please use

Code: Select all

,

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

,

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]

Posted: Thu Jun 22, 2006 11:25 am
by feyd
you're missing semicolons.. lots of them.

Posted: Thu Jun 22, 2006 11:28 am
by noclss2000
feyd | Please use

Code: Select all

,

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

,

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]

Posted: Thu Jun 22, 2006 11:31 am
by tsalexey544
I almot DROPED PHP FOR THE REST OF MY LIFE, but you saved me!!!!! THANKS!

Posted: Thu Jun 22, 2006 11:33 am
by tsalexey544

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 :cry:

Posted: Thu Jun 22, 2006 11:37 am
by feyd
Are you dumping this to a browser? Look at the page source if so.

Posted: Thu Jun 22, 2006 11:39 am
by tsalexey544
in the script I should get "b>a" or "b<a" NOT "b"

Posted: Thu Jun 22, 2006 11:50 am
by Jixxor
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 :cry:
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.

Posted: Thu Jun 22, 2006 11:52 am
by tsalexey544
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;
}

Posted: Thu Jun 22, 2006 12:01 pm
by Jixxor
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";
    }
?>

Posted: Thu Jun 22, 2006 12:06 pm
by RobertGonzalez
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]}.";
}
?>

Posted: Thu Jun 22, 2006 2:24 pm
by tsalexey544
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.

Posted: Thu Jun 22, 2006 3:31 pm
by RobertGonzalez
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>";
}
?>

Posted: Thu Jun 22, 2006 3:39 pm
by daedalus__
This stuff sounds like it's out of a book.

Finish the book and RTFM.