referral statistics

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
summertime
Forum Newbie
Posts: 4
Joined: Thu Feb 17, 2005 4:50 am

referral statistics

Post by summertime »

I'm complete lamer in PHP. I compilied this code from several others.

I want to receive statistic about number of referrals each user have.

My user table contains:

Code: Select all

id
share(referrals)
own(same as id)
email
pass
credits

In config.inc.php

Code: Select all

function report_ref()
{
        $result = mysql_query("SELECT * FROM user WHERE own=id ORDER by id");
        for($i=0; $row=mysql_fetch_array($result); $i++){
                $listї$i]=$row;
        }
        return $list;
}
In referral.php

Code: Select all

<?
require('config_inc.php');
$referral=report_ref();
?>
<?
require('header_inc.php')
?>
<table border="1" cellspacing="1" cellpadding="0" bordercolor="#000000">
  <tr align="center">
    <td width="20"><b>ID</b></td>
    <td width="350"><b>Total Referrals</b></td>
    </tr>
<?php
for($i=0; $i<count($reported); $i++)
        echo '
  <tr align="center">
    <td width="20">'.$referral&#1111;$i]&#1111;id].'</td>
    <td width="350">'.$referral&#1111;$i]&#1111;own].'</td>
     </tr>
        ';
?>
</TD>
</TR>
</TABLE>
<?
require('footer_inc.php')
?>
Result I get is just ID and Total Referrals row without any data.

Where is my mistake?

By the way I tried:

Code: Select all

$result = mysql_query("SELECT id, share, own FROM user WHERE own=id
with the same success.

Mariela


feyd | please use the formatting tags when posting code. Bolding all your text doesn't help us, nor did the original title
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

How is 'share' stored?


Moved to PHP - Code.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Code: Select all

for($i=0; $i<count($reported); $i++)
Where did $reported come from? Why not use $referral in count() since it actually holds the array of items?
summertime
Forum Newbie
Posts: 4
Joined: Thu Feb 17, 2005 4:50 am

Post by summertime »

Maugrim_The_Reaper wrote:

Code: Select all

for($i=0; $i<count($reported); $i++)
Where did $reported come from? Why not use $referral in count() since it actually holds the array of items?
It came form another code:P
I changed it ... still no report.
summertime
Forum Newbie
Posts: 4
Joined: Thu Feb 17, 2005 4:50 am

Post by summertime »

feyd wrote:How is 'share' stored?


Moved to PHP - Code.
Actually I think share have nothing to do with referrals.
To be more clear this is auto surf script in which I'm trying to add referral statistic.

Here is the original MySQL maybe this will help you:

Code: Select all

CREATE TABLE user (
   id int(11) NOT NULL AUTO_INCREMENT,
   name varchar(255) NOT NULL,
   email varchar(255) NOT NULL,
   pass varchar(255) NOT NULL,
   share tinyint(2) NOT NULL DEFAULT '0',
   own int(11) NOT NULL DEFAULT '0',
   credits float NOT NULL DEFAULT '0',
   c1 float NOT NULL DEFAULT '0',
   c2 float NOT NULL DEFAULT '0',
   c3 float NOT NULL DEFAULT '0',
   c4 float NOT NULL DEFAULT '0',
   c5 float NOT NULL DEFAULT '0',
   c6 float NOT NULL DEFAULT '0',
   c0 float NOT NULL DEFAULT '0',
   type tinyint(3) NOT NULL DEFAULT '0',
   br tinyint(4) NOT NULL DEFAULT '0',
   date date NOT NULL DEFAULT '0000-00-00',
   cr_earn float NOT NULL DEFAULT '0',
   tmp_mail int(11) NOT NULL DEFAULT '0',
   PRIMARY KEY (id))
   TYPE=MyISAM;
And here is how the author made referral statistic to each user:

Code: Select all

<?
	$query = "select * from ".$t_user." where own=".$id;      
	$result = MYSQL_QUERY($query);
?>
          <td>You refer:(<?print mysql_num_rows($result);?>)<br>
<?	if(mysql_num_rows($result)==0)&#123;
		print "none";
	&#125;
	while($row = mysql_fetch_array($result))&#123;
	if($row&#1111;"share"]==0)&#123;
		print $row&#1111;"name"];
	&#125;else&#123;
?>
<a href="mailto:<?print $row&#1111;"email"];?>"><font color=blue><?print $row&#1111;"name"];?></font></a>
I tired to modify this ... with the same success as the last code.

Mariela
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

how's this?

Code: Select all

SELECT COUNT(own) number_of_referrals, * FROM users GROUP BY own ORDER BY id
summertime
Forum Newbie
Posts: 4
Joined: Thu Feb 17, 2005 4:50 am

Post by summertime »

feyd wrote:how's this?

Code: Select all

SELECT COUNT(own) number_of_referrals, * FROM users GROUP BY own ORDER BY id

This part of the code

Code: Select all

number_of_referrals, *
gave me error - mysql_fetch_array(): supplied argument is not a valid MySQL result resource . Without it I have two rows - one small and one bigger but no data.



Mariela
Post Reply