View Full Version : Converting a bit of VB logic to PHP
gorilla1
11-08-2002, 04:53 AM
In asp I have a script with the following logic:
Call DisplayForm()
}
Else
Call DoSignup()
}
The two routines are basically just different pieces of html. Can I do something like this in PHP, or will I have to write all the html out with echo statements in order to make the if then logic work??
G
Spookster
11-08-2002, 06:19 AM
What are those two routines suppose to do?
There are many ways you can do this in PHP.
<?php
if(condition1){
echo "all your html here"
}
else {
echo "other html here"
}
?>
or
<?php
if(condition1){
?>
all your html here
<?php
}else {
?>
other html here
<?php
}
?>
or
<?php
if(condition1){
include "html1.stuff"
}
else {
include "html2.stuff"
}
?>
or
<?php
if(condition1){
function1thatprintshtmlstuff();
}
else {
function2thatprintsotherhtmlstuff();
}
?>
or
<?php
if(condition1){
echo function1thatreturnshtmlstuff();
}
else {
function2thatreturnsotherhtmlstuff();
}
?>
firepages
11-08-2002, 06:23 AM
well you could write the HTML content in 2 seperate include files then...
<?
if($condition){
$include_this='./html/signup_form.inc';
}else{
$include_this='./html/do_signup.inc';
}
?>
<html>
//blah//
<?readfile('include_this');?>
//blah//
</html>
but there are a hundred different ways to approach it ?
many apps are now taking the 1 file approach with 1 index or controller file that includes the correct content depending on the current request , almost event driven just without the events ;)
firepages
11-08-2002, 06:26 AM
sorry Spooks did not see you there ! just goes to proove there are a yaksload of ways!
Spookster
11-08-2002, 06:31 AM
yes I could have kept yakking some more out but my yakker was getting tired. Time to upgrade my yak :D
firepages
11-08-2002, 07:16 AM
:D yep my yak has a lack of stamina thesedays , I am considering investing in a llama but am not sure if they are X-platform
gorilla1
11-08-2002, 11:31 AM
Ah, thanks. There is a lot of html, so I wanted to avoid having to write echo's and appropirate punctuation through it all, so the include approach is good.
G
fractalvibes
11-09-2002, 04:20 AM
Sure, you can do alot of the same things in PHP that you would
do with ASP via included files/functions. A little different syntax, and watch your semicolons and curly-braces!
What matters is the architecture - common routines that can be included, etc.
Phil J.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.