Pagination issues

Started by actionman, April 28, 2014, 06:50:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mindless

You've still got code in there from browse - catsperrow shit, code needs pulled right back to beginning then redone - it does not look right to me - but I can't test nothing , only my knowledge and eye, if I can get the code from you  working without any pager code added I'll more and likely be able to work it out.

actionman

#7
getting
Warning: Invalid argument supplied for foreach() in /home/admin/domains/mayhem-zone.com/public_html/movies2.php on line 57

Notice: Undefined variable: catsperrow in /home/admin/domains/mayhem-zone.com/public_html/movies2.php on line 94

Warning: Division by zero in /home/admin/domains/mayhem-zone.com/public_html/movies2.php on line 94

Notice: Undefined variable: catsperrow in /home/admin/domains/mayhem-zone.com/public_html/movies2.php on line 95

Warning: Division by zero in /home/admin/domains/mayhem-zone.com/public_html/movies2.php on line 95

any idea what is causing the first error for foreach?

i got the foreach error to disappear when i modded the sql to remove the $ret[]=$row; & return $ret;

but now i get
Notice: Uninitialized string offset: 0  on each call for Poster, Id, Name, Category etc

this is called from the foreach.


Mindless

#6
Code (php) Select
bring in the function ?

//require_once (INCL_DIR . 'pager_functions.php');

//==Need a count so select that from torrents -

$res = mysql_query("SELECT COUNT(id) FROM torrents");
$row = mysql_fetch_array($res);
$count = $row[0];
$perpage = 15;

//==Also define $pager before the select query

$pager = pager($perpage, $count, "movies.php?");

//code to call sql
$ret =array();
    $movies = array(8,7,11,15,18,14,23,38);
        $movies = implode(',', $movies);
    $res = mysql_query("SELECT * FROM torrents WHERE category IN (".$movies.") ORDER BY added DESC {$pager['limit']}");
    while ($row = mysql_fetch_array($res))
        $ret[] = $row;
    return $ret;
///HTML
//== if greater than per page use pager
          if ($count > $perpage) $htmlout .= $pager['pagertop']; 
     
$htmlout .="<table width='97%' align='center'><tr><td style='border:none'>
<table width='100%' align='center'><tr>";
$i = 0;
foreach ($row as $torrent) {
$catsperrow = 4;

//== use int or 0 + or int_val to force numeric value or htmlspecialchars on strings

$torrentid = (int) $row['id'];
$torpic = "<img src='".htmlspecialchars($row['poster'])."' width='110px' height='130px' style='padding:5px' />";
$torname = htmlspecialchars($row['name']);
$torleech = (int) $row['leechers'];
$torseed = (int) $row['seeders'];
if ($torrent['anonymous'] == 'no')
$name = htmlspecialchars($torrent['owner']);
else
$name = "Anonymous";

// == use sqlesc in on selects/inserts/updates
           
$fab = mysql_query("SELECT username FROM users WHERE id=".sqlesc($name));
$fac = mysql_fetch_assoc($fab);
if ($fac['username'] == "")
        $username = "Anonymous";
else
$username = htmlspecialchars($fac['username']);

$torname = str_replace(array('100percent', '1000percent', 'bbbbbb', '''), array('100%', '1000%', '%', '\''), $torname);
$htmlout .= ($i && $i % $catsperrow == 0) ? "</tr><tr>" : "";
      $htmlout .= "<td width='20%'>
     <a href='details.php?id={$torrentid}'>{$torpic}<br />
<br />" . CutName($torname,30) . "
</a><br />Leechers: $torleech<br />
Seeders: $torseed<br />
Genre: ".$torrent['subgenre']."<br />
Uploaded by: $username<br />
</td>";
      $i++;
          }
$ncats = count($count);
    $nrows = ceil($ncats/$catsperrow);
    $lastrowcols = $ncats % $catsperrow;

    if ($lastrowcols != 0)
    {
      if ($catsperrow - $lastrowcols != 1)
       
          $htmlout .= "<td class='bottom' rowspan='" . ($catsperrow  - $lastrowcols - 1) . "'>&nbsp;</td>";
     
        }
$htmlout .="</tr></table></td></tr></table>";
if ($count > $perpage) $htmlout .= $pager['pagerbottom'];
$htmlout .= end_frame();
           
print stdhead().$htmlout.stdfoot();


Cant be far away from that, the bottom stuff from browse will need removed - thats pretty much everything required, just the query placement thats different in this instance, aboves not tested just from eye lol.

actionman

H Mindless

Will look at those few bits - here my code minus the pager stuff

Code (php) Select

//code to call sql
$ret =array();
    $movies = array(8,7,11,15,18,14,23,38);
$movies = implode(',', $movies);
    $res = mysql_query("SELECT * FROM torrents WHERE category IN (".$movies.") ORDER BY added DESC {$pager['limit']}");
    while ($row = mysql_fetch_array($res))
        $ret[] = $row;
    return $ret;
///HTML
  $htmlout .=$pager['pagertop'];
$htmlout .="<table width='97%' align='center'><tr><td style='border:none'>
<table width='100%' align='center'><tr>";
$i = 0;
foreach ($row as $torrent) {
$catsperrow = 4;
$torrentid = (int) or 0 + $row['id'];
$torpic = "<img src='".htmlspecialchars($row['poster'])."' width='110px' height='130px' style='padding:5px' />";
$torname = .htmlspecialchars($row['name']);
$torleech = (int) or 0 + $row['leechers'];
$torseed = (int) or 0 + $row['seeders'];
if ($torrent['anonymous'] == 'no')
$name = $torrent['owner'];
else
$name = "Anonymous";
   
$fab = mysql_query("SELECT username FROM users WHERE id=$name");
$fac = mysql_fetch_assoc($fab);
if ($fac['username'] == "")
$username = "Anonymous";
else
$username = $fac['username'];

$torname = str_replace(array('100percent', '1000percent', 'bbbbbb', '''), array('100%', '1000%', '%', '\''), $torname);
$htmlout .= ($i && $i % $catsperrow == 0) ? "</tr><tr>" : "";
      $htmlout .= "<td width='20%'>
      <a href='details.php?id={$torrentid}'>{$torpic}<br />
<br />" . CutName($torname,30) . "
</a><br />Leechers: $torleech<br />
Seeders: $torseed<br />
Genre: ".$torrent['subgenre']."<br />
Uploaded by: $username<br />
</td>";
      $i++;
  }
