Customizing SMF > SMF Coding Discussion

add to database

<< < (3/3)

Sorck:
Can I suggest that you rename 'shop_Dog' to 'shop_dog' so as to work with all of SMF's supported databases? A simple find and replace through your code along with with the appropriate ALTER TABLE query will solve it. :)


Wizard, you might want to consider using custom profile fields rather than manually adding to the user table. Not sure if you could hook into this from a mod or not though.

The Wizard:

--- Quote from: Sorck on July 31, 2012, 01:20:30 PM ---Can I suggest that you rename 'shop_Dog' to 'shop_dog' so as to work with all of SMF's supported databases? A simple find and replace through your code along with with the appropriate ALTER TABLE query will solve it. :)

--- End quote ---

Yes I will fix this and put the images in the right place. I just want to make all the parts work and then I will clean up the mess. Just so you know I'm trying to revamp a old shop item mod and those where the orginal code designers work.

The Wizard:
@SA

Those latest corrections worked like a charm. Thank you
I would like to thank everybody who helped on this.

Wiz

The Wizard:
This is the orginal database code that Arantor help me with. If anyone wants to take a stab at cleaning it up go for it.

Wiz




--- Code: ---<?php
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
   require_once(dirname(__FILE__) . '/SSI.php');
   
// Hmm... no SSI.php and no SMF?

elseif (!defined('SMF'))
   die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');

$smcFunc['db_add_column'](
   '{db_prefix}members',
   array(
      'name' => 'shop_Dog',
      'type' => 'text',
      'null' => false
   )
);

 $smcFunc['db_insert']($topicinfo['new_from'] == 0 ? 'ignore' : 'replace',
   '{db_prefix}shop_items',
   array(
     'name' => 'string-255', 'desc' => 'string-65534', 'price' => 'string-255', 'module' => 'string-255', 'Stock' => 'int', 'input_needed' => 'int', 'can_use_item' => 'int',
   ),
   array(
      'name' => 'Dog Image',
      'desc' => 'Show an image next to your posts',
      'price' => '100.00',
      'module' => 'Dog',
      'Stock' => '50',
      'input_needed' => '1',
      'can_use_item' => '1'
   )
);   
?>


--- End code ---

Sorck:
That database code doesn't create the shop_items table - you might want to create it unless you're getting it from another mod.

Also, might work better if the price was actually an int and put the price in at 100 times the value you currently use. It'll be much better if you ever want to sort by the price - sorting by a string results in 2.10 being after 121.00 even though it, as a number, is smaller.

Navigation

[0] Message Index

[*] Previous page

Go to full version