Page 1 of 1

Query Issue

Posted: Tue Dec 28, 2010 11:16 pm
by rapid3642
Hey Guys i am having a problem with a Query.

What happens is that when my quest is queried and displayed it only focuses on the first quest displayed i am assuming its just looking at the first query.

Here is an example The first quest i did i already completed so thats right, but now the next quest i have accepted it and yet it does not say in progress with no link. Instead it displays visit and then the user can get the quest over and over again. The image is uploaded below.

Here is the code. (Btw the way if anyone has a better suggestion on setting up a quest system please let me know.)

Code: Select all

 $selectpquest="SELECT * from playerquests where pid='$userid'";
      $selectpquest2=mysql_query($selectpquest) or die("Could not select player quest.");
	  $selectpquest3 = mysql_fetch_array($selectpquest2);
	  
	  $select1inventory="SELECT COUNT(name) from playerinventory where pid = '$userid' AND name='$selectpquest3[req1]'";
      $select1inventory2=mysql_query($select1inventory) or die("Could not retrieve inventory Count.");
	  $select1inventory3=mysql_fetch_array($select1inventory2);
	  
	  $select2inventory="SELECT COUNT(name) from playerinventory where pid = '$userid' AND name='$selectpquest3[req2]'";
      $select2inventory2=mysql_query($select2inventory) or die("Could not retrieve inventory Count.");
	  $select2inventory3=mysql_fetch_array($select2inventory2);
	  
	  $select3inventory="SELECT COUNT(name) from playerinventory where pid = '$userid' AND name='$selectpquest3[req3]'";
      $select3inventory2=mysql_query($select3inventory) or die("Could not retrieve inventory Count.");
	  $select3inventory3=mysql_fetch_array($select3inventory2);
	  
	  $select4inventory="SELECT COUNT(name) from playerinventory where pid = '$userid' AND name='$selectpquest3[req4]'";
      $select4inventory2=mysql_query($select4inventory) or die("Could not retrieve inventory Count.");
	  $select4inventory3=mysql_fetch_array($select4inventory2);
	  
   print "<center><h3>Availabe Quests In Town</h3></center>";
      print "<center>";
      print "<table border='0' width='70%' cellspacing='20'>";
      print "<tr><td width='25%' valign='top'>";
      print "</td>";
      print "<td valign='top' width='75%'>";
      $selectquest="SELECT * from quests";
      $selectquest2=mysql_query($selectquest) or die("Could not select quest.");
      print "<table border='1' bordercolor='white' bgcolor='#FFFFFF' >";
      print "<tr><td><img src='Images/Name_Text.gif'></td><td>
	  <img src='Images/Status_Text.gif'></td></tr>";
     while($selectquest3 = mysql_fetch_array($selectquest2))
{
	
	print "<tr><td>$selectquest3[name]</td>";
	$counter = 1;
	
	if ($selectquest3[name] !== $selectpquest3[name])
	{
	print "<td><center><a href = 'Home.php?type=q&id=$selectquest3[id]'><img src='Images/Visit_Button.gif'></a></center></td></tr>";
	$counter = 1;
	}
	
	if ($selectpquest3[name] == $selectquest3[name] && $selectpquest3[completed] == no && id == $selectquest3[id])
	{
	print "<td><center><img src='Images/In_Progress_Text.gif'></center>";
			if ($select1inventory3['COUNT(name)'] >= $selectquest3['req1amount'] && $select2inventory3['COUNT(name)'] >= $selectquest3['req2amount'] && $select3inventory3['COUNT(name)'] >= $selectquest3['req3amount'] && $select4inventory3['COUNT(name)'] >= $selectquest3['req4amount'])
	{
	print "<br><center><a href = 'Home.php?type=eq&id=$selectquest3[id]'><img src='Images/Finish_Button.gif'></a></center>";
	}
	print "</td></tr>";
	$counter = 1;
	}

	if ($selectpquest3[name] == $selectquest3[name] && $selectpquest3[completed] == yes)
	{
	print "
	<td><img src='Images/Completed_Text.gif'></td></tr>";
	$counter = 1;
	}
}

Re: Query Issue

Posted: Thu Dec 30, 2010 10:42 pm
by rapid3642
ok so basically there are 2 quests showing. one of them i completed. and its working normally there but the second quest i accepted and should be showing "in progress" instead of visit. What im thinking is the query thats set up is only affecting the first quest but it wont affect anything else its only looking at the first quest i don't know why but it seems like the script only works for the first quest and any other quests added it wont affect. i think its how its getting queried or how it is set up to be displayed to the end user.

Does anyone have any ideas on what i need to change?

Re: Query Issue

Posted: Thu Dec 30, 2010 11:21 pm
by alexander19
I've noticed that you forgot a lot of quotes there...:

Code: Select all

 if ($selectquest3[name] !== $selectpquest3[name])
should have been:

Code: Select all

 if ($selectquest3['name'] !== $selectpquest3['name'])
and:

