acidglitter Posted November 11, 2006 Share Posted November 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/26912-help/ Share on other sites More sharing options...
wildteen88 Posted November 11, 2006 Share Posted November 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/26912-help/#findComment-123089 Share on other sites More sharing options...
acidglitter Posted November 11, 2006 Author Share Posted November 11, 2006 Thanks it seems to be working. I used that with [code]while($row=mysql_fetch_array($sql)){[/code](I put the code you gave me as $sql). But when I looked at it it showed 4 empty lines. How do I get the information to show up now? Quote Link to comment https://forums.phpfreaks.com/topic/26912-help/#findComment-123207 Share on other sites More sharing options...
Orio Posted November 11, 2006 Share Posted November 11, 2006 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 Link to comment https://forums.phpfreaks.com/topic/26912-help/#findComment-123221 Share on other sites More sharing options...
acidglitter Posted November 11, 2006 Author Share Posted November 11, 2006 [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 thisSELECT COUNT(referal_col) FROM your_tbl GROUP BY referal_colas 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 Quote Link to comment https://forums.phpfreaks.com/topic/26912-help/#findComment-123257 Share on other sites More sharing options...
wildteen88 Posted November 12, 2006 Share Posted November 12, 2006 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, 5Again 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. Quote Link to comment https://forums.phpfreaks.com/topic/26912-help/#findComment-123509 Share on other sites More sharing options...
acidglitter Posted November 13, 2006 Author Share Posted November 13, 2006 [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 )1Array ( [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 )1Array ( [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 )1Array ( [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 )1Array ( [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] Quote Link to comment https://forums.phpfreaks.com/topic/26912-help/#findComment-123674 Share on other sites More sharing options...
wildteen88 Posted November 13, 2006 Share Posted November 13, 2006 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, 5Now you should be able to get the Total referrals using $row['refTotal'] Quote Link to comment https://forums.phpfreaks.com/topic/26912-help/#findComment-124013 Share on other sites More sharing options...
acidglitter Posted November 17, 2006 Author Share Posted November 17, 2006 mmkay. thankyou! :) Quote Link to comment https://forums.phpfreaks.com/topic/26912-help/#findComment-125960 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.