Foros del Web » Programando para Internet » PHP »

problema para update en mysql

Estas en el tema de problema para update en mysql en el foro de PHP en Foros del Web. buenas.... de antemano agradezco su ayuda para solucionar este problema. soy estudiante de php. como veran no me hayo mucho aun en ello. tengo un ...
  #1 (permalink)  
Antiguo 04/11/2008, 04:55
 
Fecha de Ingreso: agosto-2008
Mensajes: 367
Antigüedad: 15 años, 7 meses
Puntos: 5
problema para update en mysql

buenas.... de antemano agradezco su ayuda para solucionar este problema. soy estudiante de php. como veran no me hayo mucho aun en ello. tengo un problema con un contador de visitas incluido en mysql.. el lleva a cabo el conteo de visitas a cada pregunta. para asi luego poder calificar las preguntas por las mas consultadas y mostrarlas. lo que debo hacer es cada ves que una pregunta es consultada tomar de la tabla el campo contador de esa pregunta unicamente y sumarle uno. agradezco su ayuda.. el codigo es el sigiente ...

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<style type="text/css">
<!--
.Estilo7 {font-size: 17px; font-style: italic; font-weight: bold; }
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
body {
background-color: #00CC99;
}
-->
</style>
</head>
<?php
$dbhost='localhost';
$dbusername='root';
$dbuserpass='root';
$dbname='club';



mysql_connect ($dbhost, $dbusername, $dbuserpass) or die ("no se conecta a database");
mysql_select_db($dbname) or die("Cannot select database");
$res=mysql_query("SELECT * FROM `preguntas_frecuentes` ORDER BY contador DESC LIMIT 7 ") or die ("no seleciona datos");

$pre=mysql_result($res,0,0);
$pre1=mysql_result($res,0,1);
$pre2=mysql_result($res,0,2);
$pre3=mysql_result($res,1,0);
$pre4=mysql_result($res,1,1);
$pre5=mysql_result($res,1,2);
$pre6=mysql_result($res,2,0);
$pre7=mysql_result($res,2,1);
$pre8=mysql_result($res,2,2);
$pre9=mysql_result($res,3,0);
$pre10=mysql_result($res,3,1);
$pre11=mysql_result($res,3,2);
$pre12=mysql_result($res,4,0);
$pre13=mysql_result($res,4,1);
$pre14=mysql_result($res,4,2);
$pre15=mysql_result($res,5,0);
$pre16=mysql_result($res,5,1);
$pre17=mysql_result($res,5,2);
$pre18=mysql_result($res,6,0);
$pre19=mysql_result($res,6,1);
$pre20=mysql_result($res,6,2);

//el contador a la pregunta 1, seria $pre2 a este tengo que incrementarle uno al momento de seleccionar la pregunta y actualizar el campo de la tabla de esa linea unicamente. sumandole uno. muchas gracias

?>

<body>
<table width="873" height="802" border="1" align="center">
<tr>
<td width="863" height="796" valign="top" bgcolor="#D0DECF"><table width="807" height="80" border="0" align="center">
<tr>
<td width="705" height="76" valign="middle"><table width="805" height="97" border="0">
<tr>
<td width="171" height="93">&nbsp;</td>
<td width="519"><img src="/img/jVmdxC.gif" alt="Bienvenido" width="468" height="60" /></td>
<td width="101"><img src="/img/logut.png" width="87" height="20" /></td>
</tr>
</table></td>
</tr>
</table>
<table width="815" border="0
">
<tr>
<td>&nbsp;</td>
</tr>
</table>
<table width="817" border="0">
<tr>
<td width="58">&nbsp;</td>
<td width="749"><img src="/img/marco.png" width="45" height="35" /><img src="/img/marco.png" alt="marc" width="45" height="35" /><img src="/img/historia.png" alt="his" width="103" height="35" /><img src="/img/vision.png" alt="visi" width="148" height="35" /><img src="/img/mision.png" alt="misi" width="151" height="35" /><img src="/img/contactenos.png" alt="con" width="151" height="35" /><img src="/img/marco.png" alt="marco" width="45" height="35" /><img src="/img/marco.png" alt="marc" width="45" height="35" /></td>
</tr>
</table>