Code: Select all

   if ($selectpquest3[name] == $selectquest3[name] && $selectpquest3[completed] == no && id == $selectquest3[id])
should be:

Code: Select all

   if ($selectpquest3['name'] == $selectquest3['name'] && $selectpquest3['completed'] == no && id == $selectquest3['id'])
and:

Code: Select all

   if ($selectpquest3[name] == $selectquest3[name] && $selectpquest3[completed] == yes)
same for it:

Code: Select all

   if ($selectpquest3['name'] == $selectquest3['name'] && $selectpquest3['completed'] == yes)

Re: Query Issue

Posted: Fri Dec 31, 2010 1:02 am
by rapid3642
yea i didn't think it would matter but you could be right.

I insert what i needed and still nothing :/ i dont knw why the query is only affecting the first quest

Re: Query Issue

Posted: Fri Dec 31, 2010 8:52 am
by alexander19
Did some changes,and removed the table for now...but if it works you can add it back.

Code: Select all

  $selectpquest="SELECT * from playerquests where pid='$userid'";
          $selectpquest2=mysql_query($selectpquest) or die("Could not select player quest.");
         $selectpquest3 = mysql_fetch_array($selectpquest2);
        
         $select1inventory="SELECT COUNT(name) from playerinventory where pid = '$userid' AND name='$selectpquest3[req1]'";
          $select1inventory2=mysql_query($select1inventory) or die("Could not retrieve inventory Count.");
         $select1inventory3=mysql_fetch_array($select1inventory2);
        
         $select2inventory="SELECT COUNT(name) from playerinventory where pid = '$userid' AND name='$selectpquest3[req2]'";
          $select2inventory2=mysql_query($select2inventory) or die("Could not retrieve inventory Count.");
         $select2inventory3=mysql_fetch_array($select2inventory2);
        
         $select3inventory="SELECT COUNT(name) from playerinventory where pid = '$userid' AND name='$selectpquest3[req3]'";
          $select3inventory2=mysql_query($select3inventory) or die("Could not retrieve inventory Count.");
         $select3inventory3=mysql_fetch_array($select3inventory2);
        
         $select4inventory="SELECT COUNT(name) from playerinventory where pid = '$userid' AND name='$selectpquest3[req4]'";
          $select4inventory2=mysql_query($select4inventory) or die("Could not retrieve inventory Count.");
         $select4inventory3=mysql_fetch_array($select4inventory2);
        
    
          $selectquest="SELECT * from quests";
          $selectquest2=mysql_query($selectquest) or die("Could not select quest.");
         while($selectquest3 = mysql_fetch_array($selectquest2))
    {
       
       print $selectquest3['name'];
       
       if ($selectquest3['name]' !== $selectpquest3['name'])
       {
       print "<center><a href = 'Home.php?type=q&id=$selectquest3[id]'><img src='Images/Visit_Button.gif'></a></center><br>";
       }
       elseif ($selectpquest3['name'] == $selectquest3['name'] && $selectpquest3['completed'] == 'no')
       {
       print "<center><img src='Images/In_Progress_Text.gif'></center><br>";
       elseif ($select1inventory3['COUNT(name)'] >= $selectquest3['req1amount'] && $select2inventory3['COUNT(name)'] >= $selectquest3['req2amount'] && $select3inventory3['COUNT(name)'] >= $selectquest3['req3amount'] && $select4inventory3['COUNT(name)'] >= $selectquest3['req4amount'])
       {
       print "<br><center><a href = 'Home.php?type=eq&id=$selectquest3[id]'><img src='Images/Finish_Button.gif'></a></center><Br>";
       }
       }

       else
       {
       print "<img src='Images/Completed_Text.gif'><br>";
       }
    }

Re: Query Issue

Posted: Sat Jan 01, 2011 8:11 am
by rapid3642
Hey thanks for the effort! unfortunately it didnt work, it does the exact same thing. i think whats going on is when it querys

SELECT * FROM quests

it selects all from quests but when the if statements are executed. it selects the first one that matches the statements and doesnt even try to look at the other quests cuz its trying to look at the fist one that matches the statements. maybe?

Re: Query Issue

Posted: Sat Jan 01, 2011 8:43 am
by alexander19
Well you used a while loop..so it should go through all the quests and check any of them.
But you could short that code by A LOT if you would made the checks when you actually found enough items,on the attack script like I told you on that pm rather than making all the checks here on the quest page.
Rather than checking everytime if you have enough items,or if you have the right items..you should check only if the quest is completed,like:

Code: Select all

if($selectpquest3['completed']=='yes')
echo "Congratulation you finished the quest";
else
echo "The quest is still in progress";
So rather than writing 100 rows..you could do it with 10,but make those checks right when you get the necesary items,and if you get enough just query the playersquests table and set completed to yes.

Re: Query Issue

Posted: Sat Jan 01, 2011 5:59 pm
by rapid3642
ok when i get the chance ill do it. ill post back when i finish it