Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Which is the best practice ?

Featured Replies

When doing something like echoing out table row's in php is it better to group things as much as possible or do it lots of lines.

 

For example

 

Method 1:

<?php
echo "<tr><td class='row'>$mysqlvalue</td></tr>";
?>

 

Method 2:

<?php
echo "<tr>";
echo "<td class='row'>";
echo $mysqlvalue;
echo "</td>";
echo "</tr>";
?>

 

This is obviously quite a basic example but I was thinking in more complex situations it might make a bit of a difference ?

When doing something like echoing out table row's in php is it better to group things as much as possible or do it lots of lines.

 

For example

 

Method 1:

<?php
echo "<tr><td class='row'>$mysqlvalue</td></tr>";
?>

 

Method 2:

<?php
echo "<tr>";
echo "<td class='row'>;
echo $mysqlvalue;
echo "</td>";
echo "</tr>";
?>

 

This is obviously quite a basic example but I was thinking in more complex situations it might make a bit of a difference ?

Well firstly idk if you have noticed but you have one error in the code you forgot a quote at the end of the sec echo in example 2 and the best practice is example 2 though the first one would save you from having to write a few more echos but yea as for best practice its the sec.

  • Author

Well firstly idk if you have noticed but you have one error in the code you forgot a quote at the end of the sec echo in example 2 and the best practice is example 2 though the first one would save you from having to write a few more echos but yea as for best practice its the sec.

 

Yh slight mistake lol..

 

So would there not be any difference in the speed that either was executed ?

Yh slight mistake lol..

 

So would there not be any difference in the speed that either was executed ?

 

Nah their would be no diff in your code speed wise their perfectly both good at using but im just use to using the sec one so i think it makes for better practice but eather ones perfectly fine hope this helped :yahoo:

  • Author

Ah ok thanks mate :)

You can use commas as a compromise point, you get both HTML layout and less echo calls:

 

<?php

echo "<tr>,
<td class='row'>,
$mysqlvalue,
</td>,
</tr>";

?>

Even better: don't mix excess HTML and PHP:

 

// break out of PHP
?>
<tr>
<td class="row"><?php echo $mysqlvalue; ?></td>
</tr>
<?php
// and we're back again...

  • Author

^ Yh I know that but in actual case that I was using it that bit of code is inside an if statement so it gets echoed out for every record that is in the database...

 

I see your point though.

performance-wise

one echo is better than many

comma separate echo statement is faster than concatenated (i.e .= ) type statements

alternatively, use output-buffering.

Even better: don't mix excess HTML and PHP:

 

// break out of PHP
?>
<tr>
<td class="row"><?php echo $mysqlvalue; ?></td>
</tr>
<?php
// and we're back again...

 

 

I second this. Also...a million echo is silly...this isn't dollhouse. ;)

  • Author

Yh I know from the example I've put it looks like I'm echo'ing it all out for no reason..

 

But where I'm actually using this it needs to be like that.

 

Anyway question answered, thanks

I second this. Also...a million echo is silly...this isn't dollhouse. ;)

 

Dugg for Whedon

performance-wise

one echo is better than many

comma separate echo statement is faster than concatenated (i.e .= ) type statements

alternatively, use output-buffering.

Worrying about micro-optimisations normally detract attention from the bigger picture. If your app is so big that the fraction of a second saved by using a comma over "." is important, this probably isn't the forum to be asking questions on.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.