mforan Posted February 1, 2009 Share Posted February 1, 2009 just wondering if there is any plausible way to make this code smaller, for when i add new columns to the database i have to change this file every time in 2 places: $query = "INSERT INTO usersb SET fullname='$info[0]', email='$info[1]', cemail='$info[2]', username='$info[3]', password='$info[4]', squadname='$info[5]', lastclick='$info[6]', protection='$info[7]', rank='$info[8]', pop='$info[9]', tax='$info[10]', money='$info[11]', land='$info[12]', people='$info[13]', homes='$info[14]', farms='$info[15]', factories='$info[16]', hangars='$info[17]', turrets='$info[18]', repairbays='$info[19]', satellites='$info[20]', naval='$info[21]', art='$info[22]', lab='$info[23]', eb4='$info[24]', eb5='$info[25]', eb6='$info[26]', eb7='$info[27]', eb8='$info[28]', eb9='$info[29]', eb10='$info[30]', barren='$info[31]', createdate='$info[32]', freeland='$info[33]', alliance='$info[34]', logdate='$info[35]', networth='$info[36]', timer='$info[37]', messagecount='$info[38]', newscount='$info[39]', anewscount='$info[40]', t80='$info[41]', bmp='$info[42]', mi28='$info[43]', ah64='$info[44]', rah66='$info[45]', f16='$info[46]', f117='$info[47]', f22='$info[48]', b52='$info[49]', b2='$info[50]', icbm='$info[51]', bmls='$info[52]', nuke='$info[53]', custom1='$info[54]', u5='$info[55]', u6='$info[56]', u7='$info[57]', u8='$info[58]', u9='$info[59]', u10='$info[60]', t80a='$info[61]', bmpa='$info[62]', mi28a='$info[63]', ah64a='$info[64]', rah66a='$info[65]', f16a='$info[66]', f117a='$info[67]', f22a='$info[68]', b52a='$info[69]', b2a='$info[70]', icbma='$info[71]', bmlsa='$info[72]', nukea='$info[73]', custom1a='$info[74]', ua5='$info[75]', ua6='$info[76]', ua7='$info[77]', ua8='$info[78]', ua9='$info[79]', ua10='$info[80]', aid='$info[81]', power='$info[82]', banned='$info[83]', img='$info[84]', theme='$info[85]', premium='$info[86]', txn_id='$info[87]', admin='$info[88]', hacker='$info[89]', age='$info[90]', ros='$info[91]', breason='$info[92]', lastip='$info[93]', mteam='$info[94]', chatban='$info[95]', secret='$info[96]', vid='$info[97]', killedu='$info[98]', lostu='$info[99]', wonl='$info[100]', lostl='$info[101]', points='$info[102]', lostue='$info[103]', remail='$info[104]', killp='$info[105]', lasta='$info[106]', cuname='$info[107]', cuurl='$info[108]', cuap='$info[109]', cudp='$info[110]', country='$info[111]', rankno='$info[112]', reports='$info[113]', repip='$info[114]', whitel='$info[115]', ptrial='$info[116]', iemail='$info[117]', bank='$info[118]', bantimer='$info[119]' ON DUPLICATE KEY UPDATE fullname=VALUES(fullname), email=VALUES(email) , cemail=VALUES(cemail) , username=VALUES(username) , password=VALUES(password) , squadname=VALUES(squadname) , lastclick=VALUES(lastclick) , protection=VALUES(protection) , rank=VALUES(rank) , pop=VALUES(pop) , tax=VALUES(tax) , money=VALUES(money) , land=VALUES(land) , people=VALUES(people) , homes=VALUES(homes) , farms=VALUES(farms) , factories=VALUES(factories) , hangars=VALUES(hangars) , turrets=VALUES(turrets) , repairbays=VALUES(repairbays) , satellites=VALUES(satellites) , naval=VALUES(naval) , art=VALUES(art) , lab=VALUES(lab) , eb4=VALUES(eb4) , eb5=VALUES(eb5) , eb6=VALUES(eb6) , eb7=VALUES(eb7) , eb8=VALUES(eb8) , eb9=VALUES(eb9) , eb10=VALUES(eb10) , barren=VALUES(barren) , createdate=VALUES(createdate) , freeland=VALUES(freeland) , alliance=VALUES(alliance) , logdate=VALUES(logdate) , networth=VALUES(networth) , timer=VALUES(timer) , messagecount=VALUES(messagecount) , newscount=VALUES(newscount) , anewscount=VALUES(anewscount) , t80=VALUES(t80) , bmp=VALUES(bmp) , mi28=VALUES(mi28) , ah64=VALUES(ah64) , rah66=VALUES(rah66) , f16=VALUES(f16) , f117=VALUES(f117) , f22=VALUES(f22) , b52=VALUES(b52) , b2=VALUES(b2) , icbm=VALUES(icbm) , bmls=VALUES(bmls) , nuke=VALUES(nuke) , custom1=VALUES(custom1) , u5=VALUES(u5) , u6=VALUES(u6) , u7=VALUES(u7) , u8=VALUES(u8) , u9=VALUES(u9) , u10=VALUES(u10) , t80a=VALUES(t80a) , bmpa=VALUES(bmpa) , mi28a=VALUES(mi28a) , ah64a=VALUES(ah64a) , rah66a=VALUES(rah66a) , f16a=VALUES(f16a) , f117a=VALUES(f117a) , f22a=VALUES(f22a) , b52a=VALUES(b52a) , b2a=VALUES(b2a) , icbma=VALUES(icbma) , bmlsa=VALUES(bmlsa) , nukea=VALUES(nukea) , custom1a=VALUES(custom1a) , ua5=VALUES(ua5) , ua6=VALUES(ua6) , ua7=VALUES(ua7) , ua8=VALUES(ua8) , ua9=VALUES(ua9) , ua10=VALUES(ua10) , aid=VALUES(aid) , power=VALUES(power) , banned=VALUES(banned) , img=VALUES(img) , theme=VALUES(theme) , premium=VALUES(premium) , txn_id=VALUES(txn_id) , admin=VALUES(admin) , hacker=VALUES(hacker) , age=VALUES(age) , ros=VALUES(ros) , breason=VALUES(breason) , lastip=VALUES(lastip) , mteam=VALUES(mteam) , chatban=VALUES(chatban) , secret=VALUES(secret) , vid=VALUES(vid) , killedu=VALUES(killedu) , lostu=VALUES(lostu) , wonl=VALUES(wonl) , lostl=VALUES(lostl) , points=VALUES(points) , lostue=VALUES(lostue) , remail=VALUES(remail) , killp=VALUES(killp) , lasta=VALUES(lasta) , cuname=VALUES(cuname) , cuurl=VALUES(cuurl) , cuap=VALUES(cuap) , cudp=VALUES(cudp) , country=VALUES(country) , rankno=VALUES(rankno) , reports=VALUES(reports) , repip=VALUES(repip) , whitel=VALUES(whitel) , ptrial=VALUES(ptrial) , iemail=VALUES(iemail) , bank=VALUES(bank) , bantimer=VALUES(bantimer)"; mysql_query($query) or die("Error: ".mysql_error()); Quote Link to comment Share on other sites More sharing options...
mforan Posted February 1, 2009 Author Share Posted February 1, 2009 actually thinking about it.... how would i go about coping the data row into the other database table, but also if it already exsists, like overwrite. then i wouldn't have to update this code every time. Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 1, 2009 Share Posted February 1, 2009 You need to read on database normalization. Quote Link to comment Share on other sites More sharing options...
mforan Posted February 1, 2009 Author Share Posted February 1, 2009 well all it is, is when a person clears their account it backups everything they had prior to that action. simple as that really. abnormality's are the norm in this situation lmao. Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 1, 2009 Share Posted February 1, 2009 If it's just for backup, why not have a single TEXT field, and store serialized data in there? Quote Link to comment Share on other sites More sharing options...
mforan Posted February 1, 2009 Author Share Posted February 1, 2009 that sounds like a good idea, but how do you output all the entire row? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 1, 2009 Share Posted February 1, 2009 unserialize it and you get your variables back Quote Link to comment Share on other sites More sharing options...
mforan Posted February 2, 2009 Author Share Posted February 2, 2009 nono, is there a way to ouput SELECT * without specifing any column headers, in otherwords all columns. Quote Link to comment Share on other sites More sharing options...
gevans Posted February 2, 2009 Share Posted February 2, 2009 <?php $query = "SELECT * FROM your_table WHERE id= /*PUT ID HERE*/"; $result = mysql_query($query) or die(mysql_error()); $details = mysql_fetch_assoc($result); foreach($details as $key => $value) { echo "$key: $value<br />\n"; } Instead of echoing the values you can serialize them into an array for storage Quote Link to comment Share on other sites More sharing options...
mforan Posted February 2, 2009 Author Share Posted February 2, 2009 brilliant, works like a charm and is an easy way to backup. shall use this one oftern lol! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.