Jump to content

mysql query and how to join


Aero77

Recommended Posts

I have two tables, where I need data from both, but I also need to count or sum the votes in one of the tables and make a variable like totalVotes. 

 

This is the current sql query I got which works, but it don't count

SELECT * FROM wp_links INNER JOIN wp_toplist ON wp_links.link_id=wp_toplist.link_id

Hope someone can help. Thanks for reading :)

Edited by Aero77
Link to comment
Share on other sites

nevermind I figured it out.

SELECT *, count(wp_toplist.link_id) AS totalVotes  FROM wp_toplist INNER JOIN wp_links ON wp_toplist.link_id=wp_links.link_id GROUP BY wp_toplist.link_id ORDER BY totalVotes DESC

is that okay you think or is there a better way ?

Link to comment
Share on other sites

Im making a wordpress toplist plugin. Each vote is a new entry in the database table called wp_toplist where I store the IP address for 12 hours or so. So to find out how many votes each site has on the list I count the records and group them by link id

 

From what I can see it seems to be working cause they sites are listed one by one with their total number of votes, unless I'm missing something

Edited by Aero77
Link to comment
Share on other sites

id	        mediumint(9)
link_id	        text	 
visitor_ip	varchar(15)
click_at	date
site_votes	text
on_page	        varchar(50)
link_id	        bigint(20)	No 	 	 
link_url	varchar(255)	No 	 	 
link_name	varchar(255)	No 	 	 
link_image	varchar(255)	No 	 	 
link_target	varchar(25)	No 	 	 
link_description	varchar(255)	No 	 	 
link_visible	varchar(20)	No 	Y 	 
link_owner	bigint(20)	No 	1 	 
link_rating	int(11)	No 	0 	 
link_updated	datetime	No 	0000-00-00 00:00:00 	 
link_rel	varchar(255)	No 	 	 
link_notes	mediumtext	No 	 	 
link_rss	varchar(255)

First one is wp_toplist and 2nd is wp_links

Edited by Aero77
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.