Deleting a Name from Colum

Started by Cool, Feb 26, 2017, 08:58 AM

Previous topic - Next topic

Cool

as title says i want to know how i can delete only 1 name without losing full colum data

as you see there are 3 names so how i can delete only one name that is [VA]Noob

Cool


Thijn

You don't save them like that.

Anyways, you gotta split it, remove the element with the name you want, then concatenate them again. Have fun.

rulk

concatenate - to link things together.

I have just learnt a new word today.  Nobody in my immediate family have come across this word either.  Thanks chap, this will come in handy.
We are all god's children.

KAKAN

string concatenation - I've heard this term in the basics of many languages( all tbh, except some )
oh no

Cool

Quote from: Thijn on Feb 26, 2017, 03:11 PMYou don't save them like that.

Anyways, you gotta split it, remove the element with the name you want, then concatenate them again. Have fun.
@Thijn is there any disadvantage of it If yes i will separate them

Murdock

Quote from: happymint2 on Feb 26, 2017, 04:15 PM@Thijn is there any disadvantage of it If yes i will separate them

Learn about database normalization. The first normal form in database design states that "Multivalued attributes or composite attributes" are not allowed. Because it's a pain to manage, just like you're facing right now. I suggest you look into creating multiple tables and relationships between them.

Cool

@Thijn Like this i did not get your talk so i searched and finally got this you were talking about function like this
else if ( cmd == "removeclanuser" )
 {
 if ( player.Name != Admin ) MessagePlayer( "You're level is not high enough.", player );
 if ( PlayerCheckWithOutSpawn( player, cmd ) ) return 0;
 else if ( Stats[ player.ID ].Clan != null )
  {
  local
   Clan = Stats[ player.ID ].Clan,
   Tag = Stats[ player.ID ].ClanTag,
   ClaneState = Stats[ player.ID ].ClaneState;
  if ( ClaneState == "Owner" || ClaneState == "Leader1" || ClaneState == "Leader2" || ClaneState == "Leader3" )
   {
   local
    q = QuerySQL( Clans, "SELECT * FROM ClanMembers WHERE Clan LIKE '" + Clan + "' COLLATE NOCASE" ),
    Owner = GetSQLColumnData( q, 1 ),
    Leader1 = GetSQLColumnData( q, 2 ),
    Leader2 = GetSQLColumnData( q, 3 ),
    Leader3 = GetSQLColumnData( q, 4 ),
    Users = GetSQLColumnData( q, 5 );
   FreeSQLQuery( q );
   if ( !text ) MessagePlayer( "[SYNTAX ERROR] Usage: /"+cmd+" <Full-User-Nick>", player );
   else
    {
    local User = GetTok( text, " ", 1 );
    local Usere = Users.tolower().find( User.tolower() );
    if ( !Usere  ) MessagePlayer( "[ERROR] [ " + User + " ] is not member of this clan.", player );
    else
     {
     local Usera = JoinArray( split(""+Users+"", " "+Usere+" "), " ");
     FreeSQLQuery( QuerySQL( Clans, "UPDATE ClanMembers SET Users='"+Usera+"' WHERE Clan='" + Clan + "'COLLATE NOCASE" ) );
     MessagePlayer( "[CLAN-INFO] Removed Member:[ " + Usera + " ]: from Clan:[ " + Clan + " ].", player );
     }
    }
   }
  }
 }

Thijn

Yes, that's wrong.
Your tables should look like this:

Table: Clan
Column: Id
Column: Name

Table: ClanMember
Column: Id (Not really required, I just like a primary key)
Column ClanId
Column: Name
Column: Status (leader etc.?)

Then in order to remove a member, you remove his row on the ClanMember table. In order to add one, you insert into the ClanMember table.
Easy, right?

!

#9
Bump
looks like you need this function
This function was give to me by @jWeb
http://forum.vc-mp.org/?topic=4273.msg31614#msg31614
function SearchAndReplace(str, search, replace)
{
local li = 0, ci = str.find(search, li), res = "";
while (ci != null)
{
if (ci > 0)
{
res += str.slice(li, ci);
res += replace;
}
else res += replace;
li = ci + search.len(), ci = str.find(search, li);
}
if (str.len() > 0) res += str.slice(li);
return res;
}

//now get column data, remove the name and then update.
local string = "zeus khan killer";
local newstring = SearchAndReplace(string, " khan ", " ");
print(newstring);

Discord: zeus#5155