jhonnywg Posted July 28, 2004 Report Share Posted July 28, 2004 bem eu quria criar um obijedo de inclusão e exclusão do mysql alguém pode me ajudar??? Quote Link to comment Share on other sites More sharing options...
0 jhonnywg Posted July 28, 2004 Author Report Share Posted July 28, 2004 bem eu quria criar um obijedo de inclusão e exclusão do mysql alguém pode me ajudar??? tipo eu queria que no canpo do mysql nome que esta dentro de cadastro eu queria fazer um obijeto que fisese com que eu auterase e e excluise o nome selesionado Quote Link to comment Share on other sites More sharing options...
0 sadrack Posted July 28, 2004 Report Share Posted July 28, 2004 decida o que você quer fazer e poste .. pra podermos ajudar ... ! Quote Link to comment Share on other sites More sharing options...
0 gladiador Posted July 28, 2004 Report Share Posted July 28, 2004 /* Qual a duvida? qual seu conhecimento em bd se manja de banco ou não php ? pode ser mais específico ? */ Quote Link to comment Share on other sites More sharing options...
0 jhonnywg Posted July 29, 2004 Author Report Share Posted July 29, 2004 bem eu quria criar um obijedo de inclusão e exclusão do mysql alguém pode me ajudar??? sim meu manjo eu sei como fazer pra auterar e excluir tudo isso mais eu quero criar um abijeto que fasa isso pra mim e depois so chamar esse obijeto no meu escript Quote Link to comment Share on other sites More sharing options...
0 jhonnywg Posted July 29, 2004 Author Report Share Posted July 29, 2004 bem eu quria criar um obijedo de inclusão e exclusão do mysql alguém pode me ajudar??? sim meu manjo eu sei como fazer pra auterar e excluir tudo isso mais eu quero criar um abijeto que fasa isso pra mim e depois so chamar esse obijeto no meu escript esse e o codigo so que eu quero fazer um objeto de conexão e outro de auteração e exclusão etc,<? ######################################## # Função de execução de requisições SQL ######################################## function executaRequisicao($sql) { $conn = mysql_connect ("localhost","root","elaborata"); mysql_select_db ("aula09",$conn); $data = array (); $result = mysql_query ($sql,$conn); if (eregi ("select",$sql)) { while ($tmp = mysql_fetch_array ($result,1)) { $data[] = $tmp; } } else { $data = mysql_affected_rows ($conn); } mysql_close ($conn); return $data; } ####################### # Chaveamento de ações ####################### if (isset ($acao) && strlen ($acao)) { switch ($acao) { case "Incluir": if (strlen ($inc_nome) && strlen ($inc_idade)) { $tmp = executaRequisicao("insert into tCadastro (Nome,Idade) values ('".$inc_nome."',".$inc_idade.")"); } break; case "Excluir": if (strlen ($alt_id)) { $tmp = executaRequisicao("delete from tCadastro where Id=".$alt_id); } break; case "Alterar": if (strlen ($alt_id) && strlen ($alt_nome) && strlen ($alt_idade)) { $tmp = executaRequisicao("update tCadastro set Nome='".$alt_nome."',Idade=".$alt_idade." where Id=".$alt_id); } break; } } ################## # Layout de busca ################## $html_busca = ""; $registros = executaRequisicao("select * from tCadastro order by Id"); if (count ($registros)) { for ($i = 0; $i < count ($registros); $i++) { $html_busca_registros .= "\n <form action=cadastro.php method=post> <tr> <td align=center><input type=text name=alt_nome size=20 value=\"".$registros[$i]["Nome"]."\" class=texto_preto /></td> <td align=center><input type=text name=alt_idade size=3 value=\"".$registros[$i]["Idade"]."\" class=texto_preto /></td> <td align=center> <input type=hidden name=alt_id value=\"".$registros[$i]["Id"]."\" /> <input type=submit name=acao value=Alterar class=texto_preto /> <input type=submit name=acao value=Excluir class=texto_preto /> </td> </tr> </form>"; } $html_busca = "\n <table border=0 align=center> <tr> <td colspan=3 align=center bgcolor=#00F> <font class=texto_branco>Registros encontrados (".count ($registros).")</font> </td> </tr> <tr> <td align=center><font class=texto_preto>Nome</font></td> <td align=center><font class=texto_preto>Idade</font></td> <td align=center><font class=texto_preto>Ação</font></td> </tr> ".$html_busca_registros." </table>"; } ##################### # Layout de inclusão ##################### $html_inclusao = "\n <form action=cadastro.php method=post> <table border=0 align=center> <tr> <td colspan=2 align=center bgcolor=#00F> <font class=texto_branco>Novo registro</font> </td> </tr> <tr> <td align=right><font class=texto_preto>Nome:</font></td> <td><input type=text name=inc_nome size=20 class=texto_preto /></td> </tr> <tr> <td align=right><font class=texto_preto>Idade:</font></td> <td><input type=text name=inc_idade size=3 class=texto_preto /></td> </tr> <tr> <td colspan=2 align=center> <input type=submit name=acao value=Incluir class=texto_preto /> </td> </tr> </table> </form>"; ############### # Layout geral ############### $html = "\n <html> <head> <title>Cadastro</title> <style type=text/css> .texto_branco { font:bold 12px Arial; color:#FFF; } .texto_preto { font:bold 12px Arial; color:#000; } </style> </head> <body> ".$html_inclusao." ".$html_busca." </body> </html>"; print ($html); ?> Quote Link to comment Share on other sites More sharing options...
0 Guest - jhonny - Posted July 29, 2004 Report Share Posted July 29, 2004 bem eu quria criar um obijedo de inclusão e exclusão do mysql alguém pode me ajudar??? sim meu manjo eu sei como fazer pra auterar e excluir tudo isso mais eu quero criar um abijeto que fasa isso pra mim e depois so chamar esse obijeto no meu escript esse e o codigo so que eu quero fazer um objeto de conexão e outro de auteração e exclusão etc,<? ######################################## # Função de execução de requisições SQL ######################################## function executaRequisicao($sql) { $conn = mysql_connect ("localhost","root","elaborata"); mysql_select_db ("aula09",$conn); $data = array (); $result = mysql_query ($sql,$conn); if (eregi ("select",$sql)) { while ($tmp = mysql_fetch_array ($result,1)) { $data[] = $tmp; } } else { $data = mysql_affected_rows ($conn); } mysql_close ($conn); return $data; } ####################### # Chaveamento de ações ####################### if (isset ($acao) && strlen ($acao)) { switch ($acao) { case "Incluir": if (strlen ($inc_nome) && strlen ($inc_idade)) { $tmp = executaRequisicao("insert into tCadastro (Nome,Idade) values ('".$inc_nome."',".$inc_idade.")"); } break; case "Excluir": if (strlen ($alt_id)) { $tmp = executaRequisicao("delete from tCadastro where Id=".$alt_id); } break; case "Alterar": if (strlen ($alt_id) && strlen ($alt_nome) && strlen ($alt_idade)) { $tmp = executaRequisicao("update tCadastro set Nome='".$alt_nome."',Idade=".$alt_idade." where Id=".$alt_id); } break; } } ################## # Layout de busca ################## $html_busca = ""; $registros = executaRequisicao("select * from tCadastro order by Id"); if (count ($registros)) { for ($i = 0; $i < count ($registros); $i++) { $html_busca_registros .= "\n <form action=cadastro.php method=post> <tr> <td align=center><input type=text name=alt_nome size=20 value=\"".$registros[$i]["Nome"]."\" class=texto_preto /></td> <td align=center><input type=text name=alt_idade size=3 value=\"".$registros[$i]["Idade"]."\" class=texto_preto /></td> <td align=center> <input type=hidden name=alt_id value=\"".$registros[$i]["Id"]."\" /> <input type=submit name=acao value=Alterar class=texto_preto /> <input type=submit name=acao value=Excluir class=texto_preto /> </td> </tr> </form>"; } $html_busca = "\n <table border=0 align=center> <tr> <td colspan=3 align=center bgcolor=#00F> <font class=texto_branco>Registros encontrados (".count ($registros).")</font> </td> </tr> <tr> <td align=center><font class=texto_preto>Nome</font></td> <td align=center><font class=texto_preto>Idade</font></td> <td align=center><font class=texto_preto>Ação</font></td> </tr> ".$html_busca_registros." </table>"; } ##################### # Layout de inclusão ##################### $html_inclusao = "\n <form action=cadastro.php method=post> <table border=0 align=center> <tr> <td colspan=2 align=center bgcolor=#00F> <font class=texto_branco>Novo registro</font> </td> </tr> <tr> <td align=right><font class=texto_preto>Nome:</font></td> <td><input type=text name=inc_nome size=20 class=texto_preto /></td> </tr> <tr> <td align=right><font class=texto_preto>Idade:</font></td> <td><input type=text name=inc_idade size=3 class=texto_preto /></td> </tr> <tr> <td colspan=2 align=center> <input type=submit name=acao value=Incluir class=texto_preto /> </td> </tr> </table> </form>"; ############### # Layout geral ############### $html = "\n <html> <head> <title>Cadastro</title> <style type=text/css> .texto_branco { font:bold 12px Arial; color:#FFF; } .texto_preto { font:bold 12px Arial; color:#000; } </style> </head> <body> ".$html_inclusao." ".$html_busca." </body> </html>"; print ($html); ?> dai alguém pode me ajudar com pelo menos a criação do codigo da conexão ??? Quote Link to comment Share on other sites More sharing options...
Question
jhonnywg
bem eu quria criar um obijedo de inclusão e exclusão do mysql alguém pode me ajudar???
Link to comment
Share on other sites
6 answers to this question
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.