Hey Guys,
Ok here is my problem:
There is around 350 rows in the db.
All the variables $actor_id, $comment_id and $likes_id are all uid's for facebook users
Now i want to group and sum how many entries there are of each unique uid
Say for example the number:
'65653171' came up
10 times as a $actor_id
5 times as a $comment_id
3 times as a $likes_id
and
'67418530' came up
5 times as a $actor_id
21 times as a $comment_id
3 times as a $likes_id
Then i want a query that would display in order of most entries:
1.) 67418530 (29)
2.) 65653171 (18)
Thanks for the help, real brain teazer for me. This is the code i use to fetch the Data from the FQL Table, a preview of the FQL Table can been seen on the bottom of this thread. - $query = "SELECT post_id, actor_id, comments, likes FROM stream WHERE source_id = ".$user." LIMIT 500";
-
$result = mysql_query($query);
-
$count = count($result);
-
$total=$count;
-
-
-
for ($i = 0; $i < $count; $i++)
-
{
-
-
$actor_id = $result[$i][actor_id];
-
$count_c = $result[$i][comments][count];
-
-
if($count_c > 0){
-
for ($a = 0; $a < $count_c; $a++){
-
$comment_id = $result[$i][comments][comment_list][$a][fromid];
-
-
}
-
}
-
-
-
$count_l = $result[$i][likes][count];
-
-
if($count_l > 0){
-
for ($b = 0; $b < $count_l; $b++){
-
$likes_id = $result[$i][likes][friends][$b];
-
-
}
-
}
-
-
-
-
-
}
This is how the information is stored in the DB 1 3196 TheServant 1,168
Recognized Expert Top Contributor
I am assuming that it will grow beyond 350 rows.
Besides making a rediculous query with lots of filtering you can't do this in one step. It would be way too resource intensive even if you could if it greew to say 10,000 rows.
I suggest this:
Have another column called entry_totalizer or something and then you can ORDER BY that and display that instead of doing a whole lot of COUNTing. Every time a comment_id or actor_id etc is entered, a filter can add one to the entry_totalizer .
With the ones that you already have, you might need to write a simple script to update those already in the table by searching for the empty ones and then doing the math and updating the value for each. If you are worried about resources, LIMIT it to 50 at a time, but I suspect that only having 350 will not be a problem.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: James |
last post by:
HI,
I'm looking for a script that will allow users/admins to have a one
click backup solution for a MYSQL Database..
'BACK DATABASE' button, click and its done...
The a restore option, that shows all current backups, and restores the
selected one with one click...
|
by: Philip Stoev |
last post by:
Hi all,
Please tell me if any of this makes sense. Any pointers to relevant
projects/articles will be much appreciated.
Philip Stoev
http://www.stoev.org/pivot/manifest.htm
===================================
|
by: Mike Chirico |
last post by:
Interesting Things to Know about MySQL
Mike Chirico (mchirico@users.sourceforge.net)
Copyright (GPU Free Documentation License) 2004
Last Updated: Mon Jun 7 10:37:28 EDT 2004
The latest version of this document can be found at:
http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
|
by: Ross Contino |
last post by:
Hello to all:
I have been searching the web for examples on how to determine a median
value in a mySQL table. I have reviewed the article at
http://mysql.progen.com.tr/doc/en/Group_by_functions.html. I am an
experienced VB programmer that has recently moved to PHP/mySQL. My employer
has a text file outputted from a vendor specific software with data.
However it cannot be manipulated because it is text. I created a web that
reads the...
|
by: Ljoha |
last post by:
I need to create report where will be shown total quantity of all rows
for every hour in some data range.
I have a table where I have column in DATETIME format. I have problem
to create sql query where I have to get result of the all counts for
every hour of the date range.
Something like that:
from starting hour to final hour = total row count (if there is an
entries),
from 01:00 to 02:00 = 5,
| |
by: jlee |
last post by:
I'm pretty much a newbie on mysql, and I need some help.
I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4
(i386) on a server hosting an active website.
The site's developer uses his own php shopping cart to receive customer
orders.
The configuration was done via cPanel with no external modifications -
which produced no protests when built, ran and connected with no
|
by: dottty |
last post by:
Hi,
i have a table that has the following fields:
id, name, dept, pay
1, John, Sales, 4000
2, Peter, HR, 5000
etc.
How do i count how many people there are in each dept with an sql query?
I find this surprisingly difficult, given the fact that i can sum the total
|
by: ojorus |
last post by:
Hi!
My company make several flash-based games, and I use php to communicate with
mysql to provide highscore-lists.
My problem is this:
When I save a player's score in the mysql-table, I want to find which place
the player got with his score (today). To get this I have tried two
different solutions, which both works, but are very ineffective: (The
Time-field is a DateTime type, and I have Score and Time as Indexes)
|
by: gerrymcc |
last post by:
Hello, I'm a php/mysql beginner...
Is there any way of making the mysql command line client full-screen?
Sometimes it's easier to use the client than go thru php, but
since it's only about 80 characters wide that limits its usefulness.
Thanks,
Gerard http://homepage.eircom.net/~gerfmcc]
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |