Thanks button

making a thanks button

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 1901 Views - Last Post: 29 November 2009 - 01:35 PM Rate Topic: -----

#1 doc1984  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 24-November 09

Thanks button

Posted 27 November 2009 - 12:49 PM

<?php
$con = mysql_connect("localhost","*****","test");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("*******", $con);

mysql_query("user (post_thanks_thanked_times)
VALUES ('+1')");

mysql_close($con);
?> 


Im trying to make a thanks button for vbulletin 4.0 this connects to the database what is good :) not sure on the plus 1 part but every time its clicked i want it to add one to the database.

Now my main problem what i hope you can help with is how to get it to know what user to thanks as the thanks button would bebelow each post i have looked at various coding scripts and the new vubulletin 4 variables and got no where so if you could help with what i need so it picks up the member to put the +1 on it would be great

Thanks

Mark

Is This A Good Question/Topic? 0
  • +

Replies To: Thanks button

#2 BGDeveloper  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 84
  • Joined: 01-April 09

Re: Thanks button

Posted 27 November 2009 - 01:33 PM

<?php
	$dbhost = '';
	$dbuser = '';
	$dbpass = '';
	$dbname = '';
	
	$connection = mysql_connect($dbhost, $dbuser, $dbpass);
	$db = mysql_select_db($dbname, $connection);
	
	$dbtable = 'vb_users'; // Change this to your table name.(Don't know it exactly)
	$user = ''; // Change this to your username, who'll get +1. I.E. $_SESSION['username'] or whatever is it.
	
	$sql = "UPDATE `{$dbtable}`
			SET `post_thanks_thanked_times`) = (`post_thanks_thanked_times`+1)
			WHERE `user` = '{$user}' LIMIT 1";
	
	print mysql_query($sql) ? 'Query success' : 'Query failed';
?>


Something like that. I've write some comments.
Hope it helps.
Was This Post Helpful? 0
  • +
  • -

#3 doc1984  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 24-November 09

Re: Thanks button

Posted 27 November 2009 - 02:42 PM

View PostBGDeveloper, on 27 Nov, 2009 - 12:33 PM, said:

<?php
	$dbhost = '';
	$dbuser = '';
	$dbpass = '';
	$dbname = '';
	
	$connection = mysql_connect($dbhost, $dbuser, $dbpass);
	$db = mysql_select_db($dbname, $connection);
	
	$dbtable = 'vb_users'; // Change this to your table name.(Don't know it exactly)
	$user = ''; // Change this to your username, who'll get +1. I.E. $_SESSION['username'] or whatever is it.
	
	$sql = "UPDATE `{$dbtable}`
			SET `post_thanks_thanked_times`) = (`post_thanks_thanked_times`+1)
			WHERE `user` = '{$user}' LIMIT 1";
	
	print mysql_query($sql) ? 'Query success' : 'Query failed';
?>


Something like that. I've write some comments.
Hope it helps.


Thanks that was a great help one question tho as the users use different user id i take it i will have to make all 1600 members a seperate button as they isnt no way for it to auto find the user id or name ?
Was This Post Helpful? 0
  • +
  • -

#4 doc1984  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 24-November 09

Re: Thanks button

Posted 27 November 2009 - 03:06 PM

<?php
	$dbhost = 'localhost';
	$dbuser = '*******_new';
	$dbpass = '*******';
	$dbname = '*******_new';
   
	$connection = mysql_connect($dbhost, $dbuser, $dbpass);
	$db = mysql_select_db($dbname, $connection);
   
	$dbtable = 'user'; // Change this to your table name.

(Don't know it exactly)
  $_username = 'doc'; // Change this to your username, who'll 

get +1. I.E. $_SESSION['username'] or whatever is it.
   
	$sql = "UPDATE `{$dbtable}`
			SET `post_thanks_thanked_times`) = 

(`post_thanks_thanked_times`+1)
			WHERE `user` = '{$user}' LIMIT 1";
   
	print mysql_query($sql) ? 'Query success' : 'Query 

failed';
?>



Keep getting failed ?

table gos like this

user > then it has userid and username

then i have post_thanks_thanked_times what is set as

INT lenghth / value 10 UNSIGNED not null deafult 0

Sorry to be ap ain and thanks for your time
Was This Post Helpful? 0
  • +
  • -

#5 BGDeveloper  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 84
  • Joined: 01-April 09

Re: Thanks button

Posted 27 November 2009 - 03:21 PM

Okay. I'll try to make it simple with explanations.

Let's say that you've already have the users info.
Each of them have a unique id.

Create a test file with a simple loop to test the script first.

<?php
	$dbhost = '';
	$dbuser = '';
	$dbpass = '';
	$dbname = '';
   
	$connection = mysql_connect($dbhost, $dbuser, $dbpass);
	$db = mysql_select_db($dbname, $connection);
	
	$sql = "SELECT * FROM `user`";
	$query = mysql_query($sql);
	
	while($row = mysql_fetch_array($query))
	{
		print "User ID:#{$row['userid']} - Username: <strong>{$row['username']}</strong> | Give a thank <a href='thank.php?user={$row['userid']}'>here</a>.<br/>";
	}
?>



With the code above, you create a simple query to print out all the users.(Just for the example).
Then you show the unique userid of each of them, among with the username and a unique link to give a "thanks".

Now that you have each unique link, we must create a file to process the data.(The first code I've posted').

