This is for anyone who wants a challenge. Can't make it work

Need some coding help with a MOD or tweak you are working on? - Ask here.
Forum rules
Ask for support specifically regarding coding help with phpBB3.
Not for generic usability questions or support.

This is for anyone who wants a challenge. Can't make it work

Postby BlueCollar » 22 Mar 2011, 11:07

See my most recent post for the most recent code I'm working on (below).
Last edited by BlueCollar on 01 Apr 2011, 13:55, edited 1 time in total.
BlueCollar    
Cadet II
Cadet II
 
Posts: 23
Joined: 21 Mar 2011, 20:32
Gender: Male
phpBB Knowledge: 3


Re: This is for anyone who wants a challenge. Can't make it work

Postby topdown » 22 Mar 2011, 15:40

When it comes to creating queries for phpBB3 this should help a bit
http://wiki.phpbb.com/Database_Abstraction_Layer
Do not PM me for Support unless I give permission in a post......PM's only help one, posts help everyone !
User avatar
topdown    
STG Styles Leader
STG Styles Leader
 
Posts: 3027
Joined: 01 Oct 2007, 22:56
Location: Handyman's harddrive
Favorite Team: STG Teams
Gender: Male
phpBB Knowledge: 9

Re: This is for anyone who wants a challenge. Can't make it work

Postby BlueCollar » 24 Mar 2011, 12:59

Thanks for the advice! I got the code to repeat how I wanted (code posted at bottom of this post). I have another question now:

This code is going to repeat itself until it retrieves and displays all of a user's items. However, it's going to retrieve and display them all in one quick dump. For example:

Someone who has ALL the items would have a page like this:

Image

So consider the above image the 'template', if you will, for all the other users to try to mimick by buying items from the shop.





Now, someone who only has a few items SHOULD have a page like this:

Image




However, the coding I currently have will give them a page like this:

Image




Does anyone have an idea of how I can alter the coding so that image 3 becomes image 2? Hopefully this makes sense. Originally I was trying to find a way to use constants in the mix but I wasn't sure where to start. I was also thinking about adding a number to the start of each image URL and then coming up with a query that would look for the number and place it in the appropriate position in the table on the page. Currently I'm only working with one block_var assignment, and I'm starting to think that I may need multiple block_vars to transfer over to the HTML page and use 1 block_var for each position on the table. However that seems tedious and not very easy to manipulate so I'm hoping someone might have a better idea than mine.

If you are unclear on something please ask and I'll clarify it the best I can. This is the first piece of coding that I've been successfully tweaking and it's pretty cool if I say so myself!


Here's the code that I've tweaked:

