Jump to content
MakeWebGames

Need help with award feature


Miks

Recommended Posts

Thanks but when I changed it to your suggestion it then added the award and every time I loaded the page it would duplicate on the screen and the database

So first visit it added one award and displayed 1 award, the second time it would display two awards and add the award twice, then 4 times and then 8 times etc

KEEP THE WHILE!

Told you before, you need to look into If Else statements properly.

The code you have is saying that if the user is below level 9 and have the award tell the they have the award. If not, if they are level 10 give them the award. You haven't told it to check again whether or not they have the award.

Change your first if statement to this:

if ( $a['awardno'] == 2)

 

Now your code is saying, if they have the award, tell them they have it, if not, are they level 10 or higher? If yes then give them the award

$i=$db->query("SELECT `awardno` FROM `uawards` WHERE userid={$userid}");

while($a = $db->fetch_row($i))
{
if ($a['awardno'] == 2)
{
echo "You have the award already";
die($h->endpage());
}
else if ($ir['level'] >= 10)
{
$db->query("INSERT INTO `uawards` (`id`, `userid`, `awardno`) VALUES ('',{$userid}, '2')");
   echo "
<div class='desc2'>
<div class='citstat'>
<table class='mytable'><tr><td><center>
<font color='green'>Congratulations!</font> you have earned an award!<img src='https://cdn4.iconfinder.com/data/icons/pc_de_hamburg_icon_pack/32x32/bestseller.png'>You have reached level 10</center></td></tr></table></div></div>
"; 

}
}
Edited by Coly010
Link to comment
Share on other sites

Apparently I need the white statement

The feature adds an award to an award Table, it checks to see if the user has the award, if they dont it goes onto the else statement and adds it. The problem I am having is everytime you refresh the page it keeps adding the award.

I must point out that this is for Award number 2,3,4+ etc Award 1 doesnt repeat itself. So the select and fetch section is only looking at one row i.e Award 1 even though award 2 is in the table as well. So I need help getting the result to query the whole table and not just 1 row.....if that makes sense

Link to comment
Share on other sites

Apparently I need the white statement

The feature adds an award to an award Table, it checks to see if the user has the award, if they dont it goes onto the else statement and adds it. The problem I am having is everytime you refresh the page it keeps adding the award.

I must point out that this is for Award number 2,3,4+ etc Award 1 doesnt repeat itself. So the select and fetch section is only looking at one row i.e Award 1 even though award 2 is in the table as well. So I need help getting the result to query the whole table and not just 1 row.....if that makes sense

Check my post, the code at the bottom will work

Link to comment
Share on other sites

Why exactly would he need the while? I don't really see any use for it there. I use while statements for running through adding something into a database for multiple entries. Now looking better at the code I'd do it something like this:

 

$i=$db->query("SELECT `awardno` FROM `uawards` WHERE awardno=2 userid={$userid}");
if($db->num_rows($i) > 0) {
$a = $db->fetch_row($i);
echo "You have the award already";
die($h->endpage());
} else if($db->num_rows($i) == 0 && $ir['level'] >= 10) {
$db->query("INSERT INTO `uawards` (`id`, `userid`, `awardno`) VALUES ('',{$userid}, '2')");
   echo "
<div class='desc2'>
<div class='citstat'>
<table class='mytable'><tr><td><center>
<font color='green'>Congratulations!</font> you have earned an award!<img src='https://cdn4.iconfinder.com/data/icons/pc_de_hamburg_icon_pack/32x32/bestseller.png'>You have reached level 10</center></td></tr></table></div></div>
"; 

}
Link to comment
Share on other sites

Why exactly would he need the while? I don't really see any use for it there. I use while statements for running through adding something into a database for multiple entries. Now looking better at the code I'd do it something like this:

 

$i=$db->query("SELECT `awardno` FROM `uawards` WHERE awardno=2 userid={$userid}");
if($db->num_rows($i) > 0) {
$a = $db->fetch_row($i);
echo "You have the award already";
die($h->endpage());
} else if($db->num_rows($i) == 0 && $ir['level'] >= 10) {
$db->query("INSERT INTO `uawards` (`id`, `userid`, `awardno`) VALUES ('',{$userid}, '2')");
   echo "
<div class='desc2'>
<div class='citstat'>
<table class='mytable'><tr><td><center>
<font color='green'>Congratulations!</font> you have earned an award!<img src='https://cdn4.iconfinder.com/data/icons/pc_de_hamburg_icon_pack/32x32/bestseller.png'>You have reached level 10</center></td></tr></table></div></div>
"; 

}

