On Thu, Aug 05, 2010 at 10:10:26PM -0400, Rick Dwyer wrote: > Hi List. > I've mentioned before that I am both just beginning to learn PHP AND I have inherited a number of pages that I'm trying to clean up the w3c validation on. > > Something that confuses me is how the code on the page is written where in one instance, it follows this: > > echo "<table border='1'><tr>.... > > And elsewhere on the page it follows: > > echo '<table border="1"><tr>.... > > In what I've read and from many of the suggestions from this board, the latter seems to be the better way to code, generally speaking. > > So given that the page has javascript in it, perhaps the reason for the previous developer switching between the two was for ease of incorporating JS?.... Don't really know... but what I would like to know is it considered poor coding switch between the two on a single page or is it perfectly acceptable? > Not acceptable and sloppy. Be consistent in your coding style. In general, HTML attributes should be surrounded by double quotes. I don't know about javascript. Moreover, it's generally better to simply output HTML rather than to echo it, like: <table border="1"><tr> <td> <?php echo $some_value; ?> </td> </tr> > 2nd question, in the 3 lines below: > > $_SESSION['newpage'] = $newpage; > $checkstat = "select field from table where fieldid = $field_id"; > $result1 = @mysql_query($checkstat,$connection) or die("Couldn't execute query"); > > > If I were to recode in the latter style, should they not look like this: > > $_SESSION['newpage'] = $newpage; > $checkstat = 'select field from table where fieldid = "'.$field_id.'"'; > $result1 = @mysql_query($checkstat,$connection) or die('Couldn\'t execute query'); > This is a matter of taste, but I've heard that if you can do it without string concatenation, it executes faster. In my opinion, the former is better because it's easier to follow than the second, where you have strings concatenated with single and double quotes all over the place. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php