<table width="857" height="518" border="0">
<tr>
<td width="851" valign="top"><table width="855" height="56" border="0">
<tr>
<td width="159" height="52">&nbsp;</td>
<td width="158"><img src="file:///F|/Sitio sin nombre 1/img/tel.png" width="160" height="25" alt="telefono" /></td>
<td width="524"><img src="file:///F|/Sitio sin nombre 1/img/email.png" width="350" height="25" /></td>
</tr>
</table>
<table width="711" height="472" border="0" align="right">
<tr>
<td width="516" height="20" align="center">Preguntas</td>
<td width="172" align="center">visitas</td>
<td width="9" rowspan="3">&nbsp;</td>
</tr>
<tr>
<td height="9" align="center"><a href="ind.log.faq.res1.php"><? echo $pre ?></a></td>
<td width="172" align="center"><?php echo $pre2 ?></td>
</tr>
<tr>
<td height="75" align="center"><?php echo $pre1 ?></td>
<td width="172" align="center">&nbsp;</td>
</tr>
<tr>
<td height="47" align="center"><A HREF="ind.log.faq.res2.php"><? echo $pre3 ?> </A></td>
<td height="47" align="center"><?php echo $pre5 ?></td>
<td rowspan="6">&nbsp;</td>
</tr>
<tr>
<td height="44" align="center"><A HREF="ind.log.faq.res3.php"><? echo $pre6 ?> </A></td>
<td height="44" align="center"><?php echo $pre8 ?></td>
</tr>
<tr>
<td height="63" align="center"><A HREF="ind.log.faq.res4.php"><? echo $pre9 ?> </A></td>
<td height="63" align="center"><?php echo $pre11 ?></td>
</tr>
<tr>
<td height="58" align="center"><A HREF="ind.log.faq.res5.php"><? echo $pre12 ?> </A></td>
<td height="58" align="center"><?php echo $pre14 ?></td>
</tr>
<tr>
<td height="46" align="center"><A HREF="ind.log.faq.res6.php"><? echo $pre15 ?> </A></td>
<td height="46" align="center"><?php echo $pre17 ?></td>
</tr>
<tr>
<td height="59" align="center"><A HREF="ind.log.faq.res7.php"><? echo $pre18 ?> </A></td>
<td height="59" align="center"><?php echo $pre20 ?></td>
</tr>
</table>
<table width="142" height="320" border="0" bgcolor="#D0DECF">
<tr>
<td width="136"bgcolor="#D0DECF"><a href="../ind.log.actividades.php" target="_self"><img src="/img/actividades.png" width="135" height="20" border="0" /></a></td>
</tr>
<tr>
<td><a href="../ind.log.noticias.php" target="_self"><img src="/img/noticias.png" width="134" height="20" border="0" /></a></td>
</tr>
<tr>
<td><a href="..ind.log.consejo.php" target="_self"><img src="/img/dejeconsejo.png" width="133" height="20" border="0" /></a></td>
</tr>
<tr>
<td><a href="../ind.log.faq.php" target="_self"><img src="/img/FAQ.png" width="86" height="20" border="0"/></a></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p></td>
</tr>
</table>
<p>&nbsp;</p>
<table width="863" border="0">
<tr>
<td width="748" height="44">&nbsp;</td>
<td width="150"><img src="file:///F|/Sitio sin nombre 1/img/ugudesign.png" width="150" height="40" /></td>
</tr>
</table> <p>&nbsp;</p></td>
</tr>
</table>
</body>
</html>
  #2 (permalink)  
Antiguo 04/11/2008, 20:59
 
Fecha de Ingreso: septiembre-2006
Ubicación: Buenos Aires
Mensajes: 53
Antigüedad: 17 años, 6 meses
Puntos: 0
Respuesta: problema para update en mysql

Por empezar, no entiendo por qué te enliaste tanto usando mysql_result, si total, el limite ya lo pusite con limit. ¿Por qué no usas mysql_fetch_array haciendo una iteracion con while? es decir:

while($fila=mysql_fetch_array($res)){
?>
<tr>
<td height="58" align="center"><A HREF="faqs.php?id=<?=$fila[id]?>"><?=$fila[nombre del campo]?> </A></td>
<td height="58" align="center"><?=$fila[nobre del campo]?></td>
</tr>
<?
}
mysql_free_result($res);

Tu metodo es funcional solo si siempre va a haber la misma cantidad de preguntas (faqs) al menos que siempre muestres 7 resultados por pagina.

Como sea..., la suma la vas a poder realizar una vez que entren a la pagina de la pregunta, lo cual podes hacer facilmente:

mysql_query("Update preguntas_frecuentes Set contador=contador+1 where id=''$id de la pregunta") or die(mysql_error());
__________________
mysql_query("SELECT * FROM Intenet WHERE "Una pagina de verdad" ORDER BY id ASC");
  #3 (permalink)  
Antiguo 04/11/2008, 21:03
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 15 años, 11 meses
Puntos: 2534
Respuesta: problema para update en mysql

un mal diseño del software trae consigo muchos problemas...

tan solo eso opino, de ver tanto spaghetti aquí...
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:44.