Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Regular Coder
    Join Date
    May 2012
    Posts
    142
    Thanks
    112
    Thanked 0 Times in 0 Posts
    Thank you for the tips on the XHTML, and thanks for helping me understand the single sided tags. My page now validates! Whoo-hoo!

    But, the fix did not quite work..
    It viewed the same as it did before, but just left a large vertical gap between the 1st paragraph and the 2nd paragraph. (I tried showing you in this thread, but it is hard to make it look like it does on my web page).

    You see that yes, the paragraphs are now correctly separated (amen), but only the first line of the first paragraph is indented.

    I am hoping to indent the FIRST LINE of the second paragraph, as well as the first line of the third paragraph (and any subsequent paragraphs).

    I hope that makes sense. If you wouldn't mind taking a look at my page after work, you will see what I mean. I really hate to keep bugging you, but you obviously know php really well, and I am still trying to learn (and am soo close!). Thank you very much.

    I will show you my latest current code:
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
      <link rel="stylesheet" type="text/css" href="css/style.css" />
    </head>

    <body>

     *** <h1>Your Info</h1><br />


    <?php

            
    require ('dbstuff.php');
            
    $db connectDB();
     
            
    // get results from database 
            
    $query"SELECT * FROM mytable";   
                     
    $result=mysql_query($query)or die("Failed Query of " $query); 
    $num=mysql_numrows($result);
    mysql_close();

    $i=0;
    while (
    $i<$num) {  // beginning of outer loop

    $name=mysql_result($result,$i,"name");
    $address=mysql_result($result,$i,"address");
    $paragraph=mysql_result($result,$i,"paragraph");
    ?>


    <?php 
     
    echo "<b>Name:</b> "$name."<br/>"."<br/>" ;
      echo 
    "<b>Address:</b>  "$address."<br/>"."<br/>"."<br/>";
      echo 
    "<b>Paragraph(s) below:</b>"."<br/>";
     
    ?>
     <div class="paragraph">

     <p class="paragraph">
     <?php
    print nl2br($paragraph);
     
    ?>
     </p> 
     
     

     </div>

     &nbsp;
     <p><a href="user/add.php"> Back to User Interface</a></p>
     <?php

    ?>

    <?php
    $i
    ++;} // End of outer loop
    ?>

    </body>
    </html>

  2. #17
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Assign a class onto the paragraphs in the implosion, or use an inheritance in the CSS to apply the proper class to all subsequent paragraphs.

  3. Users who have thanked Fou-Lu for this post:

    Eggweezer (12-04-2012)

  4. #18
    Regular Coder
    Join Date
    May 2012
    Posts
    142
    Thanks
    112
    Thanked 0 Times in 0 Posts
    I am trying to follow you. I already have a class set to the paragraphs.

    p.paragraph{
    text-indent:40px;
    padding:1em .2em;
    }

    I am trying to understand this. Really.

  5. #19
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    Quote Originally Posted by Eggweezer View Post
    I am trying to follow you. I already have a class set to the paragraphs.
    You mean the..

    PHP Code:

     <p class="paragraph"> 
     <?php 
    print nl2br($paragraph); 
     
    ?> 
     </p>
    This would only apply to the content as a whole, which is why you only get one indent. The key here is getting each paragraph out of the single database result, and making them seperate elements in the mark-up. Then they can be formatted by the CSS, where formatting belongs. I don't see you doing that in your last code posted, perhaps you didn't understand that part?

  6. Users who have thanked Custard7A for this post:

    Eggweezer (12-05-2012)

  7. #20
    Regular Coder
    Join Date
    May 2012
    Posts
    142
    Thanks
    112
    Thanked 0 Times in 0 Posts
    Yes, you are correct.
    To be honest, I am by no means an expert in php yet, but trying.

    I had input the paragraphs as a whole into a VARCHAR(400) field. The folks today, showed me how to extract them while looking for the "line breaks" to identify new paragraphs.

    That works great, BUT as you know, I can only indent the first paragraph. I am kind of lost at the moment (to say the least!). Maybe, as you mentioned, I am using the wrong strategy? Any help would be greatly appreciated.

  8. #21
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    Indeed. Actually, all you need has already been suggested by Fou-Lu, but since he knows everything ever I think that his examples might go over your head rather easily.

    This code he posted on the previous page:

    PHP Code:

    printf
    ('<p class="paragraph">%s</p>'implode('</p><p>'explode("\n"trim($paragraph)))); 
    I suppose the best way to look at this is backwards, since that is more or less the way it will run.
    - You pass $paragraph into a trim function, to make sure there isn't hanging off whitespace.
    - This is then exploded into an array, with the break being on newlines.
    - It's then put back together with implode, however, this adds </p><p> after each item as it does so.
    - The result of all that will be put in the position of the %s in the first part of the printf.

    Making sense so far? That means if your database output this:

    This is a paragraph. \n This is another paragraph.
    The above would reach the page as:

    Code:
    
    <p class="paragraph">This is a paragraph.</p><p>This is another paragraph.</p>
    Edit: It would probably be more like this, actually (And I don't know if the newlines stay or not):

    Code:
    
    <p class="paragraph">This is a paragraph. </p><p> This is another paragraph.</p><p></p>
    This would be used like so, in your code:

    PHP Code:

     <?php

      
    // ... Other stuff

      
    echo "<b>Name:</b> "$name."<br/>"."<br/>" 
      echo 
    "<b>Address:</b>  "$address."<br/>"."<br/>"."<br/>"
      echo 
    "<b>Paragraph(s) below:</b>"."<br/>"

      
    ?>

      <div class="paragraph"> 
     
      <?php 
      printf
    ('<p class="paragraph">%s</p>'implode('</p><p>'explode("\n"trim($paragraph))));
      
    ?>   

      </div>
    For formatting that end result, you have two options as mentioned above by Fou-Lu. Assigning the class durring the implosion so all elements end up with your class, example (Note: implosion):

    PHP Code:


    printf
    ('<p class="paragraph">%s</p>'implode('</p><p class="paragraph">'explode("\n"trim($paragraph)))); 
    Or using "inheritance" (or more correctly, a descendant selector) in the CSS:

    Code:
    
    p.paragraph p { /* style for p tags inside p tags with class paragraph */ }
    Hope this helps you understand it all a bit. (Hope I explained it all right ).
    Last edited by Custard7A; 12-05-2012 at 02:36 AM.

  9. Users who have thanked Custard7A for this post:

    Eggweezer (12-05-2012)

  10. #22
    Regular Coder
    Join Date
    May 2012
    Posts
    142
    Thanks
    112
    Thanked 0 Times in 0 Posts
    Wow, that was an awesome explanation! Yes, Fou-lu was just a wee bit over my head, but I am sure is second nature to him.... (and you, apparently).

    It makes sense, and... it is also a good way to explain it backwards, as like you said, that is the way it is executed. Very nice.


    Now, I will have to play the last stage. The css. (yup. In the morning)!

    Thanks you all again for all your help!

    Working perfect. You folks are awesome!

    Thanks. What a great day
    Last edited by Eggweezer; 12-05-2012 at 02:58 AM.

  11. #23
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    Yay, it actually worked. I mean.. of course it worked!

    I was figuring it out as I typed to be honest, I knew what trim() was though.

  12. Users who have thanked Custard7A for this post:

    Eggweezer (12-05-2012)


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •