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.
Results 1 to 13 of 13
  1. #1
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts

    Not showing more than 1 result

    I am trying to have a select box show multiple records. For my account it should be 3 options total. (1 rune, 2 rune, 3 rune).

    However it will only display 1 rune and nothing else. I think something is wrong with the counting of the records?

    PHP Code:
    $runecheck mysql_query("SELECT fire,water,wind,earth FROM users WHERE id='" $userrow['id'] . "'");

    if (
    $userrow['fire'] == '0') {
              echo 
    '<td>You have no fire runes.</td></tr>';
            }
            else {
              
    $inc 0;
              echo 
    '<td><select name="fire">';
              while (
    $runecheck2 mysql_fetch_array($runecheck))
              {
                
    $inc++;
                echo 
    "<option value=\"".$inc."\">".$inc." Runes</option>";
              }
              echo 
    '</select></td></tr>'
    Last edited by myfayt; 11-10-2010 at 01:47 PM.

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Are you saying that you only get one item in the dropdown or are you saying that you get the same item 3 times in the dropdown?

    Only getting one single item in the dropdown would signify that only one result is returned from the mysql query.

    Conversely, getting the same item three times would signify a problem with the incrementing of $inc (which is unlikely).

    I see no problems with the code that would print the options for the dropdown, so I would assume that your problem is either with your database records or with your query such that you are not receiving all of the results you expected to receive.

    Have you verified your database data to make sure that you actually have the three results you expected?
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    $runecheck = mysql_query("SELECT fire,water,wind,earth FROM users WHERE id='" . $userrow['id'] . "'");
    Please post your table schema and the data present.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    It is only showing 1 drop down option.

    The way it's stored is a smallint 3. The maximum number they can have is 100, and everyone starts with 0.

    So if my number is 3 (I purchased 3 runes), it should list 3 options.

  • #5
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Quote Originally Posted by myfayt View Post
    It is only showing 1 drop down option.

    The way it's stored is a smallint 3. The maximum number they can have is 100, and everyone starts with 0.

    So if my number is 3 (I purchased 3 runes), it should list 3 options.
    So it's still one result, but the result would be the number "3" - is that correct?
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #6
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    No it needs to be like this

    [1 Rune]
    [2 Rune]
    [3 Rune]

    Not

    [1 Rune]
    or
    [3 Rune]

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Are you actually inserting a new row for each rune or just incrementing the count on a single row for how many runes they have? Plus:

    Not showing more than 1 result

  • #8
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    It's a single row. When they purchase runes, it adds to their total count. Such as

    Fire Rune: 2, they purchase 3 more, now their account is Fire Rune: 5.

    So when they go to remove it, there should be a selection box with 5 options.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I think I got you here.
    This here I believe will be your biggest drag down:
    PHP Code:
    while ($runecheck2 mysql_fetch_array($runecheck)) 
    If I understand your structure correctly, with the example of the fire rune than $runecheck2['fire'] would contain the value of 5. The reason why it is one is because you only have one corresponding records in the table `users` matching the userid, which makes sense. What I believe you are looking for is:
    PHP Code:
    $runecheck mysql_query("SELECT fire,water,wind,earth FROM users WHERE id='" $userrow['id'] . "'");
    $runecheck2 mysql_fetch_assoc($runecheck);
    // Now, I debate if the actual query above is necessary.
    // If it matches the results in $userrow['fire'], ['water'], etc, than the query is not necessary.
    if ($userrow['fire'] == '0') {
        echo 
    '<td>You have no fire runes.</td></tr>';
    }
    else
    {
        echo 
    '<td><select name="fire">';
        for (
    $i 1$i <= $runecheck2['fire']; ++$i)
        {
            echo 
    "<option value=\"".$inc."\">".$inc." Runes</option>";
        }
        echo 
    '</select></td></tr>';

    Now this would result in:
    Code:
    <td><select name="fire">
    <option value="1">1 Runes</option>
    <option value="2">2 Runes</option>
    <option value="3">3 Runes</option>
    <option value="4">4 Runes</option>
    <option value="5">5 Runes</option>
    </select></td></tr>
    Is that what you are looking to do? As mentioned in the comments, I'm not sure if the query is necessary. If the $userrow array contains the same data, than you can just loop up to the $userrow record instead.

    Edit:
    Sorry sorry my bad, I modified the loop to go from 1 - 5, not from 0 - 4
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    With your code changes Fou-Lu, (you've ditched $inc?), the following:

    Code:
    echo "<option value=\"".$inc."\">".$inc." Runes</option>";
    should be:

    Code:
    echo "<option value=\"".$i."\">".$i." Runes</option>";

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by MattF View Post
    With your code changes Fou-Lu, (you've ditched $inc?), the following:

    Code:
    echo "<option value=\"".$inc."\">".$inc." Runes</option>";
    should be:

    Code:
    echo "<option value=\"".$i."\">".$i." Runes</option>";
    O.o
    Yeah my bad I guess that a lot of null's would be up otherwise eh
    Guess thats what I get for copying and pasting lol.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    myfayt (11-10-2010)

  • #12
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Thanks Fou! you are the guru of this forum. This was driving me nuts for a couple days. *high five*

    @Matt, thanks for pointing out the variable name mistake.

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by myfayt View Post
    Thanks Fou! you are the guru of this forum. This was driving me nuts for a couple days. *high five*

    @Matt, thanks for pointing out the variable name mistake.
    You bet! Always glad to help, even though I'm so super swamped at work right now O.o.
    Lol, it cuts into my browsing time
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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