$ncats = count($count);
    $nrows = ceil($ncats/$catsperrow);
    $lastrowcols = $ncats % $catsperrow;

    if ($lastrowcols != 0)
    {
      if ($catsperrow - $lastrowcols != 1)
       
          $htmlout .= "<td class='bottom' rowspan='" . ($catsperrow  - $lastrowcols - 1) . "'>&nbsp;</td>";
     
}
$htmlout .="</tr></table></td></tr></table>";
$htmlout .= $pager['pagerbottom'];
$htmlout .=end_frame();
   
print stdhead().$htmlout.stdfoot();

Mindless

#4
I think lifting the code from browse is the problem here, can you post your code minus any pager stuff and i'll post back how to mod it with pager with a few lines,

Just checking the code, nice mod - few points to note

Code (php) Select
$torrentid = $row['id'];
$torpic = "<img src='".$row['poster']."' width='110px' height='130px' style='padding:5px' />";
$torname = $row['name'];
$torleech = $row['leechers'];
$torseed = $row['seeders'];
$id = $row['id'];


That's wide open and not santized, its then printed to screen, thats ripe for Xss xploit mate, query's need sqlesc applied anywhere a user/script supplied variable is pulled in, will show that next

Code (php) Select
$torrentid = (int) or 0 + $row['id'];
$torpic = "<img src='".htmlspecialchars($row['poster'])."' width='110px' height='130px' style='padding:5px' />";
$torname = .htmlspecialchars($row['name']);
$torleech = (int) or 0 + $row['leechers'];
$torseed = (int) or 0 + $row['seeders'];
$id = (int) or 0 + $row['id'];

actionman

Hi Mindless

Thanks for the update - i have tried adding the ".$pager['limit']." to the sql query but it doesnt work as  get

Notice: Undefined variable: pager in /home/admin/domains/mayhem-zone.com/public_html/include/bittorrent.php

so i added the function to below the $pager bit on my code and called it back from there

but  still get the same error

Regards

Mindless

You need to add to the select query to limit results for the pager

Code (sql) Select
$sql = sql_query("SELECT * FROM tablename ORDER BY var1 ASC " . $pager['limit']) or sqlerr(__FILE__, __LINE__);

actionman

Hi

Im trying to code a page to add to my site but i am unable to get the pager function to work