<?php
$dbhost = '';
	$dbuser = '';
	$dbpass = '';
	$dbname = '';
   
	$connection = mysql_connect($dbhost, $dbuser, $dbpass);
	$db = mysql_select_db($dbname, $connection);
   
	$dbtable = 'user'; 
	$user = $_GET['user']; 
	
	if(is_numeric($user))
	{
	
		$sql = "UPDATE `{$dbtable}`
				SET `post_thanks_thanked_times`) = (`post_thanks_thanked_times`+1)
				WHERE `userid` = '{$user}' LIMIT 1";
	   
		print mysql_query($sql) ? 'Query success' : 'Query failed';
	}
?>



This code checks if the given Id is numeric, and if so then do a simple query, by updating the row field +1.

If there's something that you don't understand ask.
Sorry if there are any grammar errors. My english is not so good.

This post has been edited by BGDeveloper: 27 November 2009 - 03:23 PM

Was This Post Helpful? 1
  • +
  • -

#6 doc1984  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 24-November 09

Re: Thanks button

Posted 27 November 2009 - 03:37 PM

first part worked a treat
webaddress
gave me user=1 for me for example doc but the second part through an error sorry to be a pain and if this is to much i will understand if you say you cant help any more

This post has been edited by doc1984: 27 November 2009 - 03:56 PM

Was This Post Helpful? 0
  • +
  • -

#7 BGDeveloper  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 84
  • Joined: 01-April 09

Re: Thanks button

Posted 27 November 2009 - 03:52 PM

Okay, but please first rename the file name, so that only you can test it.

And as for the second script - paste the error here, so I can help you out.
Was This Post Helpful? 0
  • +
  • -

#8 doc1984  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 24-November 09

Re: Thanks button

Posted 27 November 2009 - 03:56 PM

View PostBGDeveloper, on 27 Nov, 2009 - 02:52 PM, said:

Okay, but please first

rename the file name, so that only you can test it.

And as for the second script - paste the error here, so I can help you out.


how can i find errors as all it says is query failed
Was This Post Helpful? 0
  • +
  • -

#9 BGDeveloper  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 84
  • Joined: 01-April 09

Re: Thanks button

Posted 27 November 2009 - 03:57 PM

print mysql_query($sql) ? 'Query success' : 'Query failed';


-->
print mysql_query($sql) ? 'Query success' : 'Query failed<br/>'.mysql_error();


Was This Post Helpful? 0
  • +
  • -

#10 doc1984  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 24-November 09

Re: Thanks button

Posted 27 November 2009 - 04:00 PM

View PostBGDeveloper, on 27 Nov, 2009 - 02:57 PM, said:

print mysql_query($sql) ? 'Query success' : 'Query failed';


-->
print mysql_query($sql) ? 'Query success' : 'Query failed<br/>'.mysql_error();



Query failed
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') = (`post_thanks_thanked_times`+1) WHERE `userid` = '1' LIMIT 1' at line 2 

Was This Post Helpful? 0
  • +
  • -

#11 BGDeveloper  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 84
  • Joined: 01-April 09

Re: Thanks button

Posted 27 November 2009 - 04:03 PM

Jesus... I've forget to remove a bracket.

Quote

SET `post_thanks_thanked_times`)

-->

Quote

SET `post_thanks_thanked_times`

Was This Post Helpful? 1
  • +
  • -

#12 doc1984  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 24-November 09

Re: Thanks button

Posted 27 November 2009 - 04:06 PM

View PostBGDeveloper, on 27 Nov, 2009 - 03:03 PM, said:

Jesus... I've forget to remove a bracket.

Quote

SET `post_thanks_thanked_times`)

-->

Quote

SET `post_thanks_thanked_times`


Thanks so much that was perfect and i owe you so much you got my domain if you ever need anything you know where to find me or on here

one question as im going to link it to a button can i hide the success page so the person that clicks it dont see that page at all and stays where they are :)
Was This Post Helpful? 0
  • +
  • -

#13 BGDeveloper  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 84
  • Joined: 01-April 09

Re: Thanks button

Posted 27 November 2009 - 04:10 PM

You can try to combine it with javascript.
A Pop-Up will be nice. Like the D.I.C. bot who pops up when you receive a message.
If the query is okay, you can show a link to close the pop-up and the user doesn't need to open the new page.
Was This Post Helpful? 0
  • +
  • -

#14 doc1984  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 24-November 09

Re: Thanks button

Posted 28 November 2009 - 06:46 AM

View PostBGDeveloper, on 27 Nov, 2009 - 03:10 PM, said:

You can try to combine it with javascript.
A Pop-Up will be nice. Like the D.I.C. bot who pops up when you receive a message.
If the query is okay, you can show a link to close the pop-up and the user doesn't need to open the new page.



Thanks for all your help there is one little question if you dont mind so it can display like here in post bit what code would i need would it be something like $show post_thanked_times or something under that users postbit
Was This Post Helpful? 0
  • +
  • -

#15 BGDeveloper  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 84
  • Joined: 01-April 09

Re: Thanks button

Posted 28 November 2009 - 09:34 AM

Okay, I've write you a simple function for this.
<?php
	function count_thanks($userid)
	{
		$sql = "SELECT COUNT(`post_thanks_thanked_times`) AS `thanks_count` FROM `users` WHERE `userid` = {$userid}";
		$query = mysql_query($sql);
		$result = mysql_fetch_array($query);
		
		return $result['thanks_count'];
	}
?>



All you have to do is to call it by parsing the user id.

Quote

print count_thanks($userid)

where $userid will be variable with each unique id. I hope you've got the idea.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2