SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 71 of 71

Thread: Line Breaks

  1. #51
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Form page. Here is the form (submimtAoM.php):

    Code:
    <body bgcolor="#777777">
    <table width="75%" align=center border=1 bordercolor=#000000 style="border-collapse: collapse;" cellpadding=5>
    <form action="HandleForm.php" method=post>
    <tr>
    <td colspan=2>
    Submit a strategy for AoM.</td></tr>
    <tr><td colspan=2 align=left>
    <select name="Which" id="which" tabindex="5">  
             <option value="Egypt">Egyptian</option>         
             <option value="Greek">Greek</option> 
             <option value="Norse">Norse</option> 
           </select>
    </td></tr>
    <tr>
    <td>
    Submitted By:</td><td> <input type=text name="Name" size=30></td></tr>
    <tr><td>Strat Name:</td><td> <input type=text name="Strat" size=30></td></tr>
    <tr><td>Strategy: </td><td><textarea name="Body" rows=7 cols=50></text></td></tr>
    <tr><td colspan=2>
    God: <select name="God" id="rate" tabindex="5">  
             <option value="All Gods">All Gods (for one culture)</option>         
             <option value="Isis">Isis</option> 
             <option value="Ra">Ra</option> 
             <option value="Set">Set</option> 
             <option value="Hades">Hades</option> 
             <option value="Poseidon">Poseidon</option> 
             <option value="Zeus">Zeus</option> 
             <option value="Loki">Loki</option> 
             <option value="Odin">Odin</option> 
             <option value="Thor">Thor</option> 
           </select>
    </td></tr>
    <tr><td colspan=2 align=right>
    <input type=submit name="submit" value="submit!"></td></tr>
    </form>
    </table>
    
    
    </body>
    That is what it is now, actually. As I said I was putting it all into just one page now, the culture and god selection will be deleted, so it will looking something like this:

    Code:
    <body bgcolor="#777777">
    <table width="75%" align=center border=1 bordercolor=#000000 style="border-collapse: collapse;" cellpadding=5>
    <form action="HandleForm.php" method=post>
    <tr>
    <td>
    Submitted By:</td><td> <input type=text name="Name" size=30></td></tr>
    <tr><td>Strat Name:</td><td> <input type=text name="Strat" size=30></td></tr>
    <tr><td>Strategy: </td><td><textarea name="Body" rows=7 cols=50></text></td></tr>
    <tr><td colspan=2 align=right>
    <input type=submit name="submit" value="submit!"></td></tr>
    </form>
    </table>
    
    
    </body>
    Not sure if you need the rest, but i'll post it anyways in the interest of time.

    The data then goes to HandleForm.php:

    Code:
    <BODY>
    <?php
    /* This page receives and handles the data generated by "form.html". */
    // Trim the incoming data.
    $Name = trim($_POST['Name']); 
    $Strat = trim($_POST['Strat']); 
    $Body = nl2br(trim($_POST['Body'])); 
    
    
    // Set the variables for the database access:
    $Host = "localhost";
    $User = "the-barr";
    $Password = "pass";
    $DBName = "thebarr_content";
    $TableName = "AoMstrats";
    
    $Link = mysql_connect ($Host, $User, $Password);
    $Query = "INSERT into $TableName values ('0', '$Name', '$Strat', '$Body')";
    
    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>
    Then the next step is the display page, which will be strats.php (it was/is egyptian2.php right now, but that was just for egyptian strats)

  2. #52
    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 think my problem is just that I've completely missed the aim of the project -- I'll let it rest for tonight, and see if I can offer and further "sound" advice tomorrow :-)
    My name is Steve, and I'm a super-villian.

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

    And, like I said, I don't need a select box, anyway of selecting the strat name then displaying it would be fine, as long as it does what I need. Select box would be fine, though.

  4. #54
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have now one table - AoMstrats - and one page -strats2.php (will be changed to strats.php but the other one is in use right now) So now all data for all gods go into that one table.

    Let's see if we can get this working

    Here is the source of strats2.php

    Code:
    <? include("/home/the-barr/public_html/header.php") ?>
    
    <?php
    $Display = $_POST['Display'];
    $Where =  ($Display=="all" ) ? "" : "where(Who='$Display')";
    // Set the variables for the database access:
    $Host = "localhost";
    $User = "the-barr";
    $Password = "starwars";
    $DBName = "thebarr_content";
    $TableName = "AoMstrats";
    
    $Link = mysql_connect ($Host, $User, $Password);
    
    $Query = "SELECT * from $TableName $Where";
    
    $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");
    ?> 
    
       <tr align="center" valign="top"> 
       <td align="center" valign="top" colspan="2"> 
       <form action="strats2.php" method="post"> 
       <select name="Display" id="Display"> 
    
    <?php 
    
    while ($Row = mysql_fetch_array ($Result)) {
          print ("<option value='$Row[Who]'>'$Row[Who]'</option>"); 
       } 
    
    ?> 
       </select> 
       <input type="submit" name="Display" value="Display"> 
       </td> 
    </tr> 
    <?php
    print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
    print ("<TD ALIGN=CENTER VALIGN=TOP colspan=2>Age of Mythology Strategies</TD>\n");
    print ("</TR>\n");
    
    // 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[Who]</b> -<i> $Row[Strat]</i></TD>\n");
     	print ("<TD ALIGN=right VALIGN=TOP WIDTH=\"50%\"><i>$Row[Author]</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") ?>
    *racks head*

    Now why won't that display box display properly...

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

    EDIT: I tried putting a regular name in the option box, using

    Code:
          print ("<option value=\"Testing\">\"Testing\"</option>");
    And that doesn't even show up...
    Last edited by Nick; Aug 22, 2003 at 05:35.

  5. #55
    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, the first problem is that the code has two instances of $Row = mysql_fetch_array ($Result)

    The first one will grab all the results, and the second won't have anything (we'll fix that in a moment)

    However, the first instance isn't outputting anything either.

    Insert a:
    echo "Number of Rows: ", mysql_num_rows($Result);

    just after $Result = mysql_db_query ($DBName, $Query, $Link);

    PHP Code:
    //... snip
    $Result mysql_db_query ($DBName$Query$Link);

    echo 
    "Number of Rows: "mysql_num_rows($Result);
    //... snip 
    My name is Steve, and I'm a super-villian.

  6. #56
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Done:

    Number of Rows: 0

  7. #57
    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, I presume if we add a :

    PHP Code:
    echo $Query
    Just before that, you should see an output:

    Code:
    SELECT * from AoMStrats
    Am I correct?
    My name is Steve, and I'm a super-villian.

  8. #58
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It says

    Code:
    SELECT * from AoMstrats WHERE(Who=")

  9. #59
    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)
    Ahh, ok -- so the reason there are no results is because there are no rows where Who=''.

    I'd change the following code :

    PHP Code:
    $Display $_POST['Display']; 
    $Where = ($Display=="all" ) ? "" "where(Who='$Display')"
    To:

    PHP Code:
    $Where = isset($_POST['Display']) ? "" " WHERE (Who='{$_POST['Display']}')"
    This should now adjust your query, if no $Display is passed (i.e. form not yet submitted), then all rows are displayed. Otherwise, it tries to match $Display from the POSTed value, and limits the preview to that.

    See if it makes any difference in mysql_num_rows, and your pop-down box
    My name is Steve, and I'm a super-villian.

  10. #60
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At first it says the same thing, but if you click the submit button it then goes to
    Code:
    SELECT * from AoMstrats Number of Rows:1
    and has

    Code:
    "Testing"
    In the select box, but clicking on it does nothing.

    Might want to check it out for yourself:

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

    Maybe it is because "Testing" has the quotes around it, and the strat name in the DB is just Testing, with no quotes...

  11. #61
    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, adjust that single-where liner, to:

    PHP Code:
     $Where = isset($_POST['Display'] && !empty($_POST['Display']) ? "" " WHERE (Who='{$_POST['Display']}')"
    What are the current contents of the AoMStrats table?
    My name is Steve, and I'm a super-villian.

  12. #62
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That gave me a parse error.

    AoMstrats has currently one item in it, - Testing - with a couple lines of Body.

    I can add a couple more if you think that would be helpful.

  13. #63
    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, sorry:
    PHP Code:
    $Where = (isset($_POST['Display']) && !empty($_POST['Display'])) ? "" " WHERE (Who='{$_POST['Display']}')"
    Shouldn't AoMStrats have all the Gods in it, so we can build the dropdown? Since 'testing' is all that is in there, that is all we are getting as a result.
    My name is Steve, and I'm a super-villian.

  14. #64
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put the new code in, the same things happen. At first, nothing shows up, once you click display than "Testing" shows up and Number of Rows = 1.

    Shouldn't AoMStrats have all the Gods in it, so we can build the dropdown? Since 'testing' is all that is in there, that is all we are getting as a result.
    First, as now it is Who and Strat, and, as it always seems to be the case, Who really is Strat name.

    Umm, I don't think I get what you are saying. Since I have decided to do this drop down menu, the results are no longer sorted by what God they are for, only by names. The form page no longer has an entry field for what god/culture. So yes, AoMstrats contains strats for Greek, Norse, and Egyptian.

    My table structure looks like this:

    id (primary)
    Author
    Strat
    Who
    Body

    Who = strat (name)

    strat is actually what god it is for, but the only thing I am using that for is displaying it with the Body how the user can tell, it will not be used for sorting.

  15. #65
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aha, I forgot I still had - Testing - in the option value. I changed it back to the variable and took away the ' ' and it seems to of made progress now. It still has the problem of not displaying any names at first untill you hit display once, and, of course, it still doesn't display the strat even if you have selected the name. But we are getting close!

    EDIT: I just submitted another one in the DB, and it shows up in the select box, also.

  16. #66
    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)
    The key to getting the combo box to show its content on the first page load is to make sure that the where statement isn't getting set if nothing is passed:

    Try this:
    PHP Code:
    $Where 
       (
        isset(
    $_POST['Display']) 
       && 
        !empty(
    trim($_POST['Display']))
       ) 
       ? 
    "" " WHERE (Who='{$_POST['Display']}') "
    Let's see if that makes an effect.

    Also, why is it that if the user selects a certain value, that we need to show fewer elements in the combo box? Doesn't the dropdown box stay constant throughout the script?
    My name is Steve, and I'm a super-villian.

  17. #67
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, why is it that if the user selects a certain value, that we need to show fewer elements in the combo box? Doesn't the dropdown box stay constant throughout the script?
    Yes... Were you refering to me edit? That was a good thing.


    I replaced
    Code:
    $Where = (isset($_POST['Display']) && !empty($_POST['Display'])) ? "" : " WHERE (Who='{$_POST['Display']}')";
    with what you just said and got back

    Code:
    Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /home/the-barr/public_html/aom/strats2.php on line 8
    Line 8:

    Code:
        !empty(trim($_POST['Display']))

  18. #68
    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)
    Huh? No trim() functionality?... must be an older version of PHP!

    However, if the combobox is to remain the same, we need to drop the $Where functionality entirely. We want that query to return *all* the values from AoMStrats, do we not? Doesn't that return all the 'gods' / strats for the dropdown box?

    You'll have to forgive me for my confusion -- it's not difficult to understand code, but often what the code is *trying* to do
    My name is Steve, and I'm a super-villian.

  19. #69
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe, yes, you are confusing me.

    My PHP verison is 4.3.2

    The select box is not to remain the same, at least not in the sense that I think you are thinking of. It should be updated everytime a new strategy is added to the DB.

    Ex.

    I have two strats in the DB - Strat1 and Strat2 - I go to the submitAoM.php page and enter Strat3. I now go back to the display page, and the select box now shows Strat1, Strat2, and Strat3. Selecting anyone of those will then display the respective strat (thus the WHERE statement).


    We want that query to return *all* the values from AoMStrats, do we not?
    We want it to return all [Who] values. Then selecting a [Who] (remember, really a strat name) will then display the rest of the appriopate information in the tables beneath (Author, Strat name, and Body)

    Did I clear it up or just make you more confused?

  20. #70
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it is a problem with the rest of my code, not the select box.

    I changed the line to:

    Code:
    $Query = "SELECT * from $TableName where(Who='Testing');
    and took away the $Where statement, and it still doesn't display anything.

  21. #71
    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 have to have a select box, if there is a way to make it output plane text that will change the WHERE statement when clicked...


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
  •