Jump to content
MakeWebGames

Counting rows issue


Smokey

Recommended Posts

I know this has to be something simple, either I'm just not getting it or its so late that my mind isnt working properly, anyway, i am building a list of users referrals so they can keep track of the people they have referred to the game, the problem is it only adds the first person they referred (first in the table) to the list. I cannot for the life of me figure out what i am doing wrong, I'm having the same issue with listing the item (in shop) locations which i am listing on the iteminfo page so users know where the items are located, it will list only the first location in the db ( i have 10 countries with 10 cities in each so some items are available in more than 1 city) if i can figure out the referral list i'm sure i can get the latter worked out. so heres the code for the referral list:

 

<?php


include "globals.php";

print "
<table cellspacing='0' width='100%' border='1'>
	<tr>
<td style='border:1px solid #A39B83;' bgcolor='#7D7764' colspan='4'><b><center><font size=2>Your Referrals</b></td></tr>
	<tr>
<tr>
</tr><tr><th style='border:1px solid #7D7764;' bgcolor='#948D76' width='20%'>ID</th><th style='border:1px solid #7D7764;' bgcolor='#948D76' width='20%'>Referred</th><th style='border:1px solid #7D7764;' bgcolor='#948D76' width='20%'>Level</th><th style='border:1px solid #7D7764;' bgcolor='#948D76' width='20%'>Age</th></tr>
";

$ref=$db->query("SELECT * FROM referals WHERE refREFER = $userid");
$rs=$db->fetch_row($ref);

if(!$db->num_rows($ref) ) 
{
$refer="No Referals";   
}
else
{
$refer="{$rs['refREFED']}";
}

$qs=$db->query("SELECT * FROM users WHERE userid = {$rs['refREFED']}");
$rf=$db->fetch_row($qs);
print "
<tr><td style='border:1px solid #7D7764;' bgcolor='#C9C9C9'><center>{$rf['userid']}</a></td><td style='border:1px solid #7D7764;' bgcolor='#C9C9C9'><center><a href='viewuser.php?u={$rf['userid']}'>{$rf['username']}</a></td> <td style='border:1px solid #7D7764;' bgcolor='#C9C9C9'><center>{$rf['level']}</td> <td style='border:1px solid #7D7764;' bgcolor='#C9C9C9'><center>{$rf['daysold']} Days Old</td></tr>

<tr><th style='border:1px solid #A39B83;' bgcolor='#7D7764'colspan=4></th></tr>
</table><br> ";
?>

 

any help would be much appreciated.

Link to comment
Share on other sites

I must be putting this together wrong.

<?php


include "globals.php";
$sql       = 'SELECT COUNT(refID) FROM referals WHERE refREFER = ' . $userid;
$rs        = mysql_query($sql);
$referals = array_shift(mysql_fetch_row($rs));
mysql_free_result($rs);

   $sql = <<<SQL

          SELECT userid, username
            FROM users
       LEFT JOIN referals ON refREFED = userid
           WHERE refREFER = $userid
        ORDER BY level DESC, username

  SQL;

   echo '

       <table border="1">
           <tr>
               <th>ID</th>
               <th>Name</th>
               <th>Level</th>
           </tr>

   ';

   $rs = mysql_query($sql);

   WHILE ($row = mysql_fetch_row($rs))
   {
       list($id, $name, $level) = $row;

       $name  = htmlentities($name, ENT_QUOTES, 'utf-8');
       $level = number_format($level);

       echo <<<HTML

           <tr>
               <td>$id</td>
               <td>$name</td>
               <td>$level</td>
           </tr>

   HTML;
   }

   mysql_free_result($rs);

   echo '<br style="clear:both;" /></table>';

$h->endpage();
exit;
?>

 

It works until i get down to the HTML part, i get an unexpected $end error, if i change the HTML part to a regular echo the file will work...but it will only show $id, $name, $level instead of their actual info like it isnt being defined.

Link to comment
Share on other sites

<?php 

include "globals.php";
$sql       = 'SELECT COUNT(refID) FROM referals WHERE refREFER = ' . $userid;
$rs        = mysql_query($sql);
$referals = array_shift(mysql_fetch_row($rs));
mysql_free_result($rs);

   $sql = "

          SELECT userid, username
            FROM users
       LEFT JOIN referals ON refREFED = userid
           WHERE refREFER = $userid
        ORDER BY level DESC, username

  ";

   echo '

       <table border="1">
           <tr>
               <th>ID</th>
               <th>Name</th>
               <th>Level</th>
           </tr>

   ';

   $rs = mysql_query($sql);

   WHILE ($row = mysql_fetch_row($rs))
   {
       list($id, $name, $level) = $row;

       $name  = htmlentities($name, ENT_QUOTES, 'utf-8');
       $level = number_format($level);

       echo "

           <tr>
               <td>".$id."</td>
               <td>".$name."</td>
               <td>".$level."</td>
           </tr>

   ";
   }

   mysql_free_result($rs);

   echo '<br style="clear:both;" /></table>';

$h->endpage();
exit;
?>

 

Try that

Link to comment
Share on other sites

Well you learn something everyday, i did not know this, i havent been coding very long at all :P I took out the whitespace and viola, it worked, though it is showing their level as 0 but a little work and im sure i can figure that out, thanks Octarine, i appreciate the help :)

Edit, the level part was because it wasnt retrieving level from the usertable, easy fix, thanks alot, and mixmaster that worked just the same as Octarines, thank you too

Edited by Smokey
Link to comment
Share on other sites

@Smokey, my apologies; I missed the level field in the original SELECT statement.

I seldom test these things out days, it's all of the top of my head so the occasional

slip up I'm sure can be forgiven.

@mixmaster, no need for exit or ?>.

1: I didn't put them in. 2: Ofcourse there is a need for the ?>:p

Edited by mixmaster
Link to comment
Share on other sites

No its not that i wont be buying from Peter again, i have hosting through him and have no problems with it, except it seems to be down at the moment, I just meant next time I'll make sure I explain in detail exactly what i want as we had some confusion with the layout i bought.

Link to comment
Share on other sites

No its not that i wont be buying from Peter again, i have hosting through him and have no problems with it, except it seems to be down at the moment, I just meant next time I'll make sure I explain in detail exactly what i want as we had some confusion with the layout i bought.

Yes im also with his hosting , i think this is the third time its been down in 2 weeks

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...