...

View Full Version : Badly Need Someone Help:Undefined offset: 3



djkhan
01-22-2012, 02:09 PM
Hello Everybody.

I Badly Need Someone Help and I have Tried myself a Lo t for Find a Problem But Could not Adjust it.
I Have a Script Where i Can see top 4 Referrals and This Page is Fetching the data from SQL from PhpMyAdmin

Every Calculation is Good Only at the end in getting this Error Shown in Picture.
I need Someone Help if cn guise me please
Thanks You Very Much

FILE - CODES ARE HERE
------------------------------------------------------

<?php
include('includes/admin_header.php'); ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="padding-left:50px; padding-right:50px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="td_dark_backg" style="padding-left:20px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" align="left" style="padding:10px; line-height:20px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5"></td>
<td valign="top">&nbsp;</td>
<td valign="top"><?php
$RefArray = array();
$sqlref=dbQuery("select distinct(`referrer`) from `user_registration` where `status`='1' and `referrer`<>''");
if(dbNumRows($sqlref)>0) {
?>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">

</table></td>
</tr>
<tr>
<td><table width="380" border="1" cellpadding="5" cellspacing="5" bordercolor="#4EBBE4" class="submit" style="border:1px solid #4EBBE4; border-collapse:collapse">
<?php

if(dbNumRows($sqlref)>0) {
while($resref=dbFetchArray($sqlref,MYSQL_BOTH)) {

$TYU = dbQuery("select * from `user_registration` where `email`='".$resref["referrer"]."' and `status`='1'");
if(dbNumRows($TYU)>0) {
$Totalref = dbNumRows(dbQuery("select * from `user_registration` where `referrer`='".$resref["referrer"]."' and `status`='1'"));
$resreff = dbFetchArray($TYU,MYSQL_BOTH);
$RefArray["fullname"][] = $resreff["fullname"];
$RefArray["email"][] = $resreff["email"];
$RefArray["refcount"][] = $Totalref;
}

}
}

$temp1 = ""; $temp2 = ""; $temp3 = "";
if(dbNumRows($sqlref)>0) {
$size = count( $RefArray["refcount"] );
for( $i = 0; $i < $size-1; $i++ ) {
for( $j = 0; $j < $size - 1 - $i; $j++ ) {
if( $RefArray["refcount"][$j+1] > $RefArray["refcount"][$j] ) {

$temp1 = $RefArray["fullname"][$j];
$temp2 = $RefArray["email"][$j];
$temp3 = $RefArray["refcount"][$j];

$RefArray["fullname"][$j] = $RefArray["fullname"][$j+1];
$RefArray["email"][$j] = $RefArray["email"][$j+1];
$RefArray["refcount"][$j] = $RefArray["refcount"][$j+1];

$RefArray["fullname"][$j+1] = $temp1;
$RefArray["email"][$j+1] = $temp2;
$RefArray["refcount"][$j+1] = $temp3;
}
}
}
}
if(dbNumRows($sqlref)>0) {
?>
<tr>
<td align="center" style="font-weight:bold; color:#999999;" width="40">Rank</td>
<td align="center" style="font-weight:bold; color:#999999;" width="250">Full Name</td>
<td align="center" style="font-weight:bold; color:#999999;" width="90">Total Referred</td>
</tr>
<?php
for($k=0 ; $k < 4 ; $k++) {
$kk = $k+1;
$resreff = dbFetchArray(dbQuery("select * from `user_registration` where `email`='".$RefArray["email"][$k]."'"),MYSQL_BOTH);
?>
<tr>
<td align="center"><?php echo $kk.'.'; ?></td>
<td align="center"><?php echo $resreff["fullname"]; ?></td>
<td align="center"><?php echo $RefArray["refcount"][$k]; ?></td>
</tr>
<?php }
?>
<p>&nbsp;</p>
<?php } ?>
<?php } ?></td>
<td width="5"></td>
</tr>
<tr>
<td colspan="5">&nbsp;</td>
</tr>
</table>
<?php ?>
<?php echo $_SESSION["adminusername"]; ?>!&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<?php if(isset($_GET["msg"]) && $_GET["msg"]=="passchange") { ?><span style="color:#00F">The action has been done successfully!</span><?php } ?>

<?php
include('includes/admin_footer.php');
include('includes/general_footer.php');
?>

Fou-Lu
01-22-2012, 02:43 PM
The error indicates that there is no third offset in $RefArray['refcount'].
There sure are a lot of queries here. Why not use an aggregate with a count instead?


<?php
$sQry = 'SELECT r.fullname, count(m.referrer) AS refcount
FROM user_registration r
INNER JOIN user_registration m ON (m.referrer = r.email)
WHERE r.status = 1 AND m.status = 1
GROUP BY m.referrer
ORDER BY refcount DESC LIMIT 0, 4';
// Not sure what your functions do, so I'll stick to basic mysql:
if ($qry = mysql_query($sQry))
{
?>
<tr>
<td align="center" style="font-weight:bold; color:#999999;" width="40">Rank</td>
<td align="center" style="font-weight:bold; color:#999999;" width="250">Full Name</td>
<td align="center" style="font-weight:bold; color:#999999;" width="90">Total Referred</td>
</tr>
<?php
$i = 1;
while ($row = mysql_fetch_assoc($qry))
{
print '<tr>';
printf('<td align="center">%d</td><td align="center">%s</td><td align="center">%d</td>', $i++, $row['fullname'], $row['refcount']);
print '</tr>';
}
}

djkhan
01-22-2012, 03:03 PM
Hi,
Thanks you very much for your quick reply
yes actually its generating an empty row as in " Total Referred "column as in picture
...........................................
for($k=0 ; $k < 4 ; $k++) {
$kk = $k+1;
..............................................
if i adjust $k < 3 ; $k++) {
its works fine but i can see only 3 entries from SQL

Im not a Good Programmer im just a learner.
please help me out

Fou-Lu
01-22-2012, 03:09 PM
The limit you have provided is exceeding the number available. You need to limit both by 4 as well as the max count available.


$iMaxRows = count($RefArray);
for ($k = 0; $k < 4 && $k < $iMaxRows; ++$k)


Or you can use a foreach or the code I have above instead.

djkhan
01-22-2012, 03:52 PM
@Fou-Lu

Thanks a Lot ,Really now it works fine
And i really appreciate your help.. its a first time i post something on this forum and it really helps me .
Thanks you very much again
You are Bestttttt :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum