Forum Moderators: coopster
<?
$email = NULL;
$er_email = NULL;
if(isset($_POST['sub'])){
$email = $_POST['email'];
if(!$email){
$er_email = "<i>email is required</i>";
}
}
?>
<form action="test.php" method="post">
Email: <?=$er_email?><br />
<input type="text" name="email" value="<?=$email?>" /><br />
<input type="submit" name="sub" value="submit">
</form>
Does it mean the same as if($email == "")
I just learned this shorthand and recently the
<?=$email?> is the same as <?php echo $email; ?>
What other nifty shorthand exists? Ive looked around but now found much on this.
Normal (Generally Used version)
----------------------------------
$id=$_GET['id'];
$sql="select * from myTable where id=$id";
$result=mysql_query($sql) or die(mysql_error());
$record=mysql_fetch_assoc($result);
----------------------------------
Quick Version ;)
---------------------
$record=mysql_fetch_assoc(mysql_query("SELECT * FROM myTable WHERE id='".$_GET["id"]."'"));
---------------------
Oh Sorry :( i forgot the main question was related to what you asked, i got carried away by
What other nifty shorthand exists? Ive looked around but now found much on this.
[edited by: Anyango at 9:14 am (utc) on Nov. 22, 2008]
In the long run you will do best to write your code in the clearest way possible; and that is seldom by switching in and out of PHP parsing mode. If you have lots of HTML content in your script, move it out and put it into a template file or a database - separate your code and your content. Such practices are, in fact, the ultimate shorthand.
I have one page of logic doing the php and I assign my variables I need to my template, the template with the html is used with light php to spit out what I want it to, multiple models with all my queries organised by action - select, delete, insert, update. You can even go so far as to add more models as you go along for specific sections of a site too. This makes it much easier to maintain.
Everything is split up, sure lots of clicking between folders but you always know where the problem is straight away this way as well. Is it your logic? Template? Or Query?