Jump to content

Recommended Posts

i have a ranking system

which use

$rank = 1;

and

$rank ++; in the while loop

which works fine and ranks data if all together, but what if i add pages into it, i have done and on

page 1          1 - 10      show 1 - 10
page 2          11 - 20    shows 1 -10 still

any ideas of how to get around this please?
Link to comment
https://forums.phpfreaks.com/topic/34866-ranking/
Share on other sites

echo"    <tr>
  <td colspan='2'>";
 
  if(!isset($_GET['p']))
  {    
  $p = 1;  
  }
  else
  { 
  $p = $_GET['p'];
  }

  $max_results = $results;
  $max_results_1 = $max_results - 1;    
 
  $from = (($p * $max_results) - $max_results);
 
  $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM websites;"),0);  
  $total_pages = ceil($total_results / $max_results);
 
  $page_from = $from + 1;    
  $page_to = ( ($page_from + $max_results_1) > $total_results ? $total_results : ($page_from + $max_results_1)  ) ;
 
if($total_results == 0)
{
 
echo"        <tr>
              <td class='text_red_bold'>No testimonials have been submitted.</td>
            </tr>";

}
else
{
             
echo"      <table width='695' border='0' cellspacing='0' cellpadding='0'>";
echo"        <tr>
              <td class='text_red_bold'>Showing: $page_from - <font class='text_blue_bold'>$page_to</font> of $total_results websites ordered by <font class='text_blue_bold'>$view</font> first.</td>
            </tr>";
echo"        <tr>
              <td>&nbsp;</td>
            </tr>";
echo"    <tr>
    <td class='text_red_bold'>Page:&nbsp;";

    if($p > 1)
    {
   
    $prev = ($p - 1);
 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=websites&action=purchase&view=$view&results=$results&p=$prev\" class='red_bold_none'><< &nbsp;</a>";
 
    }

    for($i = 1; $i <= $total_pages; $i++)
    {

  if(($page) == $i)
{

echo "$i ";

}
else
{

echo "<a href=\"".$_SERVER['PHP_SELF']."?page=websites&action=purchase&view=$view&results=$results&p=$i\" class='red_bold_none'>$i</a> ";

}

    }

    if($p < $total_pages)
    {

    $next = ($p + 1);

    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=websites&action=purchase&view=$view&results=$results&p=$next\" class='red_bold_none'>>></a>";

    }

echo"   </td>
    </tr>";              
echo"      </table>";

  }
           
echo"   </td>
</tr>";

echo"    <tr>
          <td height='30' colspan='2'><img src='$config_url/include/images/lines/blue.gif' width='100%' height='3'></td>        
        </tr>";
 
echo"    <tr>
  <td width='575' valign='top'>";
echo"      <table width='550' border='1' cellspacing='0' cellpadding='0' bordercolor='#001D7C'>";

echo'      <tr>
            <td width="50" class="text_red_bold" height="25">&nbsp;&nbsp;Rank</td>
            <td width="350" class="text_red_bold" height="25">&nbsp;&nbsp;Website</td>
            <td width="150" class="text_red_bold">&nbsp;&nbsp;Date</td>           
            </tr>';   

