Alpricc Posted June 7, 2012 at 12:01 PM Report Share #461166 Posted June 7, 2012 at 12:01 PM Boa tarde. Eu estou a elaborar um trabalho em que queria colocar um 'echo' na minha pagina em que escreve-se Bem Vindo (Primeiro e Ultimo Nome). So que eu na minha base de dados tenho o nome completo, existe alguma forma de restringir apenas da primeira letra até ao primeiro espaço e do ultimo espaço até ao ultimo caracter Exemplo: Nome na BD: Ana Claudia Simoes Pinto Ferreira Fernandes Mensagem do echo: Seja bem vindo (a) Ana Fernandes. Será que me podem ajudar? Cumprimentos Link to comment Share on other sites More sharing options...
pikax Posted June 7, 2012 at 12:08 PM Report Share #461168 Posted June 7, 2012 at 12:08 PM http://css-tricks.com/snippets/php/separate-first-and-last-name/ Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
Alpricc Posted June 7, 2012 at 12:18 PM Author Report Share #461169 Posted June 7, 2012 at 12:18 PM "Deprecated: Function split() is deprecated in" Nao percebo a origem deste erro :x Link to comment Share on other sites More sharing options...
pikax Posted June 7, 2012 at 12:29 PM Report Share #461170 Posted June 7, 2012 at 12:29 PM le os comentarios "Deprecated: Function split() is deprecated in" Nao percebo a origem deste erro :x http://pt.wiktionary.org/wiki/deprecated Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
Alpricc Posted June 7, 2012 at 12:34 PM Author Report Share #461172 Posted June 7, 2012 at 12:34 PM entao quer dizer que não dá? :o Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted June 7, 2012 at 12:36 PM Report Share #461173 Posted June 7, 2012 at 12:36 PM ja disse como fazer isso aqui: $name = explode(" ", "AAA BBB CCC DDD"); $result = reset($name)." ".end($name); IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Alpricc Posted June 7, 2012 at 12:44 PM Author Report Share #461174 Posted June 7, 2012 at 12:44 PM ja disse como fazer isso aqui: $name = explode(" ", "AAA BBB CCC DDD"); $result = reset($name)." ".end($name); Pode ser estupido, mas como é que ponho no lugar do AAA BBB CCC DDD a variavel? Eu coloquei assim $name='SELECT NomeProfessor FROM professores WHERE CodProf=\''.$_SESSION['cod'].'\''; $resultado=mysql_query($name,$liga); $welcome = explode(' ', ''.$resultado.''); $result = reset($welcome)." ".end($welcome); echo $result;" e deu-me um erro "Resource #3" peço desculpa por não compreender :x Link to comment Share on other sites More sharing options...
pikax Posted June 7, 2012 at 12:55 PM Report Share #461175 Posted June 7, 2012 at 12:55 PM (edited) $resultado=mysql_query($name,$liga); $welcome = explode(' ', ''.$resultado.''); a funcao mysql_query nao retorna uma string, mas sim um mysql resource! Edited June 7, 2012 at 12:56 PM by pikax Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted June 7, 2012 at 01:22 PM Report Share #461183 Posted June 7, 2012 at 01:22 PM (edited) $name="SELECT NomeProfessor FROM professores WHERE CodProf='{$_SESSION['cod']}'"; $resultado=mysql_query($name,$liga); $welcome = explode(' ', $resultado->fields['NomeProfessor']); // <--------------------- $result = reset($welcome)." ".end($welcome); echo $result; Edited June 7, 2012 at 01:23 PM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Alpricc Posted June 7, 2012 at 01:25 PM Author Report Share #461184 Posted June 7, 2012 at 01:25 PM entao tenho que por um mysql_fetch_array do $resultado?? $name="SELECT NomeProfessor FROM professores WHERE CodProf='{$_SESSION['cod']}'"; $resultado=mysql_query($name,$liga); $welcome = explode(' ', $resultado->fields['NomeProfessor']); // <--------------------- $result = reset($welcome)." ".end($welcome); echo $result; Desculpe mas nao percebi muito bem ! Nao se importa de explicar? Eu se colocar esse codigo nao me retorna nada! obrigado Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted June 7, 2012 at 01:30 PM Report Share #461186 Posted June 7, 2012 at 01:30 PM (edited) epa .. confundi as funções do mysql com a biblioteca que uso ... desculpa $name="SELECT NomeProfessor FROM professores WHERE CodProf='{$_SESSION['cod']}'"; $resultado=mysql_fetch_assoc(mysql_query($name,$liga)); $welcome = explode(' ', $resultado['NomeProfessor']); // <--------------------- $result = reset($welcome)." ".end($welcome); echo $result; Edited June 7, 2012 at 01:31 PM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Alpricc Posted June 7, 2012 at 01:34 PM Author Report Share #461187 Posted June 7, 2012 at 01:34 PM No nome "Ana Claudia Ferreira" so me está a escrever "Ana" ;x e não há problema quanto à confusao Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted June 7, 2012 at 01:43 PM Report Share #461189 Posted June 7, 2012 at 01:43 PM se dá isso é porque existe espaços no fim do nome ... altera esta linha $welcome = explode(' ', trim($resultado['NomeProfessor'])); // <--------------------- IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Alpricc Posted June 7, 2012 at 02:22 PM Author Report Share #461196 Posted June 7, 2012 at 02:22 PM Muito obrigado! 🙂 está a funcionar! Mas por exemplo no caso de outro nome qualquer que não tenha um espaço no fim vai funcionar na mesma? Link to comment Share on other sites More sharing options...
brunoais Posted June 7, 2012 at 02:28 PM Report Share #461197 Posted June 7, 2012 at 02:28 PM (edited) Muito obrigado! 🙂 está a funcionar! Mas por exemplo no caso de outro nome qualquer que não tenha um espaço no fim vai funcionar na mesma? Sim. O trim() trata disso. Ele, por predefinição, apaga os carateres brancos no inicio e no fim da string (mas não no meio). Edited June 7, 2012 at 02:29 PM by brunoais "[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31 Life is a genetically transmitted disease, induced by sex, with death rate of 100%. Link to comment Share on other sites More sharing options...
Alpricc Posted June 7, 2012 at 02:49 PM Author Report Share #461200 Posted June 7, 2012 at 02:49 PM Obrigado, é isso mesmo que eu queria! 🙂 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