help a noob

Started by rabtb, August 10, 2014, 09:28:03 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tundracanine

yes its cause you are setting $res and $arr witch is not an good idea..
something like this might work better but again man this code is layout bad..
witch i fixed maybe
<table> without </table>....

begin_table();
?>
<b><center><font size=2><font color=black>Our Staff Recommend</font></font></b>
<table cellpadding="4" cellspacing="1" border="0" style="width:450px" class="tableinborder" ><tr><td class="tabletitle"style="width:450px" align="left">Torrent Name</td><td class="tabletitle" align="left">Seeders</td><td class="tabletitle" align="left">Leechers</td></tr>
<?php 
$res_rec
=mysql_query("SELECT id,leechers,seeders,name FROM torrents WHERE recommended='1' ORDER BY id") or print(mysql_error());
 
while (
$arr_rec = @mysql_fetch_assoc($res_rec )) {
echo 
"<tr><td class=tablea align=\"left\"><b><a href=details.php?id=" $arr_rec['id'] . ">"$arr_rec['name'] . "</b></td>
</td><td class=tablea align=\"left\"><b><font color=red>"
$arr_rec['seeders'] . "</font></b></td><td class=tablea align=\"left\"><b>"$arr_rec['leechers'] . "</b></td></tr>";
}
echo 
"</table></center>"
end_table();


If wanting support help please put bare min info like
Os:
U-232 Version:
Php Version:
Tracker type: like xbt or php
Saves on asking more questions just so people can help someone.

stoner

#2
Have you added that code into the browse.php file?

A couple of bits I can see which should be tweaked, but shouldnt effect it to much.

