How to develop an item mall.

This is guide mostly for website tools and code, for example CMS or registration scripts.
There can also be tools.

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

How to develop an item mall.

Postby Rifke on Thu Aug 09, 2007 3:12 pm

How to create an item mall
I've seen many people requesting for an item mall. But none of them are quite happy when they get one.

The requirements are the same as in my previous tutorial.
I'm going to use the same system as I've used in my other tutoral, same as the map names and such.

What are we going to use?
  • HTML
  • PHP
  • MySQL
  • JavaScript

Our database model would look like this.
  1.  
  2. + item_database (28 fields)
  3.     - id        (Primairy| intreger 11  | auto increment)
  4.     - sub_id    (index  | intreger 11   | define item_subcategories)
  5.     - item_id   (index  | intreger 11   | define item_itemlist)
  6.     - socket    ( /     | intreger 1    | define if there's a socket)
  7.     - refining  ( /     | intreger 1    | define if therer's a refining)
  8.     - zullie    ( /     | intreger 11   | define amount of zullie)
  9.     - paypal    ( /     | intreger 1    | define if paypal)
  10.     - donation_points( /    | intreger 11   | define amount of don. pts.)
  11.     - itempic   ( /     | varchar 255   | define item picture
  12.     - min_level ( /     | intreger 11   | define a minum level)
  13.     - str       ( /     | intreger 11   | define strength)
  14.     - dex       ( /     | intreger 11   | define dexternity)
  15.     - _int      ( /     | intreger 11   | define inteligence)
  16.     - con       ( /     | intreger 11   | define concentration)
  17.     - cha       ( /     | intreger 11   | define charm)
  18.     - sen       ( /     | intreger 11   | define sensibility)
  19.     - mspd      ( /     | varchar 11    | define movepent speed)
  20.     - crit      ( /     | intreger 11   | define critical)
  21.     - def       ( /     | intreger 11   | define defence)
  22.     - dodge     ( /     | intreger 11   | define dodge- rate)
  23.     - mdef      ( /     | intreger 11   | define magic defence)
  24.     - atk       ( /     | intreger 11   | define atack power)
  25.     - inv       ( /     | intreger 11   | define inventory)
  26.     - attacc    ( /     | intreger 11   | define attack accuracy)
  27.     - mpcon     ( /     | intreger 11   | define Mana Points consumption)
  28.     - hp        ( /     | intreger 11   | define Hit points)
  29.     - mp        ( /     | intreger 11   | define Mana points)
  30. + item_categories (3 fields)
  31.     - id        (primary| intreger 11   | auto increment)
  32.     - category  ( /     | varchar 255   | define the category name)
  33.     - info      ( /     | text          | define some additinal information to he category)
  34. + item_subcategories (5 fields)
  35.     - id        (primary| intreger 11   | auto increment)
  36.     - cid       ( index | intreger 11   | define the category ID)
  37.     - sub_category ( /  | varchar 255   | define the sub catergy name)
  38.     - info      ( /     | text          | define some add. info. to the sub category)
  39.     - items     ( /     | intreger 11   | define the amount of items in that sub_category)
  40. + item_itemlist (5 fields)
  41.     - id        (primary| intreger 11   | auto increment)
  42.     - itemid    ( index | intreger 11   | define the item id)
  43.     - itemtype  ( index | intreger 11   | define the item type)
  44.     - itemname  ( /     | varchar 255   | define the item name)
  45.     - iteminfo  ( /     | text          | define Some onfo about the item )
  46.  

Alot of fields like you see.. ( index | type | info)
The indexes that are used are correct, and should be added in that way. If you use good indexes, it makes your queries to peform better.
More info about indexes can be found here.


Like I said I'm going to relay on my previous tutorial.
So I assume you have made a page in members & a template in templates, and setted up your index file right. (I'll get back to that)

If not (wich I assume anyway)
Create a file in you members called itemmall.php.
Create a file in templates called itemmall.tpl.

- This is done let us continue -

We make a itemmall template from scratch. If you see wich fields are needed, you can see how it would be build in your tables.
We've got a category & a subcategory.
First we need to display the Categories and if the users clicks one the Subcategories

What we need to do if some one comes to the categories-page.
  • Say if there are categories | yes / no
  • if yes show them
  • if no show: There are no categories
Example:
  1.  
  2. <!-- START BLOCK : MainIsCategory -->
  3. <dl>Categories
  4.     <!-- START BLOCK : PrintCategories -->
  5.     <dt><a href="index.php?{Seperator}={Page}&cid={cat_id}">{Category}</a>
  6.         <dd>{CategoryInformation}</a></dd>
  7.     </dt>
  8.     <!-- END BLOCK : PrintCategories -->
  9. </dl>
  10. <!-- END BLOCK : MainIsCategory -->
  11.  
  12. <!-- START BLOCK : MainIsNoCategory -->
  13. <p>Sorry but there are currently no <b>categories</b> to be viewed.</p>
  14. <!-- END BLOCK : MainIsNoCategory -->
  15.  

Easy as that.

Now we make the itemall.php file ready.
  1.  
  2. <?php
  3. /* Create connection to our database */
  4. $ident = @mysql_connect($DatabaseConfig['HOST'],$DatabaseConfig['USER'],$DatabaseConfig['PASS']);
  5. if ($ident == false)
  6. {
  7.     die ('Database problem.');
  8. }
  9. if (!@mysql_select_db($DatabaseConfig['DB'],$ident))
  10. {
  11.     die ('Wouldn't select database');
  12. }
  13. /* Connection created, no error's found */
  14. // Start the template Class.
  15. $mall = new TemplatePower('templates/itemmall.tpl');
  16. $mall->prepare();
  17.  
  18. /* Now it's time to define if there are categories or not.
  19.    easy to do with a Query (ofcource)
  20. */
  21. $CategoriesSQL = "  SELECT id,category,info
  22.                     FROM item_categories
  23.                 ";
  24. $CategoriesQRY = @mysql_query($CategoriesSQL);
  25. /* Hide an error from public */
  26. if ( $CategoriesQRY === false ) // 3x =   => bolean
  27. {
  28.     /* There's an error; but the user doesn't need to know. So we just going to way we don't hae any categories. */
  29.     $mall->newBlock('MainIsNoCategory');
  30. }
  31. elseif ( @mysql_num_rows($CategoriesQRY) == 0)
  32. {
  33.     /* if the queryworks, but we still don't have any categories */
  34.     $mall->newBlock('MainIsNoCategory');
  35. }
  36. else
  37. {
  38.     /* Everthing is fine no error & records; PRINT! */
  39.     $mall->newBlock('MainIsCategory');
  40.    
  41.     // No w'll output the result
  42.     while ($CategoriesRES = @mysql_fetch_object($CategoriesQRY))
  43.     {
  44.         $Assign = array('Category' => $CategoriesRES->categories,
  45.                         'CategoryInformation' => $CategoriesRES->info,
  46.                         'cat_id' => $CategoriesRES->id);
  47.         /* I putted them first in the array so it's easier to remove the extra slashes */
  48.         $Assign = RetriveString($Assign);   // We delete the extra slashes out of the result
  49.        
  50.         $mall->newBlock('PrintCategories');
  51.         $mall->assign($Assign);  // The result is the same.
  52.     }
  53. }
  54. /* Print the itemmall content */
  55. $mall->printToScreen();
  56. ?>
  57.  

Download functions:
If everythig is going right you'll see some nice categories (or none).
[size=x-small]Add some categories to the database by hand to see if it works.[/size]

Now we have our categories, now it's time to go to the sub category if a user clicks it.

Go back to your itemmall.tpl template and add some new code to it to make it display the subcategories

Example:
  1.  
  2. <!--START BLOCK : MainSubCategory -->
  3. <a href="index.php?{Seperator={Page}">Categories</a> &raquo; Subcategory <br />
  4.     <!-- START BLOCK : MainIsSubCategory -->
  5.     <dl>SubCategories
  6.         <!-- START BLOCK : PrintSubCategory -->
  7.         <dt><a href="index.php?{Seperator}={Page}&cid={cat_id}&sid={sub_id}">{SubCategory}</a> ({Items})
  8.             <dd>{SubCategoryInformation}</a></dd>
  9.         </dt>
  10.         <!-- END BLOCK : PrintSubCategory -->
  11.     </dl>
  12.     <!-- END BLOCK : MainIsSubCategory -->
  13.  
  14.     <!-- START BLOCK : MainIsNoSubCategory -->
  15.     <p>Sorry but there are currently no <b>subcategories</b> to be viewed.</p>
  16.     <!-- END BLOCK : MainIsNoSubCategory -->
  17. <!-- END BLOCK : MainSubCategory -->
  18.  

It's about the same to the categories outputting. It's true. You can use the old one again. I don't care I do it on my way. (But don't complain if it doesn't turn out like you would it to be).
You also see that I've made a main block. It's used to make a good navigation pattern.

in you itemmall.php You need to make some elseif-blocks.
[quote] You you need to make elseif-blocks?[/quote]
It can work witout them. That's not the point. But it would display the subcategories & after it would show the categories.
(It's better to think infront it makes things easier.)

  1.  
  2. <?php
  3. /* Create connection to our database */
  4. $ident = @mysql_connect($DatabaseConfig['HOST'],$DatabaseConfig['USER'],$DatabaseConfig['PASS']);
  5. if ($ident == false)
  6. {
  7.     die ('Database problem.');
  8. }
  9. if (!@mysql_select_db($DatabaseConfig['DB'],$ident))
  10. {
  11.     die ('Wouldn't select database');
  12. }
  13. /* Connection created, no error's found */
  14. // Start the template Class.
  15. $mall = new TemplatePower('templates/itemmall.tpl');
  16. $mall->prepare();
  17.  
  18. if (isset($_GET['sid']))        // If the user clicked a sub cateogrie
  19. {
  20.     /* Here comes the other content from outputting the items in the subcategory */
  21.    
  22. }
  23. elseif ( isset($_GET['cid']) && preg_match("/^[0-9]+$/", $_GET['cid']) )    // if the user clicked a categorie
  24. {
  25.     /* Here comes the other content from outputting the subcategories */
  26.     $cid = $_GET['cid'];    // The cid made it trough our preg_match :) So it's an intreger.
  27.     /* Create our nagivation */
  28.     $mall->newBlock('MainSubCategory');
  29.     $mall->assign(array('Seperator', $Seperator,'Page' => $page )); // Done ^^
  30.    
  31.     /* Create the SQL & execute */
  32.     $SubCatSQL = "  SELECT id,sub_category,info,items
  33.                     FROM item_subcategories
  34.                     WHERE cid = '".$cid."' ";
  35.     $SubCatQRY = @mysql_query($SubCatSQL);
  36.     if ( $SubCatQRY === false )
  37.     {
  38.         /* Error in query > Print No subcategories */
  39.         $mall->newBlock('MainIsNoSubCategory');
  40.     }
  41.     elseif ( @mysql_num_rows($SubCatQRY) == 0 )
  42.     {
  43.         /* No subcategories to show > Print No Subcategories */
  44.         $mall->newBlock('MainIsNoSubCategory');
  45.     }
  46.     else
  47.     {
  48.         /* Success Print Subcategories */
  49.         $mall->newBlock('MainIsSubCategory');
  50.         while ( $SubCatRES = @mysql_fetch_object($SubCatQRY) )
  51.         {
  52.             $Assign = array('SubCategory' => $SubCatRES->categories,
  53.                             'SubCategoryInformation' => $SubCatRES->info,
  54.                             'sub_id' => $SubCatRES->id,
  55.                             'cat_id' => $cid);
  56.             /* I putted them first in the array so it's easier to remove the extra slashes */
  57.             $Assign = RetriveString($Assign);   // We delete the extra slashes out of the result       
  58.             $mall->newBlock('PrintSubCategory');
  59.             $mall->assign($Assign);  // The result is the same.
  60.             $mall->assign(array('Seperator' => $Seperator, 'Page' => $page)); // To make the links work.
  61.         }
  62.     }
  63.    
  64. }
  65. else
  66. {
  67.     /* Here comes the other content from outputting the categories */
  68.     //  .... (it would make the Tutorial to long if I have to repeat it all over again)
  69. }
  70. /* Print the itemmall content */
  71. $mall->printToScreen();
  72. ?>
  73.  


Phew we did that, all the Catogories popped up.

So for, so good.
Now it's time for the hardwork. Printing the items within the subcategory and link them toour main item database.

Let's do the items now. (It's up to you to create the extra's like: socket & refine.)

There has to be a link between items_database (itemid) and items_itemslist (id), to do this is to use a JOIN within your query. Or using 2 different queries.

Back to our template.
We'll add the following
  1.  
  2. <!--START BLOCK : MainItems -->
  3. <a href="index.php?{Seperator={Page}">Categories</a> &raquo; <a href="index.php?{Seperator={Page}&cid={cat_id}">Subcategory</a> &raquo; Items
  4. <br />
  5.     <!-- START BLOCK : MainIsItems -->
  6.     <dl>Items
  7.         <!-- START BLOCK : PrintMainItems -->
  8.         <dt><a href="index.php?{Seperator={Page}&cid={cat_id}&sid={sub_id}&iid={item_id}">{Item}</a> ({Price})
  9.             <dd>{ItemInformation}</dd>
  10.         </dt>
  11.         <!-- END BLOCK : PrintMainItems -->
  12.     </dl>
  13.     <!-- END BLOCK : MainIsItems -->
  14.  
  15.     <!-- START BLOCK : MainNoItems -->
  16.     <p>Sorry but there are currently no <b>items</b> to be viewed.<p></p>
  17.     <!-- END BLOCK : MainNoItems -->
  18. <!-- END BLOCK : MainItems -->
  19.  


To our itemmall.php
  1.  
  2. <?php
  3. if (isset($_GET['sid']) && preg_match("/^[0-9]+$/", $_GET['sid']) && isset($_GET['cid']) && preg_match("/^[0-9]+$/", $_GET['cid']))     // If the user clicked a sub cateogrie
  4. {
  5.     /* Here comes the other content from outputting the items in the subcategory */
  6.     $sid = $_GET['sid'];
  7.     $cid = $_GET['cid'];
  8.    
  9.     $mall->newBlock('MainItems');
  10.     /* The navigation */
  11.     $mall->assign(array('Seperator' => $Seperator, 'Page' => $page,
  12.                         'cat_id' => $cid);
  13.    
  14.     $ItemSQL = "SELECT
  15.                     item_database.id as item_id,
  16.                     item_database.zullie,
  17.                     item_database.paypal,
  18.                     item_database.donation_points,
  19.                     item_itemlist.itemname,
  20.                     item_itemlist.iteminfo
  21.                 FROM
  22.                     item_itemlist
  23.                 INNER JOIN
  24.                     item_database
  25.                 ON
  26.                     ( item_itemlist.id = item_database.item_id)
  27.                 WHERE
  28.                     item_database.sub_id = '".$sid."' ";
  29.     /* It's a big query, but it selecs the name & info frmo item_itemlist e &
  30.     prices and things from item_database */
  31.     $ItemQRY = @mysql_query($ItemSQL);
  32.     if ( $ItemQRY  === false )
  33.     {
  34.         $mall->newBlock('MainNoItems');
  35.     }
  36.     elseif ( @mysql_num_rows($ItemQRY) == 0)
  37.     {
  38.         $mall->newBlock('MainNoItems');
  39.     }
  40.     else
  41.     {
  42.         $mall->newBlock('MainIsItems');
  43.         while ($ItemRES = @mysql_fetch_object($ItemQRY))
  44.         {
  45.             /* Paypal: yes (1) No (0) */
  46.             ( $ItemRES->paypal == 0 ) ? $EndStr = ' z' : $EndStr = ' pt';
  47.             ( $ItemRES->paypal == 0 ) ? $Price = $ItemRES->zullie : $Price = $ItemRES->donation_points;
  48.             /* We've defined donation & price */
  49.             $Assign = array('Item' => $ItemRES->itemname,
  50.                             'ItemInformaion' => $ItemRES->iteminfo,
  51.                             'Price' => $Price.$EndStr,
  52.                             'item_id' => $ItemRES->item_id);
  53.             $Assign = RetriveString($Assign);
  54.             /* You can add stats to it do; you only need to get them out of the database seperated */
  55.             $mall->newBlock('PrintMainItems');
  56.             $mall->assign($Assign); // Assing the array
  57.             /* The navigation */
  58.             $mall->assign(array('Seperator' => $Seperator, 'Page' => $page,
  59.                                 'cat_id' => $cid, 'sub_id' => $sid));
  60.         }
  61.     }   
  62. }
  63. ?>
  64.  


This is done also. If you click it only your url will change... Now we are going to up the new item id in a session.

Well add in top of our itemmall.php the session line.
Warning!
  • Make sure you have in your index session_start(); This is placed just under the <?php line.

Just under this line we'll add the session storage.
  1.  
  2. <?php
  3. /* Create connection to our database */
  4. $ident = @mysql_connect($DatabaseConfig['HOST'],$DatabaseConfig['USER'],$DatabaseConfig['PASS']);
  5. if ($ident == false)
  6. {
  7.     die ('Database problem.');
  8. }
  9. if (!@mysql_select_db($DatabaseConfig['DB'],$ident))
  10. {
  11.     die ('Wouldn't select database');
  12. }
  13. /* Connection created, no error's found */
  14. // Start the template Class.
  15. $mall = new TemplatePower('templates/itemmall.tpl');
  16. $mall->prepare();
  17.  
  18. /* Store item in session */
  19. if ( isset($_GET['iid']) && preg_match("/^[0-9]+$/", $_GET['iid']) )
  20. {
  21.     /* iid is a valid intreger */
  22.     $item_id = $_GET['iid'];
  23.     /* You can add refining & socketed and stuff later by your own. Now it is just the ID */
  24.     $_SESSION['ItemMall'][] = $item_id// [] stands for array format */
  25. }
  26. /* Here we will add like: You have xx items in your storage BUT we hide it when it's 0 */
  27. if (isset($_SESSION['ItemMall']) && @is_array($_SESSION['ItemMall']) && count($_SESSION['ItemMall']) > 0)
  28. {
  29.     /*
  30.         Item mall is set. It's an array & it's higher than zero.
  31.     */
  32.  
  33.     $mall->newBlock('ItemsInMall');     /* We create thatblock later on */
  34.     $mall->assign(array('Seperator' => $Seperator, 'Page' => $page,
  35.                         'Type' => 'cart' , 'iItems' => count($_SESSION['ItemMall'])));
  36. }
  37. /* Here is your other item mall code */
  38.  



Now we'll make the block named ItemsInMall goto your template itemmall.tpl

Add above any content (in top)
  1.  
  2. <!-- START BLOCK : ItemsInMall -->
  3.     You currently have {iItems} item(s) in your shopping cart. <br />
  4.     Click <a href="index.php{Seperator}={Page}&type={Type}">here</a> to go to your shopping cart. <br />
  5. <!-- END BLOCK : ItemsInMall -->
  6.  


You can add more things if you like. That's up to you.

Everything is almost done. Now comes the hardpart. The purchace of the items.

In our itemmall.tpl we create a new block called MainShoppingCart & MainNoShoppingCart .

Example:
  1.  
  2. <!-- START BLOCK : MainNoShoppingCart -->
  3.     <p> You do not have any items in your shopping cart. </p>
  4.     Click <a href="index.php{Seperator}={Page}" >here</a> to return to the categories. <br />
  5. <!-- END BLOCK : MainNoShoppingCart -->
  6.  
  7. <!-- START BLOCK : MainShoppingCart -->
  8. <script language="JavaScript" type="text/javascript">
  9. function AreYouSure(item_id) {
  10. if(window.confirm("Are you sure you want to delete this item from your shopping cart?")) {
  11.     window.location = "index.php?{Seperator}={Page}&type={Type}&del_id=" + item_id;
  12.   }  
  13. }
  14. </script>
  15. <a href="index.php{Seperator}={Page}" > Categories </a> &raquo; Shopping cart <br />
  16. <table width="100%" border="0" cellspacing="2" cellpadding="2">
  17.   <!-- START BLOCK : ShoppingCart -->
  18.   <tr>
  19.     <td width="50%">{ItemName}<br /> &nbsp;&nbsp; &raquo; {ItemInformation} </td>
  20.     <td valign="top" align="left">Price:<br />
  21.       {Price} </td>
  22.     <td align="center" width="10%">[ <a href="#" onClick="AreYouSure('{item_id}');">Remove</a>
  23.       ]</td>
  24.   </tr>
  25.   <!-- END BLOCK : ShoppingCart -->
  26.   <tr>
  27.     <td height="30" align="right" valign="top">Zulie price:<br />
  28.       Donation points:</td>
  29.     <td height="30" colspan="2" align="left" valign="top">{TotalZuliePrice}
  30.       z<br />
  31.       {TotalDonationPts} pt<br /></td>
  32.   </tr>
  33.   <tr>
  34.     <td height="30" colspan="3" align="right"><form name="form1" method="post" action="index.php?{Seperator}={Page}&type={Type}">
  35.         <input name="PurchaseOrder" type="submit" id="PurchaseOrder" value="Purchase Order" {Disabled}>
  36.       </form></td>
  37.   </tr>
  38. </table>
  39. <!-- END BLOCK : MainShoppingCart -->
  40.  


To our itemmall.php
Where we have the line that says we are in the items we make it into an elseif

  1.  
  2. if (isset($_GET['type']) && $_GET['type'] == 'cart')
  3. {
  4.     /* Here comes our item mall */
  5.     if (isset($_GET['del_id']) && preg_match("/^[0-9]+$/", $_GET['del_id'])) // This will generate fase all the time. We use this later
  6.     {
  7.         /* Delete an item from your shopping cart */
  8.         unset($_SESSION['ItemMall'][$_GET['del_id']]);
  9.     }
  10.    
  11.     /* We count the items in the session if it's 0 we say you don't have any items in your cart */
  12.     $ItemsInSession = count($_SESSION['ItemMall']);
  13.    
  14.     if ($ItemsInSession <= 0 || !@is_array($_SESSION['ItemMall']) )
  15.     {
  16.         /* No items in cart  or the session isn't an array */
  17.         $mall->newBlock('MainNoShoppingCart');
  18.         $mall->assign(array('Seperator' => $Seperator, 'Page' => $Page));
  19.     }
  20.     else
  21.     {
  22.         /* Show the items */
  23.         $mall->newBlock('MainShoppingCart');
  24.        
  25.         /* We could use a for loop.  but if an item is deleted from your session the loop quits, even if there still are items. So that isn't good
  26.             It took me a while to to figure out how I shoud do it. My conclusion felt on foreach()
  27.         */
  28.         $ItemMall = $_SESSION['ItemMall']; // Easier to use in the script
  29.        
  30.         /* In this example $Index would be the array Index & pointer would be the item id */
  31.         foreach($ItemMall as $Index => $Pointer)
  32.         {
  33.             $x = $Index;            /* No confusion posible now */
  34.             $item_id = $Pointer;    /* No confusion posible now */
  35.            
  36.             // Start the block
  37.             $mall->newBlock('ShoppingCart');
  38.            
  39.             /* We select the item name from our database & also price (pts || zulie ) */
  40.             $ShoppingSQL = "SELECT
  41.                                 item_database.id as item_id,
  42.                                 item_database.zullie,
  43.                                 item_database.donation_points,
  44.                                 item_database.paypal,
  45.                                 item_itemlist.itemname,
  46.                                 item_itemlist.iteminfo
  47.                             FROM
  48.                                 item_database
  49.                             INNER JOIN
  50.                                 item_itemlist
  51.                             ON
  52.                                 (item_database.item_id = item_itemlist.id)
  53.                             WHERE
  54.                                 item_database.id = '".$item_id."' ";
  55.             $ShoppingQRY = @mysql_query($ShoppingSQL);
  56.             if ($ShoppingQRY === false)
  57.             {
  58.                 /* Querie returned false on that item. Unset that ID*/
  59.                 unset($_SESSION['ItemMall'][$x]);          
  60.             }
  61.             elseif (mysql_num_rows($ShoppingQRY) == 0)
  62.             {
  63.                 /* Someone editied the session!!!!!!!!!!!!!!!!!!!!!!
  64.                     Or the admn just deleted that item
  65.                 */
  66.                 $mall->assign(array('ItemInfo' => 'Invalid result', 'ItemInfo' => 'Invalid search result'));
  67.                 unset($_SESSION['ItemMall'][$x]);
  68.             }
  69.             else
  70.             {
  71.                 /* No error's No 0 values */
  72.                 // Count zulie & donation pts...
  73.                 $ShoppingRES = @mysql_fetch_object($ShoppingQRY);
  74.                 $dpts = $dpts + $ShoppingRES->donation_points// $new value = $old value + $DatabaseConfig_value
  75.                 $zulie = $zulie + $ShoppingRES->zullie;
  76.                
  77.                 ( $ShoppingQRY->paypal == 0) ? $Price = $ShoppingRES->zullie.' z' : $Price = ShoppingRES->donation_points.' pts';
  78.                
  79.                 $Assign('ItemName' => ShoppingRES->itemname, 'ItemInfo' => $ShoppingRES->iteminfo,
  80.                         'Price' => $Price, 'item_id' => $ShoppingRES->item_id);
  81.                 $Assing = RetriveString($Assign);
  82.                
  83.                 $mall->assign($Assign);
  84. //              $mall->assign(array('Seperator' => $Seperator, 'Page' => $Page))
  85.             }
  86.         }
  87.         /* Foreach has finished ; show the price */
  88.         // I have no idea how your login works. But if you make one make sure it STORES the account ID somewhere . To make it absolute save use PASS & UserName to
  89.         $AccountQRY = @mysql_query("SELECT donation,zulystorage,online
  90.                                     FROM accounts
  91.                                     WHERE id='".$AccountID."'
  92.                                     /* && username='".$AccountUserName."' && password='".$AccountPassword."' */
  93.                                     ";
  94.         $AccountRES = @mysql_fetch_object($AccountQRY);
  95.         if ($zulie > $AccountRES->zulystorage || $dpts > $AccountRES->donation || $AccountRES->online == 1)
  96.         {
  97.             /* Disable the submit */
  98.             $mall->assgn('Disabled' => 'disabled="disabled"' );
  99.         }
  100.         else
  101.         {
  102.             // Do nothing or show how much he/she has left
  103.         }
  104.        
  105.     }
  106. }
  107. elseif (isset($_GET['sid']) && preg_match("/^[0-9]+$/", $_GET['sid']) && isset($_GET['cid']) && preg_match("/^[0-9]+$/", $_GET['cid']))     // If the user clicked a sub cateogrie
  108. {
  109.  /* here the item code */
  110. }
  111. elseif (...
  112.  


Phew we are trough that one... Now our final stage is to to put those item in the storage.

Back to the itemmall.php . And again we need to place some code above thet code we've just wrote.

We start writing above the following code.
  1.  
  2. if (isset($_GET['type']) && $_GET['type'] == 'cart')
  3.  


  1.  
  2. if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['PurchaseOrder']) && $_POST['PurchaseOrder'] == 'Purchase Order')
  3. {
  4.     /* Purchase code */
  5.  
  6. }
  7. if (isset($_GET['type']) && $_GET['type'] == 'cart')
  8. /* The rest of the code */
  9.  


What need to be happen
  • Item must get into the storage
  • Zulie or donation points need to be decreased
  • ...

It's quite the same, we can use part of the code we've writen above and adjust it to make it work.
  1.  
  2. if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['PurchaseOrder']) && $_POST['PurchaseOrder'] == 'Purchase Order')
  3. {
  4.     /* Purchase code */
  5.     $StroagePointer = 159; // Last position in your storage tab down right corner
  6.     foreach($ItemMall as $Index => $Pointer)
  7.     {
  8.         $x = $Index;            /* No confusion posible now */
  9.         $item_id = $Pointer;    /* No confusion posible now */ 
  10.        
  11.         $ShoppingSQL = "SELECT
  12.                             item_database.zullie,
  13.                             item_database.donation_points,
  14.                             item_itemlist.itemid,
  15.                             item_itemlist.itemtype                     
  16.                         FROM
  17.                             item_database
  18.                         INNER JOIN
  19.                             item_itemlist
  20.                         ON
  21.                             (item_database.item_id = item_itemlist.id)
  22.                         WHERE
  23.                             item_database.id = '".$item_id."' ";   
  24.         $ShoppingQRY = @mysql_query($ShoppingSQL);
  25.         if ($ShoppingQRY === false)
  26.         {
  27.             /* Querie returned false on that item. Unset that ID*/
  28.             unset($_SESSION['ItemMall'][$x]);          
  29.         }
  30.         elseif (mysql_num_rows($ShoppingQRY) == 0)
  31.         {
  32.             /* Unset that ID*/
  33.             unset($_SESSION['ItemMall'][$x]);
  34.         }
  35.         else
  36.         {
  37.             $pts = 0;   // Set don. pt to 0
  38.             $zul = 0;   // Set zul to 0
  39.             $ShoppingRES = @mysql_fetch_object($ShoppingQRY);
  40.             $pts = $ShoppingRES->donation_points;
  41.             $zul = $ShoppingRES->zullie;
  42.        
  43.             /* decrease zullie or donation points; */
  44.             $PriceSQL ="UPDATE
  45.                             account
  46.                         SET
  47.                             donation = donation - ".$pts.",
  48.                             zulystorage = zulystorage - ".$zul."
  49.                         WHERE
  50.                             id='".$AccountID."'
  51.                             /*&&  usrname='".$AccountUserName."' && password='".$AccountPassword."'  */
  52.                         ";
  53.             $PriceQRY = @mysql_query($PriceSQL);
  54.             if ($PriceQRY === false)
  55.             {
  56.                 // Uhm something failed. Ah wel :)
  57.             }
  58.             else
  59.             {
  60.                 // Everyting is fine.. Continue with the item.
  61.                 $StorageSQL = "INSERT INTO storage
  62.                                     (owner,itemnum,itemtype,slotnum)
  63.                                 VALUES
  64.                                     ('".$AccountID."',
  65.                                      '".$ShoppingRES->itemid."',
  66.                                      '".$ShoppingRES->itemtype."',
  67.                                      '".$StroagePointer."')
  68.                                 ";
  69.                 $StorageQRY = @mysql_query($StorageSQL);
  70.                 if ($StorageQRY === false)
  71.                 {
  72.                     // Hehe to bad, but we won't unset the item ID, so he can try again. But to bad fro the donation points or zullie. He lost that :)
  73.                 }
  74.                 else
  75.                 {
  76.                     // Delete the item id from the session
  77.                     unset($_SESSION['ItemMall'][$x]);
  78.                     // Decrease Storagepointer with 1
  79.                     $StroagePointer--;
  80.                 }
  81.             }
  82.         }
  83.     }
  84. }
  85.  

How to create an Item Mall tutorial, written by Rifke


Thank you for your attention.
Kind regards
Rifke


This tutorial can be used to help you know more about PHP & MySQL & Templates. It's made for osRose, and other communities where I'm on. Any coppies in any posible way is not allowed. (This includes posting on other forums).
Rifke
Pero pero
Pero pero
 
Posts: 719
Joined: Thu Aug 09, 2007 3:01 pm
Location: Belgium

Re: How to develop an item mall.

Postby xxsmurfxx on Mon Oct 08, 2007 3:17 pm

My question is maybe you can make one already working because i can't get it working,
And mayeb a little guid how to add items to the item mall it would be great :mrgreen:

Already thanks
Image
Live Your Dreams -=Smurf=-
User avatar
xxsmurfxx
Rackie
Rackie
 
Posts: 153
Joined: Tue Oct 02, 2007 6:00 pm
Location: Uhm Home

Re: How to develop an item mall.

Postby Rifke on Mon Oct 08, 2007 9:27 pm

Rifke
Pero pero
Pero pero
 
Posts: 719
Joined: Thu Aug 09, 2007 3:01 pm
Location: Belgium


Return to PHP / Web Guides, Scripts and tools.

Who is online

Users browsing this forum: No registered users and 7 guests