Exclusão Mysql Simples
#1
Posted 30/08/2011, 12:58
no pequeno relatorio coloquei o seguinte código para excluir o registro:
<th width=50><a href='exclui_prop.php?id=$lista[p_id]'> Excluir</a><br></th>';
até aqui tudo bem, já esta passando o id para cada registro da listagem.
agora não consigo montar o delete.php
cheguei até aqui:
$lista[p_id] = $_GET ['p_id'];
$sql = mysql_query("DELETE FROM jos_propriedades WHERE $lista[p_id] ");
$resultado = mysql_query($sql)
or die ("Nao foi possivel realizar a exclusao dos dados.");
echo "<h1>A propriedade foi excluida com êxito!</h1>";
sempre exibe a mensagem de que não foi possível excluir, sei que é bem simples pois já li horrores... alguém por favor tem uma dica?
#2
Posted 30/08/2011, 13:45
No caso id
Ficando:
$lista[p_id] = $_GET ['id'];
$sql = mysql_query("DELETE FROM jos_propriedades WHERE $lista[p_id] ");
$resultado = mysql_query($sql)
or die ("Nao foi possivel realizar a exclusao dos dados.");
echo "<h1>A propriedade foi excluida com êxito!</h1>";
Valeu
- ericzao likes this
Quer conhecer um site Diferente?
FORA DA TELA
==================================================================
#3
Posted 30/08/2011, 13:58
fiz o que vc disse e exclui blz, so que está excluindo todos os registros e não apenas o que foi clicado, como se ele não estivesse obedecendo a ordem de excluir apenas um determinado id, onde será o meu erro ?
te alguma dica?
#4
Posted 30/08/2011, 15:04
Qual o resultado disto ?
***********************************************
Bachelor of Technology in Technology of Information, with great knowledge in Windows operating systems and Unix-Like (BSD, Ubuntu and Slackware), languages (PHP, JavaScript and MySQL), semantic (DHTML, Tableless, Ajax, MVC, OO) and analysis (manages projects based on PMI).
Developer in PHP, JAVA, Python, Objective-c MySQL, DHTML, CSS, JAVASCRIPT, JQUERY, JSON, SMARTY, MDB2, DOCTRINE, CAKEPHP. Linux desktop for work and MacOS. E-commerces, CRM and bussiness strategys
Love-me and be FREE use UniCes-Like .
#5
Posted 30/08/2011, 15:10
#6
Posted 30/08/2011, 15:22
Esse valor deve estar vindo vazio...
$id = $_GET['id'];
mysql_query("DELETE FROM jos_propriedades WHERE id = ".$id." ");
Você deve informar qual registro vc quer deletar em WHERE campo = valor
Abraços
***********************************************
Bachelor of Technology in Technology of Information, with great knowledge in Windows operating systems and Unix-Like (BSD, Ubuntu and Slackware), languages (PHP, JavaScript and MySQL), semantic (DHTML, Tableless, Ajax, MVC, OO) and analysis (manages projects based on PMI).
Developer in PHP, JAVA, Python, Objective-c MySQL, DHTML, CSS, JAVASCRIPT, JQUERY, JSON, SMARTY, MDB2, DOCTRINE, CAKEPHP. Linux desktop for work and MacOS. E-commerces, CRM and bussiness strategys
Love-me and be FREE use UniCes-Like .
#7
Posted 30/08/2011, 15:37
$lista[p_id] = $_GET ['id'];
$sql = mysql_query("DELETE FROM jos_propriedades WHERE p_id = ".$lista[p_id]." ");
$resultado = mysql_query($sql)a unica coisa é que aparece a mensagem de não foi possível excluir, quando na verdade deveria aparacer " excluído com sucesso".
tecnicamente falando, fica "feio" deixar sem a mensagem de excluído ou não?
#8
Posted 30/08/2011, 15:42
Outra coisa porque usar $list[] (um array) ?
***********************************************
Bachelor of Technology in Technology of Information, with great knowledge in Windows operating systems and Unix-Like (BSD, Ubuntu and Slackware), languages (PHP, JavaScript and MySQL), semantic (DHTML, Tableless, Ajax, MVC, OO) and analysis (manages projects based on PMI).
Developer in PHP, JAVA, Python, Objective-c MySQL, DHTML, CSS, JAVASCRIPT, JQUERY, JSON, SMARTY, MDB2, DOCTRINE, CAKEPHP. Linux desktop for work and MacOS. E-commerces, CRM and bussiness strategys
Love-me and be FREE use UniCes-Like .
#9
Posted 30/08/2011, 15:51
muito obrigado pela dica
#10
Posted 30/08/2011, 16:18
Quando vc clica ai neste link... ele escreve id= oque ?
***********************************************
Bachelor of Technology in Technology of Information, with great knowledge in Windows operating systems and Unix-Like (BSD, Ubuntu and Slackware), languages (PHP, JavaScript and MySQL), semantic (DHTML, Tableless, Ajax, MVC, OO) and analysis (manages projects based on PMI).
Developer in PHP, JAVA, Python, Objective-c MySQL, DHTML, CSS, JAVASCRIPT, JQUERY, JSON, SMARTY, MDB2, DOCTRINE, CAKEPHP. Linux desktop for work and MacOS. E-commerces, CRM and bussiness strategys
Love-me and be FREE use UniCes-Like .
#11
Posted 30/08/2011, 16:45
http://www.meusite.c...prop.php?id=171
http://www.meusite.c...prop.php?id=172
http://www.meusite.c...prop.php?id=173
e assim por diante ... isso aparece quando voce coloca o mouse em cima do link, e quando clica ele exclui o registro.
#12
Posted 30/08/2011, 17:01
Experimenta usar o comando
if(mysql_num_rows($resultado)){
echo "Linhas foram apagada";
}else{
echo "Nao foi excluido";
}
Este comando verifica se a sua consulta sql retornou alguma linha, só irá retornar qdo tiver o id, ou seja q foi encontrado e deletado
Valeu
Quer conhecer um site Diferente?
FORA DA TELA
==================================================================
#13
Posted 30/08/2011, 17:26
fazendo deste jeito ele continua excluindo o registro clicado, porém retorna um erro:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/httpd/htdocs/itrmunbr/exclui_prop.php on line 44
Nao foi excluido
linhas:
44 if(mysql_num_rows($resultado)){
45 echo "Linhas foram apagada";
46 }else{
47 echo "Nao foi excluido";
48 }
#14
Posted 30/08/2011, 17:31
Mostra o html com o link q vc clica a consulta sql e as msg que vc deseja dar
E tbm use a tag do forum code <>
Falou
Quer conhecer um site Diferente?
FORA DA TELA
==================================================================
#15
Posted 30/08/2011, 17:44
$sql = "SELECT * FROM jos_propriedades ORDER BY p_municipio";
//EXECUTA O COMANDO ACIMA
$res = mysql_query($sql);
//VERIFICA SE O COMANDO FOI EXECUTADO COM SUCESSO
if($res) {
//EXIBE PARA O USUARIO
echo "
<table
<tr>
<td>
<h3></h3>
</td>
<td>
<h3>Id</h3>
</td>
<td>
<h3>UF</h3>
</td>
<td>
<h3>Municipio</h3>
</td>
<td>
<h3>Distrito</h3>
</td>
<td>
<h3>Propriedade</h3>
</td>
<td>
<h3>Código INCRA</h3>
</td>
<td>
<h3>Matricula</h3>
</td>
<td>
<h3>CCIR</h3>
</td>
<td>
<h3>NIRF</h3>
</td>
<td>
<h3>Área Declarada</h3>
</td>
<td>
<h3>Valor Venal</h3>
</td>
<td>
<h3>Valor Terra Nua</h3>
</td>
<td>
<h3>Logradouro</h3>
</td>
<td>
<h3>Nº</h3>
</td>
<td>
<h3>Complemento</h3>
</td>
<td>
<h3>Cx Postal</h3>
</td>
<td>
<h3>Latitude</h3>
</td>
<td>
<h3>Longitude</h3>
</td>
<td>
<h3>Usuário</h3>
</td>
</tr>
";
while ($lista = mysql_fetch_array($res)){
echo "
<tr>
<td>
<a href='exclui_prop.php?id=$lista[p_id]'> Excluir</a><br>
<!-- HABILITAR QUANDO ESTIVER PRONTO
<a href='exibe_certificado.php' target='_blank'>Imprimir</a>
!-->
<!--<a href= 'exibe_certificado?id=".$lista['p_id']."'>
".$lista['p_id']."
</a>!-->
</td>
<td>
$lista[p_id]
</td>
<td>
$lista[p_uf]
</td>
<td>
$lista[p_municipio]
</td>
<td>
$lista[p_distrito]
</td>
<td>
$lista[p_nomePropriedade]
</td>
<td>
$lista[p_codIncra]
</td>
<td>
$lista[p_matricula]
</td>
<td>
$lista[p_ccir]
</td>
<td>
$lista[p_nirf]
</td>
<td>
$lista[p_areaDeclarada]
</td>
<td>
$lista[p_valorVenal]
</td>
<td>
$lista[p_valorTerraNua]
</td>
<td>
$lista[p_logradouro]
</td>
<td>
$lista[p_numero]
</td>
<td>
$lista[p_complemento]
</td>
<td>
$lista[p_cxPostal]
</td>
<td>
$lista[x]
</td>
<td>
$lista[y]
</td>
<td>
$lista[jos_cod_users]
</td>
</tr>
";
}//fecha o loop
echo "</table>";
}//fecha o if
else {
echo "Erro ao listar os dados!";
}
?>
abaixo o exclui.php que criei
<?php
/* Initialize Joomla framework */
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
/* Required Files */
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
/* To use Joomla's Database Class */
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');
/**************************************************/
// Your code starts here...
/**************************************************/
$db = & JFactory::getDBO();
$tb_prefix = "jos";
function get_username_list($db,$tb_prefix, $limit){
$query = "SELECT `username` FROM `{$tb_prefix}_users` order by id desc LIMIT {$limit}";
$db->setQuery($query);
$result = $db->loadObjectList();
return $result;
}
//Get the list of usernames
$usernames = get_username_list($db, $tb_prefix, 10);
foreach($usernames as $username){
//echo $username->username. "<br />";
}
$session =& JFactory::getSession();
$user=& JFactory::getUser();
$userid = $user->guest ? 'guest' : $user->id;
$lista[p_id] = $_GET ['id'];
$sql = mysql_query("DELETE FROM jos_propriedades WHERE p_id = ".$lista[p_id]." ");
$resultado = mysql_query($sql);
if(mysql_num_rows($resultado)){
echo "Linhas foram apagada";
}else{
echo "Nao foi excluido";
}
?>
amigos morcosfj1 e silici0 lembrando que sou designer trabalho fazendo templates para joomla, drupal, magento entre outros. chegar até aqui onde cheguei para mim não foi nada fácil já que 'programar' para nós é extremamente difícil. desde já agradeço pela atenção de vocês, já aprendi bastante e com certeza repassarei estes aprendizados com outros colegas.
abraço!
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)