while ($arr = @mysql_fetch_assoc($res )) {

Using the @ will suppress an error.  Ok this works but is not ideal.  Use a count on the output and if >0 then do what you need with it.

$arr[name]  <<  All these should really be like this $arr['name'] to be more compliant.

My guess with your problem is you maybe need to unset $res and $arr, but thats just a quick guess.


EDIT:

Ok took a proper look at the file.  Below your code is where it outputs the actual torrent table...
if ($count) {
        print($pagertop);

        torrenttable($res);

        print($pagerbottom);
}

What you have done then is overwritten the $res variable with your new code.  Either move your code above the query or change your code from $res to something else. 

rabtb

using tbdev08

can anyone help me please when i add code for my staff recommended torrents and try show on browse it works fine but no torrents show

i added line 247-263 but cant figure out why it stopping torrents showing

code added

begin_table();
?>
<b><center><font size=2><font color=black>Our Staff Recommend</font></font></b>
<table cellpadding="4" cellspacing="1" border="0" style="width:450px" class="tableinborder" ><tr><td class="tabletitle"style="width:450px" align="left">Torrent Name</td><td class="tabletitle" align="left">Seeders</td><td class="tabletitle" align="left">Leechers</td></tr>
<?
$res=mysql_query("SELECT id,leechers,seeders,name FROM torrents WHERE recommended='1' ORDER BY id") or print(mysql_error());

while ($arr = @mysql_fetch_assoc($res )) {
echo "</td><td class=tablea align=\"left\"><b><a href=details.php?id=" . $arr[id] . ">". $arr[name] . "</b></td>
</td><td class=tablea align=\"left\"><b><font color=red>". $arr[seeders] . "</font></b></td><td class=tablea align=\"left\"><b>". $arr[leechers] . "</b></td></tr>";


}

end_table();



browse
<?

ob_start("ob_gzhandler");

require_once("include/bittorrent.php");


dbconn(false);

loggedinorreturn();
$wherethisuser = where ($_SERVER["SCRIPT_FILENAME"],$CURUSER["id"]);
parked();


$cats = genrelist();

$searchstr = unesc($_GET["search"]);
$cleansearchstr = searchfield($searchstr);
if (empty($cleansearchstr))
unset($cleansearchstr);

// sorting by MarkoStamcar

if ($_GET['sort'] && $_GET['type']) {

$column = '';
$ascdesc = '';

switch($_GET['sort']) {
case '1': $column = "name"; break;
case '2': $column = ""; break;
case '3': $column = "size"; break;
case '4': $column = "numfiles"; break;
case '5': $column = "comments"; break;
case '6': $column = "times_completed"; break;
case '7': $column = "seeders"; break;
case '8': $column = "leechers"; break;
case '9': $column = "owner"; break;
default: $column = "id"; break;
}

switch($_GET['type']) {
case 'asc': $ascdesc = "ASC"; $linkascdesc = "asc"; break;
case 'desc': $ascdesc = "DESC"; $linkascdesc = "desc"; break;
default: $ascdesc = "DESC"; $linkascdesc = "desc"; break;
}


$orderby = "ORDER BY torrents." . $column . " " . $ascdesc;
$pagerlink = "sort=" . intval($_GET['sort']) . "&type=" . $linkascdesc . "&";

} else {

$orderby = "ORDER BY torrents.sticky ASC, torrents.id DESC";
$pagerlink = "";

}



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

$wherea[] = "category!= '5'";
$wherea[] = "category!= '23'";
$wherea[] = "category!= '32'"; 
$wherea[] = "category!= '42'"; 
$wherea[] = "category!= '43'"; 
$wherea[] = "category!= '51'";


if ($_GET["incldead"] == 1)
{
        $addparam .= "incldead=1&amp;";
        if (!isset($CURUSER) || get_user_class() < UC_ADMINISTRATOR)
                $wherea[] = "banned != 'yes'";
}
elseif ($_GET["incldead"] == 2)
{
        $addparam .= "incldead=2&amp;";
                $wherea[] = "visible = 'no'";
}
elseif ($_GET["incldead"] == 3) {
    $addparam .= "incldead=3&amp;";
    $wherea[] = "free = 'yes'";
} else
                $wherea[] = "visible = 'yes'";

//       if ($CURUSER["view_xxx"] != "yes")
//$wherea[] = "category != '14'";

$category = (int)$_GET["cat"];

$all = $_GET["all"];
$blah = $_GET['blah'];

if (!$all)
        if (!$_GET && $CURUSER["notifs"])
        {
          $all = True;
          foreach ($cats as $cat)
          {
            $all &= $cat[id];
            if (strpos($CURUSER["notifs"], "[cat" . $cat[id] . "]") !== False)
            {
              $wherecatina[] = $cat[id];
              $addparam .= "c$cat[id]=1&amp;";
            }
          }
        }
        elseif ($category)
        {
          if (!is_valid_id($category))
            stderr("Error", "Invalid category ID.");
          $wherecatina[] = $category;
          $addparam .= "cat=$category&amp;";
        }
        else
        {
          $all = True;
          foreach ($cats as $cat)
          {
            $all &= $_GET["c$cat[id]"];
            if ($_GET["c$cat[id]"])
            {
              $wherecatina[] = $cat[id];
              $addparam .= "c$cat[id]=1&amp;";
            }
          }
        }

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 ($blah == 0) {
    $wherea[] = "torrents.name LIKE (" . sqlesc($searchstr) . ")";
  } elseif ($blah == 1) {
    $wherea[] = "MATCH (search_text, ori_descr) AGAINST (" . sqlesc($searchstr) . ")";
  } elseif ($blah == 2) {
    $wherea[] = "MATCH (search_text, ori_descr) AGAINST (" . sqlesc($searchstr) . ")";
  }
    $addparam .= "search=" . urlencode($searchstr) . "&amp;";
       // $orderby = "";
}

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

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

$res = mysql_query("SELECT COUNT(*) FROM torrents $where") or die(mysql_error());
$row = mysql_fetch_array($res);
$count = $row[0];

if (!$count && isset($cleansearchstr)) {
        $wherea = $wherebase;
       // $orderby = "ORDER BY id DESC";
        $searcha = explode(" ", $cleansearchstr);
        $sc = 0;
        foreach ($searcha as $searchss) {
                if (strlen($searchss) <= 1)
                        continue;
                $sc++;
                if ($sc > 5)
                        break;
                $ssa = array();
                if ($blah == 0) {
          foreach (array("torrents.name") as $sss)
            $ssa[] = "$sss LIKE '%" . sqlwildcardesc($searchss) . "%'";
            $wherea[] = "(" . implode(" OR ", $ssa) . ")";
        } elseif ($blah == 1) {
          foreach (array("search_text", "ori_descr") as $sss)
            $ssa[] = "$sss LIKE '%" . sqlwildcardesc($searchss) . "%'";
            $wherea[] = "(" . implode(" OR ", $ssa) . ")";
        } elseif ($blah == 2) {
          foreach (array("search_text", "ori_descr") as $sss)
            $ssa[] = "$sss LIKE '%" . sqlwildcardesc($searchss) . "%'";
            $wherea[] = "(" . implode(" OR ", $ssa) . ")";
   }
        }
        if ($sc) {
                $where = implode(" AND ", $wherea);
                if ($where != "")
                        $where = "WHERE $where";
                $res = mysql_query("SELECT COUNT(*) FROM torrents $where");
                $row = mysql_fetch_array($res);
                $count = $row[0];
        }
}

