Hey...just wondering what the norm/preferred method (if there is one) is.

So I'm wondering if I should have all my code look like this:

 

<?php
        if($Approved == 0){
	        $approvedCheck = false;
	}
	?>
	<tr>
	<!--the next 8 lines set each record as the while loop passes thru it-->
	<td id="date<?php echo $j;?>"><? echo $Date; ?></td>		
	<td id="date<?php echo $j;?>"><? echo $Hours; ?></td>
	<td id="date<?php echo $j;?>"><? echo $Phase."&nbsp;"; ?></td>
.
.
.
.
.
        </tr>

or if it is better to have it like this where ALL code is wrapped in <?php ?> tags, and all html code is echo'd:

<?php
        if($Approved == 0){
	        $approvedCheck = false;
	}

echo"<tr>";
//the next 8 lines set each record as the while loop passes thru it
echo"<td id="date<?php echo $j;?>"><? echo $Date; ?></td>";	
echo"<td id="date<?php echo $j;?>"><? echo $Hours; ?></td>";
echo"<td id="date<?php echo $j;?>"><? echo $Phase."&nbsp;"; ?></td>";
.
.
.
.
.
        echo"</tr>";

Or maybe it doesnt make any difference what so ever. I am just wondering which way other people are doing it.

thanks!

    you may like to consider a template engine. Otherwise the norm is what ever is going to work best for you.

      I find arrays to be a good way of outputting data effectively. Program scripts to format your data to the way you want it then add it to an array in the order of your liking. Also this gives you a dynamic way of outputting allot of data quickly, using multi-dimensional arrays for example.

      $output['data']['title'][] = 'datadatadata';
      $output['data']['content'][] = 'moredata';
      

      Then just using a simple display function that you can create to display to the view page. Most times just using a for...each/for/do...while/while/ statements will work too.

      I don't know, I just rather this way. As he said, whatever works for you.

        Somewhere down the bottom of the pile of components that I've built on top of each other in order to automate the boring repetitive things about coding (like writing screeds of <tags>) there's an XHTML renderer. I presume it's still down there because XHTML is still coming out of it 😉, but I haven't been down there in over a year.

          I would do something like this:

          <?
          if($Approved == 0){
             $approvedCheck = false;
          }
          ?>
          <tr>
             <td id="date<?=$j;?>"><?=$Date;?></td>		
             <td id="date<?=$j;?>"><?=$Hours;?></td>
             <td id="date<?=$j;?>"><?=$Phase."&nbsp;";?></td> // Why the "&nbsp;"?
          </tr>
          

          <?= is the same as <?php echo

          But as dagon said "the norm is what ever is going to work best for you"

            Haddman wrote:

            <?= is the same as <?php echo

            If short open tags are enabled, and they might not be, especially since they are not the default and can come into conflict with <?xml.

              6 days later

              Just for pure readability, I don't like to jump in and out of PHP much. In many cases, I also find that it reduces the actual volume of code if I just write a block of PHP instead. Take your example and ask yourself which line is shorter:

              <td id="date<?php echo $j;?>"><? echo $Date; ?></td>

              -- or --

              echo "<td id='$j'>$Date</td>";

              I also take full advantage of the fact that while HTML doesn't care whether you use single or double quotes, they are treated differently by PHP - so you can nest single-quotes in a double-quoted string.

              Additional note: you will probably want to add some source code formatting for troubleshooting the HTML, but your PHP line will still be shorter:

              echo "\t<td id='$j'>$Date</td>\n";
                23 days later

                and then for large chunks of output, there's heredoc:

                print <<<EOC
                content goes here
                EOC;
                
                  Write a Reply...