Jump to content

Displays username, but not maiden or last name.


Scotty13

Recommended Posts

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

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 by ckrudelux
Link to comment
Share on other sites

$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 by birbal
Link to comment
Share on other sites

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

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

Tried everything above and no errors, still just the username.
can you post your current code?
Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...