$torrentsperpage = $CURUSER["torrentsperpage"];
if (!$torrentsperpage)
        $torrentsperpage = 50;

if ($count)
{
if ($addparam != "") {
if ($pagerlink != "") {
  if ($addparam{strlen($addparam)-1} != ";") { // & = &amp;
    $addparam = $addparam . "&" . $pagerlink;
  } else {
    $addparam = $addparam . $pagerlink;
  }
}
    } else {
$addparam = $pagerlink;
    }
        list($pagertop, $pagerbottom, $limit) = pager($torrentsperpage, $count, "browse.php?" . $addparam);
        $query = "SELECT torrents.id, torrents.moderated, torrents.category, torrents.leechers, torrents.hidesize, torrents.seeders, torrents.request, torrents.scene, torrents.nuked, torrents.nukereason, torrents.free, torrents.name, torrents.sticky, torrents.vip, torrents.times_completed, torrents.size, torrents.added, UNIX_TIMESTAMP(torrents.added) as utadded, torrents.comments,torrents.numfiles,torrents.anonymous,torrents.filename,torrents.owner,torrents.seen,IF(torrents.nfo <> '', 1, 0) as nfoav," .
//        "IF(torrents.numratings < $minvotes, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, categories.name AS cat_name, categories.image AS cat_pic, users.username FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id $where $orderby $limit";
        "categories.name AS cat_name, categories.image AS cat_pic, users.username FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id $where $orderby $limit";
        $res = mysql_query($query) or die(mysql_error());
}
else
        unset($res);
if (isset($cleansearchstr))
        stdhead("Search results for \"$searchstr\"");
else

        stdhead();
               
               
               
               
        //      print'<center><table class=bordr width=400 border=1 cellspacing=0 cellpadding=4>';
    //    print("<tr><td align=center class=\"bordr\">Countdown</td></tr>\n");
   //    print("<tr><td align=center class=\"bordr\" <img src=\"http://www.fightcountdown.com/countdown/\" ></td></tr>\n");
  // print("</table>\n");


print("<br/><br/>");

begin_table();
?>
<b><center><font size=2><font color=black>Our Staff Recommend</font></font></b>
<table cellpadding="4" cellspacing="1" border="0" style="width:450px" class="tableinborder" ><tr><td class="tabletitle"style="width:450px" align="left">Torrent Name</td><td class="tabletitle" align="left">Seeders</td><td class="tabletitle" align="left">Leechers</td></tr>
<?
$res=mysql_query("SELECT id,leechers,seeders,name FROM torrents WHERE recommended='1' ORDER BY id") or print(mysql_error());

while ($arr = @mysql_fetch_assoc($res )) {
echo "</td><td class=tablea align=\"left\"><b><a href=details.php?id=" . $arr[id] . ">". $arr[name] . "</b></td>
</td><td class=tablea align=\"left\"><b><font color=red>". $arr[seeders] . "</font></b></td><td class=tablea align=\"left\"><b>". $arr[leechers] . "</b></td></tr>";


}

end_table();


?>


<STYLE TYPE="text/css" MEDIA=screen>

  a.catlink:link, a.catlink:visited{
                text-decoration: none;
        }

        a.catlink:hover {
                color: orange;
        }

</STYLE>
<p>
<b><center><font size=2><font color=yellow>Click Plus Sign To Show Categories </font></font></b>  <a href="javascript: klappe_news('browse')"><img border=0 src=/pic/plus.gif></a>
<form method="get" action="browseall.php">
<table width="70%" class="coltable" cellspacing="1" cellpadding="4" border="1">

<td class=bottom>

<table class=bottom>

<tr>
<td width=20% align=center><nobr>
<select name=blah>
<option value="0">Title Only</option>
<option value="1"<? print($blah == 1 ? " selected" : ""); ?>>Description</option>
<option value="2"<? print($blah == 2 ? " selected" : ""); ?>>Both</option>
                        </select>
