Having struggled in the past to upload sourcecode using the pre and code tags and then still having to fiddle it is great to now have this simple method posted in the WordPress news section . I was so excited so I decided I had to blog about it.
My excuse for using it is a slight amendment to my January post on running queries against a MySQL database via PHP. I was finding that if I had a text field it was hard to see where one record ended and the next started.
| Record1 | Short data | Other data | And here is a cell with loads and loads on stuff written in it trying to look like the output from a text field in my database query. Can you see what it looked like before? It isn’t easy to see where one cell starts and the next finishes is it? |
| Record2 | Short data | Other data | Particularly if there are loads of fields in the output. This by the way is another cell with loads and loads on stuff written in it trying to look like the output from a text field in my database query. Shall we look and see what it all looks like with the alignment changed? |
Just do this when looping through the records instead:
while ($row = mysqli_fetch_row($result)) {
echo "<tr>";
for ($counter = 0; $counter < $numcols; $counter++) {
echo "<td valign=\\"top\\">". $row[$counter] ."</td>";
}
echo "</tr>";
}
| Record1 | Short data | Other data | And here is a cell with loads and loads on stuff written in it trying to look like the output from a text field in my database query. Can you see what it looks like now? Is it easier to see where one cell starts and the next finishes? |
| Record2 | Short data | Other data | Particularly if there are loads of fields in the output. This by the way is another cell with loads and loads on stuff written in it trying to look like the output from a text field in my database query. Not much of a change of code but I’ve found it much more readable particularly when looking to check what the body of a stored procedure does! |