Jump to content


Photo

quick question about generated html source code


  • Please log in to reply
4 replies to this topic

#1 xfezz

xfezz
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 24 October 2006 - 05:19 AM

the html source code generated from this block of code is one big long line of html code. (seems to scroll like 10 pages across, one div tag after another with the output of the database)

    $SQL = "SELECT * FROM articles ORDER BY id DESC";
    $result = mysql_query($SQL);
      while ($db_field = mysql_fetch_array($result)) {
		$now_format = $db_field['article_date'];
		$new_format = date('F d, Y',strtotime($now_format)); // transform
                echo "<div id=\"article_date\">". $new_format ."</div>";  // prints out: date in following format October 20, 2006
		echo "<div id=\"article_chk\">"."<input type=\"checkbox\" name=\"del_select[]\" value=\"$db_field[id]\" />"."</div>"."<br>";
		$db_field['message']=nl2br($db_field['message']);
                echo "<div id=\"article_body\">" .$db_field['message']  ."</div>";
}


Is there a way to have  the output separated it when viewing the html source code? so it looks nice and neat?


#2 tippy_102

tippy_102
  • Members
  • PipPipPip
  • Advanced Member
  • 446 posts

Posted 24 October 2006 - 05:48 AM

Adding a /n will give you a line break:

echo "<div id=\"article_body\">" .$db_field['message']  ."</div>/n";

Fur is more actively protested than leather 'cause its easier to harrass rich women than biker gangs.

#3 xfezz

xfezz
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 24 October 2006 - 06:08 AM

ok ty i got the line break. its \n btw not /n. another quick question. I have seen some sites that have the html source code lines indented. obviously it was generated code. anyone know how they did that?

#4 tippy_102

tippy_102
  • Members
  • PipPipPip
  • Advanced Member
  • 446 posts

Posted 24 October 2006 - 05:06 PM

They probably use a tab (or two) for that - \t
Fur is more actively protested than leather 'cause its easier to harrass rich women than biker gangs.

#5 Psycho

Psycho
  • Moderators
  • Move along, nothing to see here
  • 11,892 posts
  • LocationCanada

Posted 24 October 2006 - 06:38 PM

Or you could simply include the spaces/tabs within the echo statements. This:

<?php
echo "<table>\n";
echo "    <tr>\n";
echo "        <td>Data1</td>\n";
echo "        <td>Data2</td>\n";
echo "        <td>Data3</td>\n";
echo "    </tr>\n";
echo "</table>\n";
?>

Will output this:
<table>
    <tr>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
    </tr>
</table>

The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users