<input type="text" id="searchinput" name="search" autocomplete="off" style="width: 420px;" ondblclick="suggest(event.keyCode,this.value);" onkeyup="suggest(event.keyCode,this.value);" onkeypress="return noenter(event.keyCode);" value="<?= htmlspecialchars($searchstr) ?>" />
<?= $deadchkbox ?>
<form method="get" action="browseall.php">
<nobr><b>Show:</b>
<select name=incldead><option value="0">Active Torrents</option>
<option value="1">Include Dead</option>
<option value="2">Only Dead</option>
<option value="3">Only Free</option>
</select>
<input type="submit" value="Search!">
</form>
<script language="JavaScript" src="suggest.js" type="text/javascript"></script>
<div id="suggcontainer" style="text-align: left; width: 250px; display: none;">
<div id="suggestions" style="cursor: default; position: absolute; background-color: orange; border: 1px solid #777777;"></div>
</div>


</td>
</tr>
</table>
<div id="kbrowse" style="display: none;"><table width=100% border="0" class=statusbar >
<tr>
<?
$cats = genrelist5();
$catdropdown = "";
foreach ($cats as $cat) {
$catdropdown .= "<option value=\"" . $cat["id"] . "\"";
if ($cat["id"] == $_GET["cat"])
$catdropdown .= " selected=\"selected\"";
$catdropdown .= ">" . htmlspecialchars($cat["name"]) . "</option>\n";
}

$i = 0;
foreach ($cats as $cat)
{
$catsperrow = 6;
print(($i && $i % $catsperrow == 0) ? "</tr><tr>" : "");
print("<td class=bottom style=\"padding-bottom: 2px;padding-left: 7px\"><input name=c$cat[id] type=\"checkbox\" " . (in_array($cat[id],$wherecatina) ? "checked " : "") . "value=1><b><a class=catlink href=browse.php?cat=$cat[id]>" . htmlspecialchars($cat[name]) . "</a></b></td>\n");
$i++;
}
?>

</tr>
</table>
</div>
</form></form>
<script language="JavaScript" src="suggest.js" type="text/javascript"></script>
<div id="suggcontainer" style="text-align: left; width: 250px; display: none;">
<div id="suggestions" style="cursor: default; position: absolute; background-color: 2d2d2d; border: 1px solid #777777;"></div>
</div>
<table class=main>

</tr>

</table>
</td>
</tr>
</table>
</form>

<?




if (isset($cleansearchstr))
print("<h2>Search results for \"" . htmlspecialchars($searchstr) . "\"</h2>\n");



if ($count) {
        print($pagertop);

        torrenttable($res);

        print($pagerbottom);
}
else {
        if (isset($cleansearchstr)) {
                print("<h2>Nothing found!</h2>\n");
                print("<p>Try again with a refined search string.</p>\n");
        }
        else {
                print("<h2>Nothing here!</h2>\n");
                print("<p>Sorry pal :(</p>\n");
        }
}

if ($CURUSER)
// Get the torrents with leechers but no seed.
$sn_lines = array();
$tnsr = mysql_query("SELECT id, name, size, leechers FROM torrents WHERE seeders = 0 AND leechers > 0") or sqlerr();
while ($tnsa = mysql_fetch_assoc($tnsr)) {
$pnsr = mysql_query("SELECT to_go FROM peers WHERE torrent = '" . $tnsa['id'] . "' ORDER BY to_go ASC LIMIT 1") or sqlerr();
if (mysql_num_rows($pnsr)) {
$pnsa = mysql_fetch_assoc($pnsr);
if ($pnsa['to_go'] >= $tnsa['size']) continue;
$perc = round((($tnsa['size'] - $pnsa['to_go']) / $tnsa['size']) * 100, 2) . "%";
}
else continue;
$sn_lines[] = '<b><a href="/details.php?id=' . $tnsa['id'] . '&hit=1">' . $tnsa['name'] .
'</a><font
color=#0099FF><b>
(' . $tnsa['leechers'] . ($tnsa['leechers'] == 1 ? " leecher, $perc" : " leechers, $perc highest") . " completion rate)</b></font>";
}

if (count($st_lines)) {
foreach ($st_lines as $line) {
echo("$line\n");
}
}
if (count($sn_lines)) {
echo('<b><center><font color=green><h2>Torrents that need help!</h2></font></center>' . "\n");
echo("<table width=737 border=1 cellspacing=0 cellpadding=10><tr><td class=text>");
foreach ($sn_lines as $line) {
echo("$line<br>\n");
}
echo("</p>\n");
echo("</td></tr></table>");

}

mysql_query("UPDATE users SET last_browse=".gmtime()." where id=".$CURUSER['id']);

stdfoot();

?>