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 :)

Link to comment
https://forums.phpfreaks.com/topic/294965-mysql-query-and-how-to-join/
Share on other sites

The query syntax is correct but I don't believe that is what you want.

 

COUNT(link_id) with GROUP BY link_id will give every count total = 1. But as I said, there is no way of my knowing exactly what you are trying to achieve.

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

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

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.