SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 71

Thread: Line Breaks

  1. #26
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bonk
    It also preserves the line break, so this is the same as nl2br:

    $line = str_replace("\n","<br />\n",$line);

    But who's counting exactly what it does
    Lol, that's what I say to *my* boss (in regards to outputted HTML formatting, anyway...)

    Interesting point -- thanks for the tidbit!
    My name is Steve, and I'm a super-villian.

  2. #27
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $line = nl2br($line);
    Ok, so which page do I put this on? The display results page? And do I have to alter that code to fit my textarea name or leave it as it is?

  3. #28
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Possibility
    Ok, so which page do I put this on? The display results page? And do I have to alter that code to fit my textarea name or leave it as it is?
    I put mine on the page that displays the results or what is being pulled from the database and not in the database itself that way their is not code mixed with content so to speak so only put it where the content or text is being displayed

  4. #29
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Possibility, why are you using arrays as your names for single elements? That's your biggest problem. Do you understand the difference between an array and a variable? I think you are using an array (incorrectly) instead of a variable, which is all you apparently need.

    Rename ALL your form fields on your initial page to a single word:

    Code:
    <textarea name='body' rows='7' cols='50'>
    Then on your processing page, set the textarea content back to a single variable:
    Code:
    $body = $_POST['body']; // puts the text into a variable called $body
    $body = nl2br($body); // converts line breaks to BR tags
    --Viral
    A computer without Windows is like a chocolate cake without mustard.

  5. #30
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doing...

    I had it in arrays because of the tutorial that I am (modifying) it from had it in an Array to begin with....I don't know why.

    Actually, it's a book, not a tutorial.

    I'll report back in a couple hours.

    EDIT: All arrays have been converted.

    I put that code in the handleform page but it doesn't work. I then tried placing it in the display results page, but it doesn't work. I think I am placing it in the wrong position, though.

    Here is my source of my handle from page:

    Code:
    <HTML>
    <HEAD>
    <TITLE>Inserting Data into a Database</TITLE>
    </HEAD>
    <BODY>
    <?php
    /* This page receives and handles the data generated by "form.html". */
    // Trim the incoming data.
    $Name = trim ($Name);
    $Strat = trim ($Strat);
    $Body = trim ($Body);
    $God = trim ($God);
    
    
    // Set the variables for the database access:
    $Host = "localhost";
    $User = "the-barr";
    $Password = "starwars";
    $DBName = "thebarr_content";
    $TableName = "$Which";
    
    $Link = mysql_connect ($Host, $User, $Password);
    $Query = "INSERT into $TableName values ('0', '$Name', '$Strat', '$God', '$Body')";
    
    $Body = $_POST['Body']; // puts the text into a variable called $body
    $Body = nl2br($Body); // converts line breaks to BR tags
    
    print ("The query is:<BR>$Query<P>\n");
    if (mysql_db_query ($DBName, $Query, $Link)) {
     	print ("The query was successfully executed!<BR>\n");
    } else {
     	print ("The query could not be executed!<BR>\n");
    } 
    mysql_close ($Link);
    ?>
    </BODY>
    </HTML>
    Is that the right spot to put it?
    Last edited by Nick; Aug 20, 2003 at 11:40.

  6. #31
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No:

    As you can see, your INSERT call to your database is called with the unmodified version of $Body. If you want the database to store the $Body with all newlines converted to <br />s, you will need to call the function before inserting it. I'd recommend you adjust your code as follows:

    PHP Code:
    // Trim the incoming data. 
    $Name trim($_POST['Name']); 
    $Strat trim($_POST['Strat']); 
    $Body nl2br(trim($_POST['Body']));  //HERE
    $God trim($_POST['God']); 

    //... rest of code, minus those two red lines 
    My name is Steve, and I'm a super-villian.

  7. #32
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yay, finally, it works!

    You can have my first born.

    No point in making another one of my (multiple) help threads, so I will just ask it here. I am trying to use a drop down select box to select what strat you want to view. It will automatically update itself. THis:

    Code:
    [...]
    
    print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
    print ("<TD ALIGN=CENTER VALIGN=TOP colspan=2>
    <form action=\"egyptian2.php\" method=post>
    <select name=\"Display\" id=\"Display\">
    <option value=$Row[God]>$Row[God]</option>
    </select>
    <input type=\"submit\" name=\"Display\" value=\"Display\">
    </TD>\n");
    print ("</TR>\n");
    print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
    print ("<TD ALIGN=CENTER VALIGN=TOP colspan=2>Egyptian Strategies</TD>\n");
    print ("</TR>\n");
    
    [...]
    I get the box, but no strat names (the strat and god names are switched around for some reason, it seems) appear.

    http://www.the-barracks.com/aom/egyptian2.php

  8. #33
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Possibility
    You can have my first born.
    Eek! Please, no keep him / her yourself. I'm way too young to have children!

    I believe this problem is due to the fact that $Row isn't getting populated (via mysql_fetch_array) -- see updated code:

    PHP Code:
    echo <<<HTML
       <tr align="center" valign="top">
       <td align="center" valign="top" colspan="2">
       <form action="egyptian2.php" method="post">
       <select name="Display" id="Display">
    HTML;

       while(
    $row mysql_fetch_array($result)) {
          echo 
    '<option value="'$row['God'], '">' $row['God'], '</option>';
       }

    echo <<<HTML
       </select>
       <input type="submit" name="Display" value="Display">
       </td>
    </tr>
    <tr align="center" valign="top">
    <td align="center" valign="top" colspan="2">Egyptian Strategies</td>
    </tr>
    HTML; 
    Last edited by lieut_data; Aug 21, 2003 at 07:42.
    My name is Steve, and I'm a super-villian.

  9. #34
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code gave me some parse errors and a couple other, so I changed it a little.

    Code:
    // Create a table.
    print ("<TABLE WIDTH=\"60%\" BORDER=1 BORDERCOLOR=#000000 CELLSPACING=0 CELLPADDING=4 ALIGN=CENTER  class=content>\n");
     	print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
     	print ("<TD ALIGN=left VALIGN=TOP colspan=2>
       <form action=\"egyptian2.php\" method=post> 
       <select name=\"Display\" id=\"Display\"> 
     while($row = mysql_fetch_array($result)) { 
          echo '<option value=\"', $row[God], '\">' , $row[God], '</option>'; 
       } 
       </select> 
       <input type=\"submit\" name=\"Display\" value=\"Display\"> 
    </TD>\n");
    print ("</TR>\n");
    Still, it doesn't display any names.

    Take a look:

    http://www.the-barracks.com/aom/egyptian2.php

    Thanks much for your time.

  10. #35
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Possibility
    That code gave me some parse errors and a couple other, so I changed it a little.
    Unfortunately, that's also what broke it -- if you take a look at your outputted HTML, you'll see that the critical part of the script, the while loop, is outputted as HTML. Try my original code, and show me where the parse errors occur (so we can fix them, and use it instead)
    My name is Steve, and I'm a super-villian.

  11. #36
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok.

    Code:
    Parse error: parse error, expecting `','' or `';'' in /home/the-barr/public_html/aom/egyptian2.php on line 29
    29:

    Code:
    echo <<<HTML
    Some of this I could probably do myself, but sense I haven't had a very good track record I want you to walk me through it :\

  12. #37
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing that line 29 is my first echo <<<HTML statement -- it almost appears that the previous line is missing a semi-colon or other delimeter - could you post the entire code (w/ mine) for analysis?
    My name is Steve, and I'm a super-villian.

  13. #38
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure thing.

    Code:
    <? include("/home/the-barr/public_html/header.php") ?>
    
    <?
    $Host = "localhost";
    $User = "the-barr";
    $Password = "starwars";
    $DBName = "thebarr_content";
    $TableName = "Egypt";
    ?>
    
    
    <?php
    // Set the variables for the database access:
    $Host = "localhost";
    $User = "the-barr";
    $Password = "******";
    $DBName = "thebarr_content";
    $TableName = "Egypt";
    
    $Link = mysql_connect ($Host, $User, $Password);
    
    $Query = "SELECT * from $TableName WHERE(God='$Display')";
    
    $Result = mysql_db_query ($DBName, $Query, $Link);
    
    
    // Create a table.
    print ("<TABLE WIDTH=\"60%\" BORDER=1 BORDERCOLOR=#000000 CELLSPACING=0 CELLPADDING=4 ALIGN=CENTER  class=content>\n");
    echo <<<HTML 
       <tr align="center" valign="top"> 
       <td align="center" valign="top" colspan="2"> 
       <form action="egyptian2.php" method="post"> 
       <select name="Display" id="Display"> 
    HTML; 
    
       while($row = mysql_fetch_array($result)) { 
          echo '<option value="', $row['God'], '">' , $row['God'], '</option>'; 
       } 
    
    echo <<<HTML 
       </select> 
       <input type="submit" name="Display" value="Display"> 
       </td> 
    </tr> 
    <tr align="center" valign="top"> 
    <td align="center" valign="top" colspan="2">Egyptian Strategies</td> 
    </tr> 
    HTML; 
    // Row God and Row Strat are switched around
    while ($Row = mysql_fetch_array ($Result)) {
     	print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
     	print ("<TD ALIGN=left VALIGN=TOP WIDTH=\"50%\"><b>$Row[God]</b> - <i>$Row[Strat]</i></TD>\n");
     	print ("<TD ALIGN=right VALIGN=TOP WIDTH=\"50%\"><i>$Row[Name]</i></TD>\n");
     	print ("</TR>\n");
     	print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
     	print ("<TD ALIGN=left VALIGN=TOP colspan=2>$Row[Body]</TD>\n");
     	print ("</TR>\n");
     	print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
     	print ("<TD ALIGN=center VALIGN=TOP colspan=2>...............</TD>\n");
     	print ("</TR>\n");
    }
    mysql_close ($Link);
    print ("</TABLE>\n");
    ?>
    
    <? include("/home/the-barr/public_html/footer.php") ?>

  14. #39
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Despite my best attempts, I can't find any parse error there -- try removing the heredoc syntax, instead exiting PHP for the HTML:

    PHP Code:
    //... Code above
    ?>

       <tr align="center" valign="top">
       <td align="center" valign="top" colspan="2">
       <form action="egyptian2.php" method="post">
       <select name="Display" id="Display">

    <?php

       
    while($row mysql_fetch_array($result)) {
          echo 
    '<option value="'$row['God'], '">' $row['God'], '</option>';
       }

    ?>
       </select>
       <input type="submit" name="Display" value="Display">
       </td>
    </tr>
    <tr align="center" valign="top">
    <td align="center" valign="top" colspan="2">Egyptian Strategies</td>
    </tr>
    <?php
    //..CODE below
    My name is Steve, and I'm a super-villian.

  15. #40
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, progress! It shows the select box this time, and it goes down far like it has results to show, yet it still doesn't show them...

  16. #41
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check the HTML of that outputted page -- see if in the option statements value="$row['God']" actually contains anything.

    Try removing the select box, and outputting the actual $row['God'] instead, to see if any results are returned.

    Or, even better, inside the while loop:

    PHP Code:
    while (...) {
       
    print_r($row);

    To see exactly what is in that array
    My name is Steve, and I'm a super-villian.

  17. #42
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I was displaying the data on a previous system, I would use $Row[God] (not in a select box, just for setting up the title/information of the text results) and it would display properly. I just looked at the source code, and found this where the select box is (even though this doesn't show up on the page)

    Code:
    <b>Warning</b>:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/home/the-barr/public_html/aom/egyptian2.php</b> on line <b>38</b><br />
    Line 38 is:

    Code:
       while($row = mysql_fetch_array($result)) {
    To put it in context:

    Code:
    <table WIDTH="60%" BORDER=1 BORDERCOLOR=#000000 CELLSPACING=0 CELLPADDING=4 ALIGN=CENTER  class=content>
     
    
       <tr align="center" valign="top"> 
       <td align="center" valign="top" colspan="2"> 
       <form action="egyptian2.php" method="post"> 
       <select name="Display" id="Display"> 
    
    
    <br />
    <b>Warning</b>:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/home/the-barr/public_html/aom/egyptian2.php</b> on line <b>38</b><br />
     
       </select> 
       <input type="submit" name="Display" value="Display"> 
       </td> 
    </tr> 
    <tr align="center" valign="top"> 
    <td align="center" valign="top" colspan="2">Egyptian Strategies</td> 
    </tr> 
    
    </table>

  18. #43
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, so that narrows it down to a failed mysql_call, from:

    PHP Code:
    $Link mysql_connect ($Host$User$Password); 

    $Query "SELECT * from $TableName WHERE(God='$Display')"

    $Result mysql_db_query ($DBName$Query$Link); 
    First, call
    PHP Code:
    // Report All running errors
    error_reporting  (E_ALL); 
    at the top of your script to make sure nothing is missed.

    Then replace that connection code:
    PHP Code:
    $link mysql_connect ($Host$User$Password); 
    mysql_select_db($DBName);
    $sql "SELECT * from $TableName WHERE(God='$Display')"

    echo 
    $sql //Just to make sure Query is formed correctly

    $result mysql_query($sql); 
    My name is Steve, and I'm a super-villian.

  19. #44
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok.

    Code:
    Notice: Undefined Variable:  Display in /home/the-barr/public_html/aom/egyptian2.php on line 18
    Line 18 is:

    Code:
    $Query = "SELECT * from $TableName WHERE(God='$Display')";
    When I replaced the connection code I got this:

    Code:
    Parse error: parse error, expecting `','' or `';'' in /home/the-barr/public_html/aom/egyptian2.php on line 21
    Line 21:

    Code:
    $result = mysql_query($sql);
    I never thought this would be that hard :|

    Just a thought about the undefined variable...Doesn't PHP/MySQL read and execute the page from top to bottom, so when it comes across $Display it doesn't know what to do because $Display isn't defined until later down in the page when you come across the select box...?

  20. #45
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you can drop the WHERE (GOD='$Display') part since the while loop handles the necessary manipulation of that code.

    I'm not positive either why this code keeps crashing on parse errors -- unless I'm just missing something :-)

    There is no other surrounding code, correct (i.e. this is the *whole* script?)
    My name is Steve, and I'm a super-villian.

  21. #46
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will try droping the where part as you said.

    This code section goes through 3 pages basically:

    Form page- enters data
    Handle page - handles data and submits it into DB
    Display page (the page we are working on) - Displays the data (duh)

    There is also a Greek and Norse page, which has the same basic code as the egyptian page, but made to display only data that was entered under either Greek or Norse (on the form page there is a select box which enters the data into either the Egyptian, Greek, or Norse table) Once we get this name select thing up, though, I will just put it on one main page (you should be able to tell what culture it is for my the name)

  22. #47
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there anyother way to accomplish what I am trying to do? I don't really care if it is in a select box. Is there a way to make it display regular text links that will change the WHERE statement when clicked?

  23. #48
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Possibility
    Is there anyother way to accomplish what I am trying to do? I don't really care if it is in a select box. Is there a way to make it display regular text links that will change the WHERE statement when clicked?
    Whoa whoa whoa -- backup there!

    I thought we were *trying* to display a pop-down list of all "gods" in your table. I figured these "gods" formed some sort of navigation structure in which you posted to another page!

    ... did I miss something?

    Perhaps that is why the results all are skewed --

    Ok, to recap -- where are all the "god"s stored, so that we can generate a pop-down list *strictly* from this list?
    My name is Steve, and I'm a super-villian.

  24. #49
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me explain...

    First off, for some reason "God" and "Strat" are switched around. So when I say "God" I am really refering to "Strat", which is the name of the strategy. No big problem there.

    Submit a strat via the form page (submitAoM.php) You have the options of:

    -Author
    -Strat Name
    -Body
    -What Cultre (Greek, Norse, or Egyptian)

    It then goes to HandleForm.php, where it inserts it into the content database, into the table Greek, Norse, or Egyptian (depends on what culture you selected on the form page).

    I then have 3 pages - egyptian.php, greek.php, norse.php Each page calls the strats from their respective tables, displaying them in a neat and orderly fashion. The problem with this system is that it would display ALL strats for that particular culture, and, as we all know, strats can get pretty long. So I wanted to make it only display one strat at a time, being able to select what strat you wish to view via the select menu we are trying to create. Doing this, I would condense all the strats to one display page - I would toss out egyptian.php, greek.php, and norse.php and just make strats.php, where the select box would be shown that lists the names of all the strats in the table, and when clicked would then update the WHERE statement to show WHERE(God='what-you-just-selected') Remember, God and Strat are switched around, so God = Strat name. I would also take the three tables in the content database - egypt, norse, and greek, and make just one table - AoMstrats or something. The form page would be updated to enter data into that table, and the option to select what culture the strat is for would go away, sense it wouldn't matter anymore because you would be selecting strats to vie via their name, not what culture they were for.

    Hope that explains it....

    Oh, and, I was using the egyptian table just for my example, sense there was already data entered in it. Once we got this select form working I was going to do what I said above, make just one strat page and just one strat DB table.

  25. #50
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, so just to recap -- the page we are working on now, egyptian2.php will be replaced by single strats.php page.

    How does this page receive the needed "god" / "strat"? -- via the QUERY_STRING, or by a form submission (i.e. $_POST?) -- we'll need to know how to grab $Display based on the user selection.
    My name is Steve, and I'm a super-villian.


Bookmarks

Posting Permissions

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