Scotty13 Posted May 6, 2012 Share Posted May 6, 2012 This just displays the username aka first name. I want it to also display the member’s last name and maiden name if they have one. /////// Mechanism to Display Real Name Next to Username - real name(username) //////////////////////////if ($firstname != "") {$mainNameLine = "$firstname $maidenname $lastname ($username)";$username = $firstname;} else {$mainNameLine = $username; $maidenname; $lastname;} I want to display maiden and last name along with the user name. I've tried everything I could think of. Any suggestions? Thanks,Scott Link to comment Share on other sites More sharing options...
ckrudelux Posted May 6, 2012 Share Posted May 6, 2012 (edited) To start with you can't use end of line like this. $mainNameLine = $username; $maidenname; $lastname; Should be like this.$mainNameLine = $username . $maidenname . $lastname; Also you maybe want some space between them? $mainNameLine = $username ." ". $maidenname ." ". $lastname; This is how you could add everything to one variable: //If firstname is not null set firstname else set usernameif($firstname)$mainNameLine = $firstname;else$mainNameLine = $username; //If maidenname is not null add maidennameif($maidenname)$mainNameLine .= " ".$maidenname; //If lastname is not null add lastnameif($lastname)$mainNameLine .= " ".$lastname; //If firstname is not null add usernameif($firstname)$mainNameLine .= " (".$username.")"; " .= " adds to the current value while " = " set the value. Edited May 6, 2012 by ckrudelux Link to comment Share on other sites More sharing options...
birbal Posted May 6, 2012 Share Posted May 6, 2012 (edited) $mainNameLine = $username ." ". $maidenname ." ". $lastname;it is fine. but it is best to not to use concatenate oprator where possible. it makes the code harder to read$mainNameLine = "$username $maidenname $lastname"; you can also interpolate variables for better readbility $mainNameLine = "{$username} {$maidenname} {$lastname}"; the obvious usage of concatenate oprator is when you need directly put the return value of a function in string or need to concat constant in string also if there is no sureity of existance of a variable it best to use isset(). without isset() if it does not exist it will throw a notice and will try to convert null to bool which behvaour is unpredictable. so it is avoidable Edited May 6, 2012 by birbal Link to comment Share on other sites More sharing options...
ckrudelux Posted May 6, 2012 Share Posted May 6, 2012 I guess this is a matter of taste but I would say that this makes the code harder to read. Using the {} makes it better but still messy. $mainNameLine = "$username $maidenname $lastname"; Why? Well then you start mixing other content in this string the variables gets harder to find by using the concatenate you make a clear mark on there data is located. Example: "Hello $username nice to see you again, you have $numMessages messages in you inbox latest one from $from do you want to view it?" "Hello ". $username ." nice to see you again, you have ". $numMessages ." messages in you inbox latest one from ". $from ." do you want to view it?" In the case of the this particular operation you are right in that your use case is more readable but in longer more complected once I prefer the one I used like the one in the example. Link to comment Share on other sites More sharing options...
Scotty13 Posted May 6, 2012 Author Share Posted May 6, 2012 Tried everything above and no errors, still just the username. Link to comment Share on other sites More sharing options...
birbal Posted May 6, 2012 Share Posted May 6, 2012 that is where interpolation make it easier, decent text editor distinguish the variable among the string by formatting it differently Link to comment Share on other sites More sharing options...
birbal Posted May 6, 2012 Share Posted May 6, 2012 Tried everything above and no errors, still just the username.can you post your current code? Link to comment Share on other sites More sharing options...
Scotty13 Posted May 6, 2012 Author Share Posted May 6, 2012 It maybe the myMembers_table.php I get this error when I test it... Success in database CONNECTION..... no TABLE created. You have problems in the system already, backtrack and debug! <?php require_once "connect_to_mysql.php"; print "Success in database CONNECTION.....<br />"; $result = "CREATE TABLE myMembers ( id int(11) NOT NULL auto_increment, username varchar(255) NOT NULL, firstname varchar(255) NOT NULL lastname varchar(255) NOT NULL, maidenname varchar(255) NULL, ) "; if (mysql_query($result)){ print "Success in TABLE creation!...... <br /><br /><b>That completes the table setup, now delete the file <br /> named 'create_Table.php' and you are ready to move on. Let us go!</b>"; } else { print "no TABLE created. You have problems in the system already, backtrack and debug!"; } exit(); ?> Thanks, Scott Link to comment Share on other sites More sharing options...
Ingolme Posted May 6, 2012 Share Posted May 6, 2012 You can use mysql_error() to see what the problem is. I think the problem is that you have a comma at the end of this line: maidenname varchar(255) NULL, Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now