views:

1073

answers:

4

I would like to embed HTML inside a PHP if statement, if it's even possible, because I'm thinking the HTML would appear before the PHP if statement is executed.

I'm trying to access a table in a database. I created a pulldown menu in HTML that lists all the tables in the database and once I select the table from the pulldown, I hit the submit button.

I use the isset function to see if the submit button has been pressed and run a loop in PHP to display the contents of the table in the database. So at this point I have the complete table but I want to run some more queries on this table. Hence the reason I'm trying to execute more HTML inside the if statement. Ultimately, I'm trying to either update (1 or more contents in a row or multiple rows) or delete (1 or more rows) contents in the table. What I'm trying to do is create another pulldown that corresponded to a column in a table to make the table search easier and radio buttons that correspond to whether I'd like to update or delete contents in the table.

+6  A: 

Yes,

<?php
if ( $my_name == "someguy" ) {
    ?> HTML GOES HERE <?php;
}
?>
Jon
+25  A: 
<?php if($condition) : ?>
    <a href="http://yahoo.com"&gt;This will only display if $condition is true</a>
<?php endif; ?>

It's that simple.

The HTML will only be displayed if the condition is satisfied.

Frank Farmer
+1 because I favor that style in view-specific code.
m0rb
I hate echoing html!
Joe Philllips
+1 for answering the question.That said, the OP might want to look at a good templating language like Smarty to separate his view from his model somewhat.
Eddie Parker
+1 for using the alternate syntax, I always use this syntax in Views.
Michael Wales
+1 alternative syntax in views!
alex
A: 

Yes.

<?  if($my_name == 'someguy') { ?>
        HTML_GOES_HERE
<?  } ?>
chaos
short tags bad m'kay. Some servers don't have them enabled.
Gary Willoughby
Some servers don't have libxml or pdo_mysql installed, but we can still recommend solutions using them.
chaos
I think this should've been just a comment for Jon's answer.
Rimas Kudelis
Mmmkay. You want to tell me how exactly I embed formatted code in a comment?
chaos
A: 

Yes,

HTML GOES HERE

Asley Jan