Code: Select all
<?php
/**
*
* @package - phpBB3 UPS Easy Shop
* @version $Id: shop.php 247 2010-08-24 16:16:48Z femu $
* @copyright (c) 2010 Wuerzi - http://spieleresidenz.de and femu - http://die-muellers.org
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/shop/functions_shop.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup(array('mods/shop', 'mods/points'));

// Load shop template
$template->set_filenames(array(
   'body' => 'displaycase_body.html')
);


         $useridnumber = $user->data['user_id'];
         $result = mysql_query   (   "SELECT *
                              FROM phpbb_shop_items_user
                              WHERE user = $useridnumber"
                           );                  
         while($row = mysql_fetch_array($result))
         {
         $itemnumber = $row['item'];
         
         $result2 = mysql_query   (   "SELECT *
                              FROM phpbb_shop_items
                              WHERE item = $itemnumber"
                           );               
         while($row = mysql_fetch_array($result2))
         {
         $itemimage = '<a href="' . $phpbb_root_path . 'images/shop_icons/' . $row['icon'] . '" onclick=" window.open(this.href); return false" title="' . $user->lang['SHOP_HIGHSLIDE_CLICK'] . '"><img src="' . $phpbb_root_path . 'images/shop_icons/' . $row['icon'] . '" alt="' . $user->lang['SHOP_HIGHSLIDE_CLICK'] . '" /></a>';
         $template->assign_block_vars('item_list', array(
               'ICON'         => $itemimage
                              ));
                           

         }
         }
         
// $result = mysql_query("SELECT * FROM phpbb_shop_items_user");
// while($row = mysql_fetch_array($result))
   // {
   // $itemdisplay = $row
// echo $user->data['user_id'];
         
            
page_header($page_title);

page_footer();

?>
BlueCollar    
Cadet II
Cadet II
 
Posts: 23
Joined: 21 Mar 2011, 20:32
Gender: Male
phpBB Knowledge: 3

Re: This is for anyone who wants a challenge. Can't make it work

Postby topdown » 24 Mar 2011, 15:40

I think we should get your code fixed up first. Your problem at hand is fairly simple once the code is corrected.

First thing I see is you have a query inside a loop.
That's a big NoNo.
Although it looks like it will only be hitting 1 id on the first loop, it's still bad practice and can lead to big problems down the road.

What is your first query actually collecting? in the table phpbb_shop_items_user ?
So what is the returned $row['item'] actually? ID, a count, etc...

Assuming that is an ID of some sort, your making another query on phpbb_shop_items using the return from the first query.

Now this could be a Join or any number of query types.
But I need to know what the data is being returned and queried.

Or i maybe best just to grab the SQL for these 2 tables so I can see your table structure.
Do not PM me for Support unless I give permission in a post......PM's only help one, posts help everyone !
User avatar
topdown    
STG Styles Leader
STG Styles Leader
 
Posts: 3027
Joined: 01 Oct 2007, 22:56
Location: Handyman's harddrive
Favorite Team: STG Teams
Gender: Male
phpBB Knowledge: 9

Re: This is for anyone who wants a challenge. Can't make it work

Postby BlueCollar » 24 Mar 2011, 16:10

The first query matches the user ID with all items associated with that user's ID number (which is in phpbb_shop_items_user).

The second query matches the item with it's image URL (which is in phpbb_shop_items).

After the two queries I want to display the image. As the code is right now, it works. However as you said it's not the greatest. For the most part all my work so far has been through reading a php book I bought, online tutorials, and guessing and checking. To be honest I'm surprised I've made it this far :thumbsup: I've attached screenshots of both tables so you can better see my train of thought.

Just a heads up, the tables are an integral part of the mod I'm tweaking, so I can't really change the structure of the tables if you were looking to do that. All that can be changed is the php to read it. But you may have figured that already. Thanks for looking into this.
Attachments
phpbb_shop_items_user.jpg
phpbb_shop_items.jpg
BlueCollar    
Cadet II
Cadet II
 
Posts: 23
Joined: 21 Mar 2011, 20:32
Gender: Male
phpBB Knowledge: 3

Re: This is for anyone who wants a challenge. Can't make it work

Postby topdown » 24 Mar 2011, 20:56

Are your trying to display rows of items that the user has?
So for instance user 2 has item 15,16,17 and 18
Do not PM me for Support unless I give permission in a post......PM's only help one, posts help everyone !
User avatar
topdown    
STG Styles Leader
STG Styles Leader
 
Posts: 3027
Joined: 01 Oct 2007, 22:56
Location: Handyman's harddrive
Favorite Team: STG Teams
Gender: Male
phpBB Knowledge: 9

Re: This is for anyone who wants a challenge. Can't make it work

Postby BlueCollar » 24 Mar 2011, 21:30

Exactly. And each item has an image in the table called phpbb_shop_items. I want to display the items, but in a predetermined order.

It's for a sports website, so there will be simple items like the Lombardi Trophy, Stanley Cup, Commissioner's Trophy and Larry O'Brien Trophy, as well as team logos (redrawn) and other items. So I'd like to have all the items in their own designated 'spot'. And if you buy the item (with the points system mod on my forum) that item will show up in your display case. If you don't buy the item, then that spot stays open until you do buy it. Makin' any sense?
My Sports Forum: GG Sports
BlueCollar    
Cadet II
Cadet II
 
Posts: 23
Joined: 21 Mar 2011, 20:32
Gender: Male
phpBB Knowledge: 3

Re: This is for anyone who wants a challenge. Can't make it work

Postby BlueCollar » 31 Mar 2011, 11:28

Bump - any ideas on this?
My Sports Forum: GG Sports
BlueCollar    
Cadet II
Cadet II
 
Posts: 23
Joined: 21 Mar 2011, 20:32
Gender: Male
phpBB Knowledge: 3

Re: This is for anyone who wants a challenge. Can't make it work

Postby BlueCollar » 09 Apr 2011, 19:43

Got it! After some help I finally got this code...

Code: Select all
<?php
/**
*
* @package - phpBB3 UPS Easy Shop
* @version $Id: shop.php 247 2010-08-24 16:16:48Z femu $
* @copyright (c) 2010 Wuerzi - http://spieleresidenz.de and femu - http://die-muellers.org
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/shop/functions_shop.' . $phpEx);


// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup(array('mods/shop', 'mods/points'));

// Load shop template
$template->set_filenames(array(
   'body' => 'trophycase_body.html')
);

         //Here is where we add the 'trophycase_order' row to the 'phpbb_shop_items' table.
         // $query = "SELECT * FROM phpbb_shop_items";
         // $result = mysql_query($query) or die(mysql_error());

         // $sql = "ALTER TABLE " . $table_prefix . "shop_items
            // ADD trophycase_order MEDIUMINT(8) NOT NULL DEFAULT '0'";
         // $db->sql_query($sql);
         
         //Finished adding the trophycase row
         
         
      
      //Here is where we combine our 'items' and 'items_user' tables together
      //and order the items based on the 'trophycase_order'
      
      $useridnumber = $user->data['user_id'];   
      $alliteminfo= array();  // All rows go in here
      $newquery=  mysql_query (   "   
                              SELECT    phpbb_shop_items_user.user,
                                    phpbb_shop_items_user.item,
                                    phpbb_shop_items.item,
                                    phpbb_shop_items.icon,
                                    phpbb_shop_items.trophycase_order
                              FROM phpbb_shop_items_user
                              INNER JOIN phpbb_shop_items
                              ON phpbb_shop_items_user.item = phpbb_shop_items.item
                              WHERE phpbb_shop_items_user.user = $useridnumber
                              ORDER BY trophycase_order ASC
                           "
                        );  // Execute
      while( $row= mysql_fetch_assoc( $newquery ) ) $alliteminfo[$row['trophycase_order']]= $row;  // Enumerate
      mysql_free_result( $newquery );  // Release
      

      $aForTemplate= array();
      for( $iItem= 0; $iItem< 25; $iItem++ )
         {
            if ($iItem != $alliteminfo[$iItem]['trophycase_order'])
               {
                  $aForTemplate['ICON'. $iItem]= '<a href="'. $phpbb_root_path. 'images/shop_icons/noicon.png'. $alliteminfo[$iItem]['icon']. '" onclick="window.open( this.href ); return false" title="'. $user-> lang['SHOP_HIGHSLIDE_CLICK']. '"><img src="'. $phpbb_root_path. 'images/shop_icons/noicon.png'. $alliteminfo[$iItem]['icon']. '" alt="'. $user-> lang['SHOP_HIGHSLIDE_CLICK']. '" /></a>';
               }
               
            else
               {
                  $aForTemplate['ICON'. $iItem]= '<a href="'. $phpbb_root_path. 'images/shop_icons/'. $alliteminfo[$iItem]['icon']. '" onclick="window.open( this.href ); return false" title="'. $user-> lang['SHOP_HIGHSLIDE_CLICK']. '"><img src="'. $phpbb_root_path. 'images/shop_icons/'. $alliteminfo[$iItem]['icon']. '" alt="'. $user-> lang['SHOP_HIGHSLIDE_CLICK']. '" /></a>';
               }
         
         }
      // Multiple values at once for the block "item_list"
      // Keep in mind that you're handing over an array which doesn't need to be built just here in place - it can be rendered earlier already with its keys and values
      $template-> assign_block_vars
      (
         'item_list'
      ,   $aForTemplate
      );
      
      
page_header($page_title);

page_footer();

?>



Thanks for all the help guys!
My Sports Forum: GG Sports
BlueCollar    
Cadet II
Cadet II
 
Posts: 23
Joined: 21 Mar 2011, 20:32
Gender: Male
phpBB Knowledge: 3


Return to phpBB3 Coding Assistance

Who is online

Users browsing this forum: No registered users and 11 guests