Jump to content

[SOLVED] Only the first word...


Germaris

Recommended Posts

Hi there !

 

I manage a directory of former students.

Among many functions, users can perform a search which returns the full identity of a friend.

In the MySQL table there's a row nammed firstName which can contain up to four names.

 

How can I modify my script in order to retrieve only the first name in the row i.e. the first word before a space?

 

Many thanks in advance for your help!

 

Best regards.

Link to comment
Share on other sites

Ouf !!!

 

I didn't expect so much replies !!!

Thank you, thank you, thank you !

 

BUT : I don't understand to use this treasure inside my script of which you'll find the interesting part below...

 

<?php
function hello($unlock,$username,$userpass)
{
if
($unlock < 1) print "Acces interdit.";
else {
	GLOBAL $db,$table;
	$username = trim($username);
	$password = md5(trim($userpass));
	$query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userPassword = '$password'") or die("&erreur=Connexion impossible avec la base de données de l'Annuaire."); 
	if ( mysql_num_rows( $query ) > 0) {
		while ($row =mysql_fetch_array ($query ) ) {
			$flashstr .= "Bonjour ".$row ["firstName" ]." !";
		}
		print "&prenomutilisateur=".$flashstr;
	}
	else {
		print "&prenomutilisateur=Bonjour, cher camarade !";
	}
}
}
?>

Link to comment
Share on other sites

<?php
function hello($unlock,$username,$userpass)
{
if
($unlock < 1) print "Acces interdit.";
else {
	GLOBAL $db,$table;
	$username = trim($username);
	$password = md5(trim($userpass));
	$query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userPassword = '$password'") or die("&erreur=Connexion impossible avec la base de données de l'Annuaire."); 
	if ( mysql_num_rows( $query ) > 0) {
		while ($row =mysql_fetch_array ($query ) ) {
			list($first) = explode(" ",$row['firstName']);
			$flashstr .= "Bonjour ".$first." !";
		}
		print "&prenomutilisateur=".$flashstr;
	}
	else {
		print "&prenomutilisateur=Bonjour, cher camarade !";
	}
}
}
?>

Link to comment
Share on other sites

<?php
function hello($unlock,$username,$userpass)
{
if($unlock < 1) {
	print "Acces interdit.";
} else {
	GLOBAL $db,$table;
	$username = trim($username);
	$password = md5(trim($userpass));
	$query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userPassword = '$password'") or die("&erreur=Connexion impossible avec la base de données de l'Annuaire."); 
	if ( mysql_num_rows( $query ) > 0) {
		while ($row =mysql_fetch_array ($query ) ) {
			list($first) = explode(" ",$row['firstName']);
			$flashstr .= "Bonjour ".$first." !";
		}
		print "&prenomutilisateur=".$flashstr;
	}
	else {
		print "&prenomutilisateur=Bonjour, cher camarade !";
	}
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.