...

View Full Version : Resolved Not showing more than 1 result



myfayt
11-09-2010, 02:27 PM
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?


$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>';

Rowsdower!
11-09-2010, 02:54 PM
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?

abduraooft
11-09-2010, 02:59 PM
$runecheck = mysql_query("SELECT fire,water,wind,earth FROM users WHERE id='" . $userrow['id'] . "'"); Please post your table schema and the data present.

myfayt
11-09-2010, 06:48 PM
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.

Rowsdower!
11-09-2010, 07:36 PM
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?

myfayt
11-10-2010, 12:26 AM
No it needs to be like this

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

Not

[1 Rune]
or
[3 Rune]

MattF
11-10-2010, 01:02 AM
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:

http://codingforums.com/showpost.php?p=1013240&postcount=3

myfayt
11-10-2010, 03:06 AM
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.

Fou-Lu
11-10-2010, 03:26 AM
I think I got you here.
This here I believe will be your biggest drag down:


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:


$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:


<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.


Sorry sorry my bad, I modified the loop to go from 1 - 5, not from 0 - 4

MattF
11-10-2010, 05:14 AM
With your code changes Fou-Lu, (you've ditched $inc?), the following:



echo "<option value=\"".$inc."\">".$inc." Runes</option>";


should be:



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

Fou-Lu
11-10-2010, 02:37 PM
With your code changes Fou-Lu, (you've ditched $inc?), the following:



echo "<option value=\"".$inc."\">".$inc." Runes</option>";


should be:



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.

myfayt
11-10-2010, 02:46 PM
Thanks Fou! you are the guru of this forum. :D This was driving me nuts for a couple days. *high five*

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

Fou-Lu
11-10-2010, 07:24 PM
Thanks Fou! you are the guru of this forum. :D 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 :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum