SA-MP Forums Archive
[HELP] How to create table for house (MySQL) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] How to create table for house (MySQL) (/showthread.php?tid=470301)



[HELP] How to create table for house (MySQL) - MartiQ - 17.10.2013

Ok, it's noob question but I would like to know, what should i insert into table Houses with this structure in script?

pawn Код:
case MYSQL_LOAD_HOUSES: {
            mysql_store_result();
            new housed[16][128];
            while(mysql_fetch_row_format(string,"|"))
            {
                if(mysql_num_rows() == 0) continue;
                explode(housed, string, "|");
                new hid = strval(housed[0]);
               
                printf("Loading House Data id %i: %s", hid, string);
                HouseData[hid][hPos][0] = floatstr(housed[1]);
                HouseData[hid][hPos][1] = floatstr(housed[2]);
                HouseData[hid][hPos][2] = floatstr(housed[3]);
                HouseData[hid][hInterior] = strval(housed[4]);
                HouseData[hid][hExPos][0] = floatstr(housed[5]);
                HouseData[hid][hExPos][1] = floatstr(housed[6]);
                HouseData[hid][hExPos][2] = floatstr(housed[7]);
                HouseData[hid][hPrice] = strval(housed[8]);
                format(HouseData[hid][hOwner], MAX_PLAYER_NAME, housed[9]);
                HouseData[hid][hOwned] = strval(housed[10]);
                HouseData[hid][hRentable] = strval(housed[11]);
                HouseData[hid][hRentPrice] = strval(housed[12]);
                HouseData[hid][hLocked] = strval(housed[13]);
                HouseData[hid][hMoney] = strval(housed[14]);
                HouseData[hid][hRent] = strval(housed[15]);
                new area[TOTAL_ZONE_NAME];
                Get2DZone(area, TOTAL_ZONE_NAME, HouseData[hid][hPos][0],HouseData[hid][hPos][1],HouseData[hid][hPos][2]);
                if(HouseData[hid][hOwned] == TRUE && HouseData[hid][hRentable] == FALSE) {
                    format(string, sizeof(string), "%d %s", hid, area);
                    HouseStructure[hid] = Create3DTextLabel(string,0xDABAA6FF,HouseData[hid][hPos][0],HouseData[hid][hPos][1],HouseData[hid][hPos][2],40.0,0, 1);
                }
                else if(HouseData[hid][hOwned] == FALSE) {
                    format(string, sizeof(string), "%d %s\nPrice: $%i", hid, area, HouseData[hid][hPrice]);
                    HouseStructure[hid] = Create3DTextLabel(string,0x00BA00FF,HouseData[hid][hPos][0],HouseData[hid][hPos][1],HouseData[hid][hPos][2],40.0,0, 1);
                }
                else if(HouseData[hid][hOwned] == TRUE && HouseData[hid][hRentable] == TRUE) {
                    format(string, sizeof(string), "%d %s\nRent price: $%i", hid, area,HouseData[hid][hRentPrice]);
                    HouseStructure[hid] = Create3DTextLabel(string,0x00BAA6FF,HouseData[hid][hPos][0],HouseData[hid][hPos][1],HouseData[hid][hPos][2],40.0,0, 1);
                }
                #if defined ENABLE_ICONS
                HouseStructure2[hid] = CreateStreamedMapIcon(HouseData[hid][hPos][0],HouseData[hid][hPos][1],HouseData[hid][hPos][2], HOUSE_ICON_TYPE, 0);
                #endif
            //  HouseStructure[hid] = Create3DTextLabel(string,0x008080FF,HouseData[hid][hPos][0],HouseData[hid][hPos][1],HouseData[hid][hPos][2],40.0,0, 1);
            }
            mysql_free_result();
        }
With that I mean:

What should I add in database?

Код:
CREATE TABLE `houses` (
  `hId` int(11) NOT NULL AUTO_INCREMENT,
  `hPosX` varchar(128) NOT NULL,
  `hPosY` varchar(128) NOT NULL,
  `hPosZ` varchar(128) NOT NULL,
  `hPosRotX` varchar(128) NOT NULL,
  `hPosRotY` varchar(128) NOT NULL,
  `hPosRotZ` varchar(128) NOT NULL,
  PRIMARY KEY (`hId`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=latin1;



Re: [HELP] How to create table for house (MySQL) - MartiQ - 17.10.2013

Anyone?


Re: [HELP] How to create table for house (MySQL) - xganyx - 17.10.2013

I just learn about mysql yesterday but i think i can help

pawn Код:
mysql_query("CREATE TABLE IF NOT EXISTS `houses` (\
  `hId` int(11) NOT NULL AUTO_INCREMENT,\
  `hPosX` varchar(128) NOT NULL,\
  `hPosY` varchar(128) NOT NULL,\
  `hPosZ` varchar(128) NOT NULL,\
  `hPosRotX` varchar(128) NOT NULL,\
  `hPosRotY` varchar(128) NOT NULL,\
  `hPosRotZ` varchar(128) NOT NULL,\
  PRIMARY KEY (`hId`)\
  ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=latin1"
);



Re: [HELP] How to create table for house (MySQL) - TryCatch - 17.10.2013

Quote:
Originally Posted by xganyx
Посмотреть сообщение
I just learn about mysql yesterday but i think i can help

pawn Код:
mysql_query("CREATE TABLE IF NOT EXISTS `houses` (\
  `hId` int(11) NOT NULL AUTO_INCREMENT,\
  `hPosX` varchar(128) NOT NULL,\
  `hPosY` varchar(128) NOT NULL,\
  `hPosZ` varchar(128) NOT NULL,\
  `hPosRotX` varchar(128) NOT NULL,\
  `hPosRotY` varchar(128) NOT NULL,\
  `hPosRotZ` varchar(128) NOT NULL,\
  PRIMARY KEY (`hId`)\
  ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=latin1"
);
Yes something like that but you don't need to use varchar(12 for float data type. Maybe is better to you to create
table with phpmyadmin or adminer and then look on SQL command to figure out how thing works. This is the best advice if you want to learn something.