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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.