KyleH112 Posted October 25, 2014 Share Posted October 25, 2014 (edited) I'm trying to add the gang tag of players onto their username in header.php ive tried everything and need some help. I've tried all the $r, $ir combinations, i've tried $tag, $gtag, ['$gtag'] ['gangPREF']. Do I need to call to the database? Edited October 25, 2014 by KyleH112 Quote Link to comment Share on other sites More sharing options...
Veramys Posted October 25, 2014 Share Posted October 25, 2014 Yes you'll need to call to the database. Quote Link to comment Share on other sites More sharing options...
SRB Posted October 26, 2014 Share Posted October 26, 2014 I was almost tempted to post the way to do this, but then I see an x10 domain. Kind of can't bring myself to invest time into a game on a free domain as if an owner can't invest in a domain, how can I invest in them? May want to consider upgrading that. Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted October 26, 2014 Share Posted October 26, 2014 First ask yourself this..Is the gang tag selected by the query that is using the $ir, $r variable? If not than that would not be the $var used. Quote Link to comment Share on other sites More sharing options...
Tangled Posted October 26, 2014 Share Posted October 26, 2014 I'd like to know how to do this also Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted October 26, 2014 Share Posted October 26, 2014 Select the gang tag from gangs where the gang id equals your gang and while the result is true fetch the data and echo it out 1 Quote Link to comment Share on other sites More sharing options...
Zettieee Posted October 26, 2014 Share Posted October 26, 2014 left join on gangs with u.id then collect gangtag and just add $gtag before $_user['username'] echo. Really guys if you cant collect basic info from a database you shouldn't own a game :( Quote Link to comment Share on other sites More sharing options...
SRB Posted October 26, 2014 Share Posted October 26, 2014 left join on gangs with u.id then collect gangtag and just add $gtag before $_user['username'] echo. Really guys if you cant collect basic info from a database you shouldn't own a game :( For, I believe, the first time ever, I feel the need to direct my comments to you, Zettieee. Why are we left joining? We just need a join, period. You must have a different version of Mc Code, since Mc Code uses userid and not id. gangtag also doesn't exist. It's gangPREF[ix] Not sure where the $gtag came from, but seems irrelevant to the cause right no. I feel a brief comment like the following would have been shorter, easier to understand AND would have offered more insight. You need to cross reference the gang system for the tag, using a join, then echo the result to the page. Now, if you wanted to be really constructive, you could have done something like; ------------------------------------------------------------------------------------------ First thing first, you need to pull the data from the database by joining the data (Or even an additional query - not what I would suggest). For an example, if your initial query looked like; SELECT * FROM users JOIN userstats USING (userid) WHERE userid = x You would change it to something like; SELECT *, gangPREF FROM users JOIN userstats USING (userid) JOIN gangs ON gang = gangID WHERE userid = x The above code will call the gang tag (gangPREF) within the query, which could then be used with something along the lines of; if (strlen($ir['gangPREF'])) { echo '[' . $ir['gangPREF'] . ']'; } ------------------------------------------------------------------------------------------ Of course, why that is par for the course, I'd suggest slight changes. Since $ir is always defined, I'd probably just do a check with a second query. if ($ir['gang']) { $sql = "SELECT gangPREF FROM gangs WHERE gangID = " . $ir['userid']; // You won't use this, I'm sure. It's a DB class I use. $result = $db->fetchRow($sql); echo '[' . $ir['gangPREF'] . ']'; } Why would you do a second call!? I would assume most people using Mc Code are still using MyIsam databases, which means for the duration of the joined query, both tables are locked. If you're using InnoDB, that is row level locking, so the hit isn't so bad; --- I'd also use htmlentities() around the output, with ENT_QUOTES and "UTF-8" as the second and third parameters. That said, if you're not using global UTF8 encoding, I'd let it use whatever it's using as mixing charsets can cause some pretty poor results (£ signs turning into square blocks etc) --- With all that said, when making comments such as "If you can't deal with a database, don't run a site", expect a reply such as "If you can't offer advice without substance, stick to the shadows" Quote Link to comment Share on other sites More sharing options...
Zettieee Posted October 26, 2014 Share Posted October 26, 2014 O.o! It has been many years since I used mcc :( I thought Gangid and gang members used different id's to get the users who are in the gang? Someone feel like sending me a copy? :O Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted October 26, 2014 Share Posted October 26, 2014 Also sometimes it helps to check your own work, such checking why you would have used $ir or $r in the first place, just because in mccodes those two are the main $vars from two different queries, doesn't mean they are joined with the gang table, so you first want to look at if they are selecting the gang tag or joined to the gang table. If not than you will have to join the gang table to the users table, or go by another method such example using $ir var.... a=$db->query("SELECT gangPREF FROM gangs WHERE gangID='".$ir['gang']."'"); $b=$db->fetch_row($a); echo ''.$b['gangPREF'].''; Quote Link to comment Share on other sites More sharing options...
SRB Posted October 26, 2014 Share Posted October 26, 2014 Also sometimes it helps to check your own work, such checking why you would have used $ir or $r in the first place, just because in mccodes those two are the main $vars from two different queries, doesn't mean they are joined with the gang table, so you first want to look at if they are selecting the gang tag or joined to the gang table. If not than you will have to join the gang table to the users table, or go by another method such example using $ir var.... a=$db->query("SELECT gangPREF FROM gangs WHERE gangID='".$ir['gang']."'"); $b=$db->fetch_row($a); echo ''.$b['gangPREF'].''; Exactly what this guy said! Wait, what did this guy just say!? Quote Link to comment Share on other sites More sharing options...
KyleH112 Posted November 8, 2014 Author Share Posted November 8, 2014 Thanks guys, I got it working. The x10 domain is of my first game I made, kind of a learning experience while I was in Iraq, I had a lot of down time so I decided to start a new hobby. I'm currently working on a new project and im using hosting24. I was almost tempted to post the way to do this, but then I see an x10 domain. Kind of can't bring myself to invest time into a game on a free domain as if an owner can't invest in a domain, how can I invest in them? May want to consider upgrading that. Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted November 12, 2014 Share Posted November 12, 2014 Guest? I love you ^.^ Your comments are always helpful in some way - even if it just makes me smile :P Marry me pl0x? ^,^ 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.