Jump to content

Recommended Posts

I'm sorry if this is a stupid question, but it's 4 in the morning so I'm not thinking as clearly and I want to ask this before I go to sleep...

I have a mysql table, and everytime this page is viewed, a new row is inserted into the table. One of the columns is the refering pages URL. I know I could make a separate table with all of the possible referals and count it there but I don't want to for this. So I'm wondering how (and if I even could) I could show all of the referals on a page, but only show each one once and also how many times it shows up in the table.
Link to comment
https://forums.phpfreaks.com/topic/26912-help/
Share on other sites

What si you database scheme? Could you post it here.From form what I can tell from your post you'll want to use Count function and use the GROUP BY clause in your query, example:

[code]SELECT COUNT(referal_col) FROM your_tbl GROUP BY referal_col[/code]

You'll want to change referal_col and your_tbl to the correct values. referal_col is the column that holds the referals and your_tbl is the table that holds the referals.
Link to comment
https://forums.phpfreaks.com/topic/26912-help/#findComment-123089
Share on other sites

[quote author=Orio link=topic=114618.msg466566#msg466566 date=1163273850]
By writing:
while($row=mysql_fetch_array($sql))

You run a loop that each time takes one row, and store the values of it in the variable you gave using an array.

For the query:
SELECT col1,col2,ip FROM `table`
the above will put the values in $row['col1'] $row['col2'] $row['ip'].

Orio.
[/quote]

But I already have this
SELECT COUNT(referal_col) FROM your_tbl GROUP BY referal_col
as my query. I'm wondering if I would have to make a 2nd query inside the while() thing from my 1st query, or if there is a way to put both of them together
Link to comment
https://forums.phpfreaks.com/topic/26912-help/#findComment-123257
Share on other sites

The query I gave wouldn't of returned anything. Try this in your query:

SELECT *, COUNT(referer_col) AS refTotal FROM referer_tbl GROUP BY referer_col LIMIT 0, 5

Again change referer_col and referer_tbl to the correct values.

Now in your while loop just add this:
[code=php:0]echo "<pre>" . print_r($row) . "</pre>";[/code]

Post here what it returns.
Link to comment
https://forums.phpfreaks.com/topic/26912-help/#findComment-123509
Share on other sites

[code]Array ( [0] => 2 [id] => 2 [1] => 2006-11-11 05:53:08 [whatime] => 2006-11-11 05:53:08 [2] => 25429605 [lookingat] => 25429605 [3] => [referal] => [4] => 20 [refTotal] => 20 )

1

Array ( [0] => 7 [id] => 7 [1] => 2006-11-11 06:00:03 [whatime] => 2006-11-11 06:00:03 [2] => 13184947 [lookingat] => 13184947 [3] => http://bulletin.myspace.com/index.cfm?fuseaction=bulletin.read&messageID=1950612106 [referal] => http://bulletin.myspace.com/index.cfm?fuseaction=bulletin.read&messageID=1950612106 [4] => 16 [refTotal] => 16 )

1

Array ( [0] => 1 [id] => 1 [1] => 2006-11-11 05:44:53 [whatime] => 2006-11-11 05:44:53 [2] => 46125020 [lookingat] => 46125020 [3] => http://bulletin.myspace.com/index.cfm?fuseaction=bulletin.read&messageID=1950692652 [referal] => http://bulletin.myspace.com/index.cfm?fuseaction=bulletin.read&messageID=1950692652 [4] => 3 [refTotal] => 3 )

1

Array ( [0] => 16 [id] => 16 [1] => 2006-11-11 10:02:32 [whatime] => 2006-11-11 10:02:32 [2] => 46125020 [lookingat] => 46125020 [3] => http://bulletin.myspace.com/index.cfm?fuseaction=bulletin.read&messageID=1951338655 [referal] => http://bulletin.myspace.com/index.cfm?fuseaction=bulletin.read&messageID=1951338655 [4] => 7 [refTotal] => 7 )

1

Array ( [0] => 27 [id] => 27 [1] => 2006-11-11 14:11:06 [whatime] => 2006-11-11 14:11:06 [2] => 17433428 [lookingat] => 17433428 [3] => http://bulletin.myspace.com/index.cfm?fuseaction=bulletin.read&messageID=1952720969 [referal] => http://bulletin.myspace.com/index.cfm?fuseaction=bulletin.read&messageID=1952720969 [4] => 9 [refTotal] => 9 )

1[/code]
Link to comment
https://forums.phpfreaks.com/topic/26912-help/#findComment-123674
Share on other sites

Okay kool the query I provided is working fine. When I told you to do this I added a LIMIT to the mysql query. Please edit your query and remove the following from it:
LIMIT 0, 5

Now you should be able to get the Total referrals using $row['refTotal']
Link to comment
https://forums.phpfreaks.com/topic/26912-help/#findComment-124013
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.