[thelist] Simple IF THEN in PHP

Mattias Thorslund mattias at inreach.com
Sun Mar 6 10:40:33 CST 2005


It's very simple.

PHP syntax is pretty similar to Javascript or C# (just to give you an
idea - I'm not saying it's the same). All variable names begin with a $,
and you terminate lines with a semicolon.

The online PHP manual is probably all you will need.
http://www.php.net/manual/en/

<?

$somecounter = 1


while ($whatever_condition){

  if ($somecounter == 1){
    print "hello world"; //or echo
    $somecounter = $somecounter + 1; //or $somecounter++;
  } else {
    //else clause not needed
  } //end if

} //end while loop
?>


Christian Anderson wrote:

>Hi Everyone,
> 
>I do all my work in ASP, but now have to add a little bit of flavor to a bit
>of PHP.
> 
>Basically, I want to do an IF THEN that would work like this in ASP.
> 
><%
> 
>somecounter = 1
> 
>DO while whatever... <-- the blog is taking care of this stuff -->
> 
>if somecounter = 1 then
>response.write("hello world")
>somecounter = somecounter + 1
>else
>end if
> 
>LOOP <-- again the blog software is taking care of this -->
> 
>%>
> 
>Basically I want to put some code only on the first post of a blog posting.
>So basically on post 1 it will put in the "hello world" thing, and then for
>any other posts that appear on that page it wont show anything.
> 
>I'm sure its not hard, but I haven't used PHP before so don't know how it
>works exactly.
> 
>Thanks!
> 
>Christian Anderson  クリスチャン アンダーソン
>::  <http://www.ckapublishing.com/> http://www.ckapublishing.com
>:: MSN / Webcam :  <mailto:platesonyourass at hotmail.com>
>platesonyourass at hotmail.com
> 
>  
>

-- 
More views at http://www.thorslund.us




More information about the thelist mailing list