He needed the while loop because in his where clause he wasn't specifiying which award no he was looking for, I didn't realise your code was

Link to comment
Share on other sites

Try this im not 100% sure it will work but try it

$i=$db->query("SELECT * FROM `uawards` WHERE userid={$userid}");
$a=$db->fetch_row($i);
if ($a['awardno'] == 1 && $ir['level'] >= 5)
{
exit("You have the award");
}
else if ($a['awardno'] !== 1 || $a['awardno']  > 1 && $ir['level'] >= 5)
{
$db->query("INSERT INTO `uawards` (`id`, `userid`, `awardno`) VALUES ('',{$userid}, '1')");
   exit("
<div class='desc2'>
<div class='citstat'>
<table class='mytable'><tr><td><center>
<font color='green'>Congratulations!</font> you have earned an award!<img src='https://cdn4.iconfinder.com/data/icons/pc_de_hamburg_icon_pack/32x32/bestseller.png'>You have reached level 10</center></td></tr></table></div></div>
"); 
} else {
exit("Error");
}
if ($a['awardno'] == 2 && $ir['level'] > 10)
{
exit("You have the award");
}
else if ($a['awardno'] !==2 || $a['awardno'] > 2 && $ir['level'] >= 10)
{
$db->query("INSERT INTO `uawards` (`id`, `userid`, `awardno`) VALUES ('',{$userid}, '2')");
exit("
<div class='desc2'>
<div class='citstat'>
<table class='mytable'><tr><td><center>
<font color='green'>Congratulations!</font> you have earned an award!<img src='https://cdn4.iconfinder.com/data/icons/pc_de_hamburg_icon_pack/32x32/bestseller.png'>You have reached level 10</center></td></tr></table></div></div>
"); 
} else {
exit("Error");
}

Theres another way of doing all this but it requires you to make a new table which inserts the awards id in this case

$a['awardno']

we the use mysql_num_rows to check if the row exists its more secure and safer

Edited by jcvenom
Link to comment
Share on other sites

Try this im not 100% sure it will work but try it
$i=$db->query("SELECT * FROM `uawards` WHERE userid={$userid}");
$a=$db->fetch_row($i);
if ($a['awardno'] == 1 && $ir['level'] >= 5)
{
exit("You have the award");
}
else if ($a['awardno'] !== 1 || $a['awardno']  > 1 && $ir['level'] >= 5)
{
$db->query("INSERT INTO `uawards` (`id`, `userid`, `awardno`) VALUES ('',{$userid}, '1')");
   exit("
<div class='desc2'>
<div class='citstat'>
<table class='mytable'><tr><td><center>
<font color='green'>Congratulations!</font> you have earned an award!<img src='https://cdn4.iconfinder.com/data/icons/pc_de_hamburg_icon_pack/32x32/bestseller.png'>You have reached level 10</center></td></tr></table></div></div>
"); 
} else {
exit("Error");
}
if ($a['awardno'] == 2 && $ir['level'] > 10)
{
exit("You have the award");
}
else if ($a['awardno'] !==2 || $a['awardno'] > 2 && $ir['level'] >= 10)
{
$db->query("INSERT INTO `uawards` (`id`, `userid`, `awardno`) VALUES ('',{$userid}, '2')");
exit("
<div class='desc2'>
<div class='citstat'>
<table class='mytable'><tr><td><center>
<font color='green'>Congratulations!</font> you have earned an award!<img src='https://cdn4.iconfinder.com/data/icons/pc_de_hamburg_icon_pack/32x32/bestseller.png'>You have reached level 10</center></td></tr></table></div></div>
"); 
} else {
exit("Error");
}

Theres another way of doing all this but it requires you to make a new table which inserts the awards id in this case

$a['awardno']

we the use mysql_num_rows to check if the row exists its more secure and safer

Again, this won't work because you haven't either specified the awardno in the SQL statement or looped through the multiple rows retrieved from the database

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...