$rank = 1;
 
    if($view == "latest")
    {
 
  $order_sql = "SELECT * FROM websites ORDER BY websites_date DESC LIMIT $from, $max_results;";
 
    }
    else
    {

  $order_sql = "SELECT * FROM websites ORDER BY websites_date ASC LIMIT $from, $max_results;";
     
    }
 
    $order_result = mysql_query($order_sql) or die(mysql_error());

    while($order_array = mysql_fetch_array($order_result))
    {
 
    $websites_id = $order_array['websites_id'];
    $websites_url = StripUrl($order_array['websites_url']);
    $websites_date = $order_array['websites_date'];
   
$rankStr = ordSuffix($rank);

if(isset($_SESSION['MemberID']))
    {
     
$adverts_seen_query = mysql_query("SELECT * FROM websites_hits_url
                                      WHERE websites_hits_url_website='$websites_id'
      AND websites_hits_url_user='$session_id';");
}
else
{
     
$adverts_seen_query = mysql_query("SELECT * FROM websites_hits_url
                                      WHERE websites_hits_url_website='$websites_id'
      AND websites_hits_url_user='$config_ip';");
   
}    

$adverts_seen_rows = mysql_num_rows($adverts_seen_query); 

if($adverts_seen_rows > 0)
{

echo'      <tr bgcolor="#ff0000" onmouseover="ChangeColorSeen(this, true);" onmouseout="ChangeColorSeen(this, false);" onclick="DoNav("'.$config_website_url.'/'.$config_website_url_topic.'/files/url.php?id='.$websites_id.'");">
          <a href="'.$config_website_url.'/'.$config_website_url_topic.'/files/url.php?id='.$websites_id.'" target="_blank">
<td class="text_bold">&nbsp;&nbsp;'.$rankStr.'</td>
            <td class="text_bold" height="25"><a href="'.$config_website_url.'/'.$config_website_url_topic.'/files/url.php?id='.$websites_id.'" class="blue_bold_none" target="_blank">&nbsp;&nbsp;'.$websites_url.'</td>
            <td class="text_bold">&nbsp;&nbsp;'.$websites_date.'</td>           
            </tr>';

        }
        else
        {
 
echo'      <tr onmouseover="ChangeColor(this, true);" onmouseout="ChangeColor(this, false);" onclick="DoNav("'.$config_website_url.'/'.$config_website_url_topic.'/files/url.php?id='.$websites_id.'");">
          <a href="'.$config_website_url.'/'.$config_website_url_topic.'/files/url.php?id='.$websites_id.'" target="_blank">
<td class="text_bold">&nbsp;&nbsp;'.$rankStr.'</td>
            <td class="text_bold" height="25"><a href="'.$config_website_url.'/'.$config_website_url_topic.'/files/url.php?id='.$websites_id.'" class="blue_bold_none" target="_blank">&nbsp;&nbsp;'.$websites_url.'</td>
            <td class="text_bold">&nbsp;&nbsp;'.$websites_date.'</td>           
            </tr>';
   
}

$rank ++;

}
           
echo"      </table>";           
echo"   </td>
          <td width='150' valign='top'>";
echo"      <table width='150' border='0' cellpadding='0' cellspacing='0'";
echo"      <tr>
            <td colspan='2' class='text_bold_underline'>Key</td>
            </tr>";
echo"      <tr>
            <td colspan='2'>&nbsp;</td>
            </tr>";               
echo"      <tr>
            <td width='20' height='20' valign='middle' align='left'><img src='$config_url/include/images/key/white.JPG' width='10' height='10'></td>
            <td width='130' height='20' class='text_bold'>Not Visited</td>           
            </tr>";             
echo"      <tr>
            <td width='20' height='20' valign='middle' align='left'><img src='$config_url/include/images/key/red.JPG' width='10' height='10'></td>
            <td width='130' height='20' class='text_bold'>Visited</td>           
            </tr>";            
echo"      </table>";           
echo"   </td>
</tr>";

echo"    <tr>
          <td height='30' colspan='2'><img src='$config_url/include/images/lines/blue.gif' width='100%' height='3'></td>        
        </tr>";       

echo"    <tr>
  <td colspan='2'>";
 
  if(!isset($_GET['p']))
  {    
  $p = 1;  
  }
  else
  { 
  $p = $_GET['p'];
  }

  $max_results = $results;
  $max_results_1 = $max_results - 1;    
 
  $from = (($p * $max_results) - $max_results);
 
  $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM websites;"),0);  
  $total_pages = ceil($total_results / $max_results);
 
  $page_from = $from + 1;    
  $page_to = ( ($page_from + $max_results_1) > $total_results ? $total_results : ($page_from + $max_results_1)  ) ;
 
if($total_results == 0)
{
 
echo"        <tr>
              <td class='text_red_bold'>No testimonials have been submitted.</td>
            </tr>";

}
else
{
             
echo"      <table width='695' border='0' cellspacing='0' cellpadding='0'>";
echo"        <tr>
              <td class='text_red_bold'>Showing: $page_from - $page_to of $total_results websites ordered by $view first.</td>
            </tr>";
echo"        <tr>
              <td>&nbsp;</td>
            </tr>";
echo"    <tr>
    <td class='text_red_bold'>Page:&nbsp;";

    if($p > 1)
    {
   
    $prev = ($p - 1);
 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=websites&action=purchase&view=$view&results=$results&p=$prev\" class='red_bold_none'><< &nbsp;</a>";
 
    }

    for($i = 1; $i <= $total_pages; $i++)
    {

  if(($page) == $i)
{

echo "$i ";

}
else
{

echo "<a href=\"".$_SERVER['PHP_SELF']."?page=websites&action=purchase&view=$view&results=$results&p=$i\" class='red_bold_none'>$i</a> ";

}

    }

    if($p < $total_pages)
    {

    $next = ($p + 1);

    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=websites&action=purchase&view=$view&results=$results&p=$next\" class='red_bold_none'>>></a>";

    }

echo"   </td>
    </tr>";              
echo"      </table>";

  }
           
echo"   </td>
</tr>";
Link to comment
https://forums.phpfreaks.com/topic/34866-ranking/#findComment-164415
Share on other sites

Can't be bothered to read all that but can't you carry values in the url?

[code]
http://www.domain.com/page.php?page=1

$page = $_GET['page'];
$max = $page * 10;
$min = $max - 10;

// Insert variables into query
$query = "SELECT * FROM t1 LIMIT $min, $max";
$result = @mysql_query($query);
$num = mysql_num_rows($result);

[/code]

Add more to suit your site but I think thats the basic principle.
Link to comment
https://forums.phpfreaks.com/topic/34866-ranking/#findComment-164492
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.