Foros del Web » Programando para Internet » PHP »

Sugerencias boton me gusta php mysql

Estas en el tema de Sugerencias boton me gusta php mysql en el foro de PHP en Foros del Web. Hola a todos! Estoy haciendo un foro en el cual cuando un usuario esta viendo un tema,estoy creando que aparezca un boton me gusta tipo ...
  #1 (permalink)  
Antiguo 08/01/2011, 08:33
Avatar de ale_dla  
Fecha de Ingreso: abril-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 189
Antigüedad: 15 años
Puntos: 3
Sugerencias boton me gusta php mysql

Hola a todos!
Estoy haciendo un foro en el cual cuando un usuario esta viendo un tema,estoy creando que aparezca un boton me gusta tipo facebook o algo asi jeeje.
Bueno, tengo mi tabla en mysql que es esta:
Código PHP:
CREATE TABLE IF NOT EXISTS `topics` (
  `
topic_idint(8NOT NULL AUTO_INCREMENT,
  `
topic_subjectvarchar(255NOT NULL,
  `
topic_datetimestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `
topic_catint(8NOT NULL,
  `
topic_byint(8NOT NULL,
  `
topic_likes-usersint(11NOT NULL,
  
PRIMARY KEY (`topic_id`),
  
KEY `topic_cat` (`topic_cat`),
  
KEY `topic_by` (`topic_by`)
ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=
Y el codigo que tengo para ver un tema es este:
Código PHP:
<?php

include 'include/php/conexion.php';
//Conexion con la Base de Datos
$link=@dbConnect();
if (!
$link) {
    echo 
"Error conectando a la Base de Datos."
}

if (
$link =="202") {
    echo 
"Error seleccionando la Base de Datos.";
}
$sql "SELECT
            topic_id,
            topic_subject
        FROM
           topics
        WHERE
           topics.topic_id = " 
mysql_real_escape_string($_GET['id']);
            
$result mysql_query($sql); 



//Segundo

//obtiene el nombre
$datos mysql_fetch_row($result);

 
$title "$datos[1] | Web";
    include_once(
'./header.php');  
            
$result mysql_query($sql);
?>
 <div id="main">
  <div class="content">
<?php
 
echo '<br />';
$id $_GET['id'];


$sql "SELECT
            topic_id,
            topic_subject
        FROM
            topics
        WHERE
            topics.topic_id = " 
mysql_real_escape_string($_GET['id']);
            
$result mysql_query($sql);

if(!
$result)
{
    echo 
'The topic could not be displayed, please try again later.';
}
else
{
    if(
mysql_num_rows($result) == 0)
    {
        echo 
'Este tema no existe.';
    }
    else
    {
        while(
$row mysql_fetch_assoc($result))
        {
            
//muestro el tema
            
echo '
               <a href="#reply">Responder</a><br />
               <table class="topic" border="1">
                    <tr>
                        <th colspan="2">' 
$row['topic_subject'] . '</th>
                    </tr>'
;
        
            
            
$posts_sql "SELECT
                        posts.post_topic,
                        posts.post_content,
                        posts.post_date,
                        posts.post_by,
                        users.id,
                        users.username
                    FROM
                        posts
                    LEFT JOIN
                        users
                    ON
                        posts.post_by = users.id
                    WHERE
                        posts.post_topic = " 
mysql_real_escape_string($_GET['id']);
                        
            
$posts_result mysql_query($posts_sql);
            
            if(!
$posts_result)
            {
                echo 
'<tr><td>The posts could not be displayed, please try again later.</tr></td></table>';
            }
            else
            {
            
                while(
$posts_row mysql_fetch_assoc($posts_result))
                {
                    
    
                    echo 
'<tr class="topic-post">
                            <td class="user-post">'
;?><img src="http://www.forosdelweb.com/f18/users/<?php echo "$id"?>/pic1.jpg" alt="Ad" ><?php echo '<a href="http://www.forosdelweb.com/f18/profile/?id=' .$posts_row['id'] .'">' $posts_row['username'] . '</a><br/>' date('d-m-Y H:i'strtotime($posts_row['post_date'])) . '</td>
                            <td class="post-content">' 
html_entity_decode($posts_row['post_content']) . '</td>
                            </tr>
                            
                            '
;
                            
                echo 
'<tr>
                            <td><a href="like.php?id='
.$row['topic_id'].'" id="east" title="Me gusta"><img src="include/images/buttons/like.jpg"/></a></td>
                          </tr>'
;
                }
                
            }
            
            if(isset(
$_SESSION['id']))
            {
                
//show reply box
                
echo '<div id="reply"><tr><td colspan="2"><h2>Responder:</h2><br />
                    <form method="post" action="reply.php?id=' 
$row['topic_id'] . '">
                        <textarea name="reply-content"></textarea><br /><br />
                        <input type="submit" value="Submit reply" />
                    </form></td></tr></div>'
;
            }
            else
            {
                
                echo 
'<tr><td colspan=2>Tienes que <a href="http://www.forosdelweb.com/f18/login.php">inciar sesi&oacute;n</a> para responder. Si sos nuevo <a href="http://www.forosdelweb.com/f18/signup">reg&iacute;strate</a> gratis.';
            }
            
            
//fin de la tabla
            
echo '</table><br /><br />';
        }
    }
}

 
?>
</div></div>
<br />
<br />
<?php
include 'include/php/footer.php';
?>
Y mi codigo que seria el me gusta es like.php
Código PHP:
<?php

include 'include/php/conexion.php';
$title =" Me gusta | Web.com";
include 
'header.php';
//Conexion con la Base de Datos
$link=@dbConnect();
if (!
$link) {
    echo 
"Error conectando a la Base de Datos."
}

if (
$link =="202") {
    echo 
"Error seleccionando la Base de Datos.";
}

$id $_GET['id'];
  
if (isset(
$_SESSION['id'])) {
    
// Put stored session variables into local php variable
    
$id $_SESSION['id'];
    
$sql "INSERT INTO topics (topic_likes-user) VALUES (" $_SESSION['id'] . ")";
$query mysql_query($sql);
echo 
"Este tema te gusta";
}else{
    echo 
"Tienes que iniciar sesi&oacute;n.<br />";
}
?>
Lo que estoy intentando hacer es que se inserte en la tabla likes-users el id del usuario que le gusta el tema.
Quien pueda ayudarme se los agradezco!

Última edición por ale_dla; 08/01/2011 a las 08:39
  #2 (permalink)  
Antiguo 08/01/2011, 15:44
 
Fecha de Ingreso: diciembre-2010
Mensajes: 788
Antigüedad: 13 años, 4 meses
Puntos: 51
Respuesta: Sugerencias boton me gusta php mysql

Tenés que guardar el id de tema y el id de usuario, sinó perdés la referencia.
  #3 (permalink)  
Antiguo 08/01/2011, 15:57
Avatar de ale_dla  
Fecha de Ingreso: abril-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 189
Antigüedad: 15 años
Puntos: 3
Respuesta: Sugerencias boton me gusta php mysql

Muchas gracias walterdevel!
Saludos!
  #4 (permalink)  
Antiguo 08/01/2011, 16:29
Avatar de ale_dla  
Fecha de Ingreso: abril-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 189
Antigüedad: 15 años
Puntos: 3
Respuesta: Sugerencias boton me gusta php mysql

Por ejemplo si en un tema a 10 usuarios le gusta un tema, en la base de datos en la tabla tendria que modificar topic_likes-users en vez de int modificarlo por text para que me muestre a todos los usuarios que les gusta este tema osea mostrando el id del usuario?
Muchas gracias.

Etiquetas: usuarios, botones, foros
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 15:54.