Page 2 of 2

Re: Is this code correct?

Posted: Thu Oct 09, 2008 5:49 pm
by cdoyle
aceconcepts wrote:In that case then:

Code: Select all

 
$itemcheck = mysql_query("SELECT * FROM items WHERE player_id='$option_name1'");
 
if(mysql_num_rows($itemcheck)==0)
{
   //INSERT PLAYER OR WEAPON ETC...
}
else
{
                        while($row = mysql_fetch_array($itemcheck))
                        {
                            if ( $item_number == "1")
                            {
                                     $itemtype = 10;
                                if ($row['item_id'] == $itemtype)
                                {
                                    $updateweapon = mysql_query("UPDATE items SET quantity = quantity + '15' Where player_id = '$option_name1' and item_id = '$itemtype'");
                                }
                                else
                                {
                                    $insertweapon = mysql_query("INSERT into items(player_id,item_id,status)values('$option_name1','$itemtype','unequipped')");
                                }
                            }
}
 
That worked great!
thank you.

I just removed that second insert since I don't need it anymore.

So when I start creating other donation packs, would I just create an elseif and copy

if ( $item_number == "1")
{

changing the $item_number to whatever it is?

And do that for each donation pack? Or is there a better way?

Re: Is this code correct?

Posted: Fri Oct 10, 2008 2:58 pm
by cdoyle
I think I need to tweak this some more,

What we have now works pretty good with just 1 type of item.

But I want to be able to let users have a choice of several different packs to choose from.
So I think the insert needs to go back into the IF, and insert the correct item type, depending on what was selected.

Here is what I have so far.
and can $itemtype can it be different for each IF?
For example for Item_Number1 the $itemtype would be 10
but if they chose Item_Number2 the $itemtype would be something else.

Code: Select all

 
  $itemcheck = mysql_query("SELECT * FROM items WHERE player_id='$option_name1'");
 
                        if(mysql_num_rows($itemcheck)==0)
                        {
                            $insertweapon = mysql_query("INSERT into items(player_id,item_id,status)values('$option_name1','$itemtype','unequipped')");   <<< I think this needs to move back into the IF statements because the type of insert depends on what pack the user selected.
                        }
                        else
                        {
                            while($row = mysql_fetch_array($itemcheck))
                            {
                                if ( $item_number == "1")//health kits
                                {
                                    $itemtype = 10;
                                    if ($row['item_id'] == $itemtype)
                                    {
                                        $updateweapon = mysql_query("UPDATE items SET quantity = quantity + '15' Where player_id = '$option_name1' and item_id = '$itemtype'");
                                    }
                                    else if( $item_number == "2")//health kits
                                    {
                                        
                                    }
 

Re: Is this code correct?

Posted: Fri Oct 10, 2008 4:47 pm
by aceconcepts
How do you store Item_Number and item_type in the database? In the same table? Different tables?

Re: Is this code correct?

Posted: Fri Oct 10, 2008 5:02 pm
by cdoyle
$Item_Number is not stored in the db, it's the ID of the paypal button. It's used to determine what pack the player purchased.

$item_type will be stored in the item_type field of the items table.

Re: Is this code correct?

Posted: Fri Oct 10, 2008 5:13 pm
by aceconcepts
I think what you need to do is relate item_type with item_number in a db table. That way you could simply query the database for the correct item_type without having to make an IF statement for each item_type.

Understand?

Re: Is this code correct?

Posted: Fri Oct 10, 2008 5:16 pm
by cdoyle
I think I will still need the ifs, because some packs give multiple of some items, and other packs will give just one of somethign else.
So I would need to have separate update queries to show that wouldn't I?

Or can that be done with the tables, and queries?

Re: Is this code correct?

Posted: Fri Oct 10, 2008 5:27 pm
by aceconcepts
If you allow the user to select their items or packs etc... by using check boxes - so that they can select multiple packs etc...

e.g. if user select pack 1 and pack 4, what you could do is simply loop the selections they make.

Does this make sense to you or not?

Re: Is this code correct?

Posted: Fri Oct 10, 2008 8:21 pm
by cdoyle
aceconcepts wrote:If you allow the user to select their items or packs etc... by using check boxes - so that they can select multiple packs etc...

e.g. if user select pack 1 and pack 4, what you could do is simply loop the selections they make.

Does this make sense to you or not?
I'm not really sure how to do this with a paypal buy it now button.
You have the buy it now button, and it can only pass a couple variables to paypal, which are then sent back to this script once payment has been accepted

I'm not understanding how how the script will know to update xx amount for specific items, unless it's actually hard coded into the page itself.

Here is how I'm seeing this work,
I'll have a donate page, and on the page I'll have a listing of packs they can buy.

Pack 1: Health Pack, gives the player 15 health packs
Pack 2: Mini Gun Pack, gives the player 1 min-gun
Pack 3: Cash Pack, Gives the user $5,000 <<< Players cash is stored in the players table.
Pack 4
Pack 5
Pack 6

So how would I go about doing this?
I'm confused how to make this work now.

Re: Is this code correct?

Posted: Sat Oct 11, 2008 12:48 pm
by aceconcepts
In order to get multiple checkbox values you can do it like this:

This HTML code will be for the checkboxes - each checkbox should have the same name with "[]" after the name:

Code: Select all

 
<input type="checkbox" name="chkPack[]" value="1" />
<input type="checkbox" name="chkPack[]" value="2" />
<input type="checkbox" name="chkPack[]" value="3" />
 
This code will loop chkPack[] values - the "[]" passes the checkbox values as an array.

Code: Select all

 
foreach($_POST['chkPack'] as $value)
{
//$value will be the value for each "checked" checkbox
}
 
Does this help?