Jump to content

Formatting in PHP


misslilbit02

Recommended Posts

Well this is a PHP question because I'm using PHP and a mysql database to output it to the browser. Sorry I wasn't clear about that. My question is how do I format data out of a mysql database?

 

I know how to print tables and things of that nature and I know this is very elementary but I have all of these entries in a mysql database and I want format the output so that every entry that comes out has indented paragraphs and has break after every 7-10 lines of data.

 

How do I go about doing that.

Link to comment
https://forums.phpfreaks.com/topic/73522-formatting-in-php/#findComment-370936
Share on other sites

Well this is a PHP question because I'm using PHP and a mysql database to output it to the browser. Sorry I wasn't clear about that. My question is how do I format data out of a mysql database?

 

I know how to print tables and things of that nature and I know this is very elementary but I have all of these entries in a mysql database and I want format the output so that every entry that comes out has indented paragraphs and has break after every 7-10 lines of data.

 

How do I go about doing that.

 

<?php
      // Variables
   $passMYSQL = 'MyPassword';
   $userMYSQL = 'MyUsername';
   $databaseMYSQL = 'MyDatabase';

     // Retrieve the data
    $CDB =  mysql_connect('localhost', $userMYSQL, $passMYSQL);
    $db_selected = mysql_select_db($databaseMYSQL, $CDB);

    $datw = mysql_fetch_assoc(mysql_query("SELECT post, text, whatever FROM TestTable WHERE post = 'UniqueId'"));
    mysql_close($CDB);

    // return data from the text column where post id is UniqueId
   echo '<p style="text-indent:1em;margin:0 0 7em 0;">'.$datw["text"].'</p>';
?>

 

Note i expect things to work, so error checking was left out to speed up abit..

Link to comment
https://forums.phpfreaks.com/topic/73522-formatting-in-php/#findComment-370944
Share on other sites

And with while loop:

<?php
      // Variables
   $passMYSQL = 'MyPassword';
   $userMYSQL = 'MyUsername';
   $databaseMYSQL = 'MyDatabase';
     // Used in the while loop
   $PostUniqueId = 1;

     // Retrieve the data
    $CDB =  mysql_connect('localhost', $userMYSQL, $passMYSQL);
    $db_selected = mysql_select_db($databaseMYSQL, $CDB);

while ($PostUniqueId <= 10) {
    $PostUniqueId++;

    $datw = mysql_fetch_assoc(mysql_query("SELECT post, text, whatever FROM TestTable WHERE post = '$PostUniqueId'"));
    // return data from the text column where post id is UniqueId
   echo '<p style="text-indent:1em;margin:0 0 7em 0;">'.$datw["text"].'</p>';
}
    mysql_close($CDB);
?>

 

Edit: Replaced $i with $PostUniqueId, since i think it makes more sense...

Link to comment
https://forums.phpfreaks.com/topic/73522-formatting-in-php/#findComment-370964
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.