[Rev 81] Storage and Itemmall structure

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

Re: [Rev 81] Storage and Itemmall structure

Postby Rifke on Thu Dec 06, 2007 10:34 pm

Yeh I interpreted this line :'UNIQUE KEY `ow_slot` (`owner`,`slotnum`)' wrong^^ my bad!
Rifke
Pero pero
Pero pero
 
Posts: 719
Joined: Thu Aug 09, 2007 3:01 pm
Location: Belgium

Re: [Rev 81] Storage and Itemmall structure

Postby lmame on Thu Dec 06, 2007 11:14 pm

No problem ;)
The world is full of love and peace ^_^
Image
User avatar
lmame
Admin
Admin
 
Posts: 8997
Joined: Mon Aug 06, 2007 4:42 pm
Location: July City

Re: [Rev 81] Storage and Itemmall structure

Postby Rifke on Sat Dec 08, 2007 12:00 am

  1.  
  2. function free_slot($owner,$slotnum) {
  3.     $sql = "SELECT owner FROM itemmall WHERE owner=%s AND slotnum=%s";
  4.     $sql = sprintf($sql,$owner,$slotnum);
  5.     $qry = @mysql_query($sql);
  6.     if ( $qry === false ) {
  7.         return false;
  8.     } elseif ( mysql_num_rows($qry) == 0 ) {
  9.         return true;
  10.     }
  11. }
  12.  
  13. for ( $i=0;$i<=150;$i++) {
  14.     if ( free_slot($owner_id,$i) === true ) {
  15.         $sql = "ADD item to itemmall";
  16.         break; // break through for-loop
  17.     }
  18. }
  19.  

Simple code


Anyway shouldn't we need to change the table 'itemmall' to mileage, so it wouldn't cause any conflict with the now known CMS -Systems?
Rifke
Pero pero
Pero pero
 
Posts: 719
Joined: Thu Aug 09, 2007 3:01 pm
Location: Belgium

Re: [Rev 81] Storage and Itemmall structure

Postby lmame on Sat Dec 08, 2007 12:19 am

Why not.

Just one thing, there are no 150 free slots in mileage, just 48:
  1.  
  2. #define MAX_STORAGE 160
  3. #define MAX_ITEMMALL 48
  4.  




Edit:
Why do you make a loop (so several queries), wouldn't be more simple to get the slotnum list for the owner (one query) and then just look for a free one inside?
The world is full of love and peace ^_^
Image
User avatar
lmame
Admin
Admin
 
Posts: 8997
Joined: Mon Aug 06, 2007 4:42 pm
Location: July City

Re: [Rev 81] Storage and Itemmall structure

Postby Rifke on Sat Dec 08, 2007 1:06 am

Yeh, as like
SELECT slotnum FROM itemmall WHERE owner='owner_id' AND slotnum IS NULL LIMIT 1

should get you the first free slot that mysql finds :)
Rifke
Pero pero
Pero pero
 
Posts: 719
Joined: Thu Aug 09, 2007 3:01 pm
Location: Belgium

Previous

Return to PHP / Web Guides, Scripts and tools.

Who is online

Users browsing this forum: No registered users and 3 guests

cron