Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Senior Member
    Join Date
    Apr 2005
    Location
    Hatfield, England
    Posts
    855
    Member #
    9790
    This is rather strange, i have an edit form, every field works apart from the field i just added. This is a loop to show the people playing and their scores. When i change from one report to another the results are still the same, as the results don't change they are obviously incorrect... i don't see how this can be as everything else changes apart from this.

    Main function
    PHP Code:
    function displayOneItem($scoreid) {
        global 
    $dbc$adminaccess;
            
    $query "SELECT * FROM matchreports WHERE scoreid=$scoreid";
            
    $result mysql_query ($query);
                    
            
    /* if we get no results back, error out */
            
    if (mysql_num_rows ($result) == 0) {
                echo 
    "Invalid News ID\n";
                return;
            }
            
    $row mysql_fetch_assoc($result);
            include 
    'matchvariables.inc';
            echo 
    "<FORM action=\"{$_SERVER['PHP_SELF']}"?action=edit&scoreid=$scoreid\" method=POST>\n";
            include 
    'matchform2.inc';

    Match Variables
    PHP Code:
    $pn = ($row['player_number']);
    $pn1 = ($row['player1']);
    $pn2 = ($row['player2']);
    $pn3 = ($row['player3']);
    $ps1 = ($row['score1']);
    $ps2 = ($row['score2']);
    $ps3 = ($row['score3']); 
    Loop in matchform2
    PHP Code:
    <? 
    for ($i=0;$i<$pn;$i++) { 
        echo 
    '<input type="text" name="player'.($i+1).'" size="30" maxlength="50" value="'.$pn.($i+1).'" />';
        echo 
    '<input type="text" name="playerscore'.($i+1).'" size="3" maxlength="3" value="'.$ps.($i+1).'" />';

        
    ?>
    Does anyone have any ideas as to why this is happening? Unfortunately the website is being built on my laptop so i can't show you a working example of the problem.

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Have you displayed the query that has just been executed? Do that and run it through a database utility (maybe your database engine itself as your on localhost).

    Does the query return what it should? If so, then we can shift our focus to a more specific part of your code.

  4. #3
    Senior Member
    Join Date
    Apr 2005
    Location
    Hatfield, England
    Posts
    855
    Member #
    9790
    If i echo $pn1,2 and $ps1,2 above the included match form the numbers all display correctly. The query is fine and the variables are fine.

  5. #4
    Senior Member raspberryh's Avatar
    Join Date
    Aug 2004
    Location
    Erie, PA
    Posts
    882
    Member #
    7208
    Liked
    1 times
    Hey,
    I think it's because you're concatenating the value in $pn with the value $i+1, whereas what you WANT to display is $pn1 if i is 0, and $pn2 if i is 1, right?
    I think that you can do something like ${"pn".$i} or also try ${pn.$i} as I think I've seen it that way too.
    Heather
    choosy developers choose gif!
    website | paintings | blog

  6. #5
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Or probably even [minicode]eval( "pn$i" );[/minicode]. The one above that has no double-quotes is probably dangerous and may well run into issues if `pn' has been [minicode]define()[/minicode]d.

  7. #6
    Senior Member
    Join Date
    Apr 2005
    Location
    Hatfield, England
    Posts
    855
    Member #
    9790
    I found a way around it this afternoon. I put all my variables in 2 arrays and used the array to call it out. It then worked. I still don't know why the above worked though. Ah well.

  8. #7
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,733
    Member #
    5580
    Liked
    718 times
    Perad ...

    I'm the same way .... if I can get it to work, any way I can ... great!
    People only see the results, not my script (I'm glad for that).


  9. #8
    Senior Member
    Join Date
    Apr 2005
    Location
    Hatfield, England
    Posts
    855
    Member #
    9790
    lol, i am not to ashamed of my finished article. For those interested...

    Variables
    PHP Code:
    $pn = array();
    for (
    $i=1;$i<25;$i++) {
        
    $pn[$i] = $row['player' $i];
    }

    $ps = array();
    for (
    $i=1;$i<25;$i++) {
        
    $ps[$i] = $row['score' $i];

    Match form
    PHP Code:
    <? 
    for ($i=0;$i<$playern;$i++) { 
        echo 
    '<input type="text" name="playername[]" size="30" maxlength="50" value="'.$pn[$i+1].'" />';
        echo 
    '<input type="text" name="playerscore[]" size="3" maxlength="5" value="'.$ps[$i+1].'" /><br />';

    ?>
    The other script is unchanged


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:16 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com