I have 543 rows which i have added in to a 4 per row via a foreach method (this works  treat however the pager function just seems not do anything and i have all 543 items on one page.

i have added a function to bittorrent.php to make it easier to call the data from

Code (php) Select
function torrentlist() {
$ret =array();
    $movies = array(8,7,11,15,18,14,23,38);
$movies = implode(',', $movies);
    $res = mysql_query("SELECT * FROM torrents WHERE category IN (".$movies.") ORDER BY added DESC");
    while ($row = mysql_fetch_array($res))
        $ret[] = $row;
    return $ret;
}


then i have created a new page with this code in
Code (php) Select

$torrents = torrentlist();

    $addparam = "";
    $wherea = array();
    $wherecatina = array();

    $category = (isset($_GET["cat"])) ? (int)$_GET["cat"] : false;

    $all = isset($_GET["all"]) ? $_GET["all"] : false;
$_by = (isset($_GET["_by"]) ? 0 + $_GET["_by"] : 0);
   
    if ($all)
    {
      $wherecatina = array();
      $addparam = "";
    }

    if (count($wherecatina) > 1)
      $wherecatin = implode(",",$wherecatina);
    elseif (count($wherecatina) == 1)
      $wherea[] = "category = $wherecatina[0]";

    $wherebase = $wherea;

       if (isset($cleansearchstr)) {
        if ($_by == 0) {
            $wherea[] = "torrents.name LIKE (" . sqlesc($searchstr) . ")";
        } elseif ($_by == 1) {
            $wherea[] = "MATCH (search_text, ori_descr) AGAINST (" . sqlesc($searchstr) . ")";
        } elseif ($_by == 2) {
            $wherea[] = "MATCH (search_text, ori_descr) AGAINST (" . sqlesc($searchstr) . ")";
    } elseif ($_by == 3) {
            $query = mysql_query("SELECT id FROM users WHERE username = ".sqlesc($searchstr)." LIMIT 1");
            if (mysql_num_rows($query) > 0)
{
$user = mysql_fetch_assoc($query);

$wherea[] = "torrents.owner = ".sqlesc($user['id']).(!$mod ? " AND torrents.anonymous != 'yes'" : "");
}

        }
        $addparam .= "search=" . urlencode($searchstr) . "&";
      $orderby = "";
     
    }

    $where = implode(" AND ", $wherea);
   
    if (isset($wherecatin))
      $where .= ($where ? " AND " : "") . "category IN(" . $wherecatin . ")";

    if ($where != "")
      $where = "WHERE $where";

    $count1 = count($torrents);

    $torrentsperpage = 30;
    if (!$torrentsperpage)
      $torrentsperpage = 30;

    if ($count1)
    {
if ($addparam != "") {

            if ($pagerlink != "") {

if ($addparam{strlen($addparam)-1} != ";") { // & = &amp;
                   
$addparam = $addparam . "&" . $pagerlink;

                } else {

                    $addparam = $addparam . $pagerlink;
                }
            }
        }


      //list($pagertop, $pagerbottom, $limit) = pager($torrentsperpage, $count, "hitnrun.php?" . $addparam);
      $pager = pager($torrentsperpage, $count1, "movies.php?" . $addparam);
 

       
    }
 
function CutName ($txt, $len)
{
    $len = 30;
    return (strlen($txt) > $len ? substr($txt, 0, $len-1) .'<br />' :$txt);
}
$htmlout = '';
$htmlout .=begin_frame("Latest Movies",true);
$htmlout .=$pager['pagertop'];

$count = count($row);
$htmlout .="<table width='97%' align='center'><tr><td style='border:none'>$count<br />
<table width='100%' align='center'><tr>";
$i = 0;
foreach ($torrents as $row) {
$catsperrow = 4;
$torrentid = $row['id'];
$torpic = "<img src='".$row['poster']."' width='110px' height='130px' style='padding:5px' />";
$torname = $row['name'];
$torleech = $row['leechers'];
$torseed = $row['seeders'];
$id = $row['id'];
if ($row['anonymous'] == 'no')
$name = $row['owner'];
else
$name = "Anonymous";
   
$fab = mysql_query("SELECT username FROM users WHERE id=$name");
$fac = mysql_fetch_assoc($fab);
if ($fac['username'] == ""){
$username = "Anonymous";
}else{
$username = $fac['username'];
}
$torname = str_replace(array('100percent', '1000percent', 'bbbbbb', '''), array('100%', '1000%', '%', '\''), $torname);
$htmlout .= ($i && $i % $catsperrow == 0) ? "</tr><tr>" : "";
      $htmlout .= "<td width='20%'>
      <a href='details.php?id={$torrentid}'>{$torpic}<br />
<br />" . CutName($torname,30) . "
</a><br />Leechers: $torleech<br />
Seeders: $torseed<br />
Genre: ".$row['subgenre']."<br />
Uploaded by: $username<br />
</td>";
// @mysql_query("UPDATE users SET cat = {$cat['id']} WHERE id = ".$CURUSER['id']."");
      $i++;
  }
$ncats = count($row);
    $nrows = ceil($ncats/$catsperrow);
    $lastrowcols = $ncats % $catsperrow;

    if ($lastrowcols != 0)
    {
      if ($catsperrow - $lastrowcols != 1)
        {
          $htmlout .= "<td class='bottom' rowspan='" . ($catsperrow  - $lastrowcols - 1) . "'>&nbsp;</td>";
        }
}
$htmlout .="</tr></table></td></tr></table>";
$htmlout .= $pager['pagerbottom'];
$htmlout .=end_frame();


print stdhead().$htmlout.stdfoot();


like i said the display part is fine just the pagination doesnt. I copied the pagination code from browse but cannot see anything to change the code to work just with what i need - so apologies if this looks choppy etc.

any help here would be much appreciated.