Jump to content

[SOLVED] Stumped on T_ECHO


mikwit

Recommended Posts

I've been doing php for a while now, I've just started using jquery/ajax, but this doesn't seem to be a problem with that.  I have a nasty problem that I've been trying to trouble shoot for the past couple hours and was wondering if an of you guys could help. The code in question is

function getAllVotes($number)
{
/**
Returns an array whose first element is likes and the second one is dislikes
**/
$votes = array();
$q = "SELECT * FROM entries WHERE number = $number";
$r = mysql_query($q);
if(mysql_num_rows($r)==1)//id found in the table
	{
	$row = mysql_fetch_assoc($r);
	$votes[0] = $row['likes'];
	$votes[1] = $row['dislikes'];
	}
return $votes;
}

$number = $_POST['id'];
$action = $_POST['action'];

if($action=='vote_up') //voting up
{

$q = "UPDATE wlu_main SET likes = likes+1 WHERE number = $number";
}
elseif($action=='vote_down') //voting down
{
$q = "UPDATE entries SET dislikes = dislikes+1 WHERE number = $number";
}

$r = mysql_query($q);
if($r) 
{
$votes = getAllVotes($number); //This is the error line
echo "Thats Awsome (".$votes[0].")  Thats terrible (".$votes[1] .")"; 
}
elseif(!$r)
{
echo "Failed!";
}

The page is an action for a javascript call thingy

the error I'm getting is Parse error: syntax error, unexpected T_ECHO ... on Line 39 (marked above).  Is there anything I missed?

If it helps the javascript used in calling it is

echo "<span class='votes' id='votes_count".$row['number']."'> <a href='javascript:;' class='vote_up' id='".$row['number']."'>Thats Awsome</a> ('".$row['likes'].")  <a href='javascript:;' class='vote_down' id='".$row['number']."'>Thats terrible </a>(".$row['dislikes'].")</span>";

And the whole thing is suppose to display "Thats awsome (4) Thats terrible (2)" with the number changing the mysql database when its clicked.

Thanks

Link to comment
https://forums.phpfreaks.com/topic/169292-solved-stumped-on-t_echo/
Share on other sites

Try this,

 

echo '<span class='votes' id='votes_count' .$row['number']. > <a href="javascript:;" class='vote_up' id="' .$row['number']. '">Thats Awsome</a> (' .$row['likes']. ')  <a href="javascript:;" class='vote_down' id=' .$row['number']. '>Thats terrible </a>(' .$row['dislikes']. ')</span>';

 

James.

Sorry,

 

This.

 

echo '<span class="votes" id="votes_count' .$row['number']. '"> <a href="javascript:;" class="vote_up" id="' .$row['number']. '">Thats Awsome</a> (' .$row['likes']. ')  <a href="javascript:;" class="vote_down" id=' .$row['number']. '>Thats terrible </a>(' .$row['dislikes']. ')</span>';

 

James.

Because the actual page loads up fine and its only when the javascript action calls on the action and then the action returns an error message where the updated information is I feel like it should be somewhere in the larger php file but i can't find anything wrong there.  wierd

Maybe if i post a abrv version of the main page that'll help someone.

<html>
<head>
<link rel="stylesheet" type="text/css" href="./css.css">
<script type='text/javascript' src='jquery.pack.js'></script>
<script type='text/javascript'>
$(function(){
$("a.vote_up").click(function(){
the_id = $(this).attr('id');
$("span#votes_count"+the_id).fadeOut("fast");

//the main ajax request
	$.ajax({
		type: "POST",
		data: "action=vote_up&id="+$(this).attr("id"),
		url: "votes.php",
		success: function(msg)
		{
			$("span#votes_count"+the_id).html(msg);	
			$("span#votes_count"+the_id).fadeIn();
		}
	});
});

$("a.vote_down").click(function(){
the_id = $(this).attr('id');


//the main ajax request
	$.ajax({
		type: "POST",
		data: "action=vote_down&id="+$(this).attr("id"),
		url: "votes.php",
		success: function(msg)
		{
			$("span#votes_count"+the_id).html(msg);
			$("span#votes_count"+the_id).fadeIn();		
		}
	});
});
});	
</script>
</head>
<body>

<?php $host  = "d***";
$username      = "***";
$password  = "***";
$database   = "***"; // Database name


mysql_connect($host,$username,$password);
@mysql_select_db($database);
$sql = 'SELECT * FROM `wlu_main` LIMIT 0, 30 '; 
$result = mysql_query($sql) or die('query:<br />'.mysql_error());
while ($row = mysql_fetch_assoc($result)){

echo '<b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b>
    <div class="contentb"><div>';
    echo nl2br($row['text']);
echo "<br />";
echo '<span class="votes" id="votes_count'.$row['number'].'"><a href="javascript:;" class="vote_up" id="'.$row['number'].'">Thats Awsome</a>(' .$row['likes']. ')  <a href="javascript:;" class="vote_down" id="' .$row['number']. '">Thats terrible </a>(' .$row['dislikes']. ')</span>';
echo '</div> </div>
<b class="b4"></b><b class="b3"></b><b class="b2"></b><b class="b1"></b>
<br />';

}

?>


</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.