Noob question: Simple PHP - $10 for an answer that works

Discussion in 'PHP' started by thewindmaster, Jan 11, 2007.

  1. #1
    I am trying to modify the download module in PHP nuke.

    I want the downloads to show in two colums instead of one. Here is the acutal page: http://www.dailytemplate.com/modules.php?name=Downloads&d_op=viewdownload&cid=1

    I am guessing that the display code need to be wrap in some type of if count< and count++ code. I just do not know exactly how to configure that or what code is the actual display code.

    Any help would be appreciated

    I am pretty confident that the below code is where the change needs to be made. However, I attached the entire page code just in case.


    function viewdownload($cid, $min, $orderby, $show) {
        global $prefix, $db, $admin, $perpage, $module_name, $user, $admin_file, $mainvotedecimal, $datetime, $transfertitle, $locale;
        include("header.php");
        if (!isset($min)) $min=0;
        if (!isset($max)) $max=$min+$perpage;
        if(!empty($orderby)) {
    	$orderby = convertorderbyin($orderby);
        } else {
    	$orderby = "title ASC";
        }
        if (!empty($show)) {
    	$perpage = $show;
        } else {
    	$show=$perpage;
        }
        menu(1);
        echo "<br>";
        OpenTable();
        $cid = intval($cid);
        $result = $db->sql_query("SELECT title,parentid FROM ".$prefix."_downloads_categories WHERE cid='$cid'");
    	list($title,$parentid)=$db->sql_fetchrow($result);
    	$title = filter($title, "nohtml");
    	$parentid = intval($parentid);
    	$title=getparentlink($parentid,$title);
    	$title="<a href=modules.php?name=$module_name>"._MAIN."</a>/$title";
        echo "<center><font class=\"option\"><b>"._CATEGORY.": $title</b></font></center><br>";
        echo "<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\" align=\"center\"><tr>";
        $cid = intval($cid);
        $result2 = $db->sql_query("SELECT cid, title, cdescription FROM ".$prefix."_downloads_categories WHERE parentid='$cid' order by title");
    	$dum = 0;
        $count = 0;
        while(list($cid2, $title2, $cdescription2) = $db->sql_fetchrow($result2)) {
        	$cid2 = intval($cid2);
        	$title2 = filter($title2, "nohtml");
        	$cdescription2 = filter($cdescription2);
        	$cresult = $db->sql_query("SELECT * FROM ".$prefix."_downloads_downloads WHERE cid='$cid2'");
            $cnumrows = $db->sql_numrows($cresult);
    		echo "<td><font class=\"option\"><strong><big>&middot;</big></strong> <a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid2\"><b>$title2</b></a></font> ($cnumrows)";
    		categorynewdownloadgraphic($cid2);
    		if ($cdescription2) {
    	    	echo "<font class=\"content\">$cdescription2</font><br>";
    		} else {
    	    	echo "<br>";
    		}
    		$result3 = $db->sql_query("SELECT cid, title FROM ".$prefix."_downloads_categories WHERE parentid='$cid2' order by title limit 0,3");
    		$space = 0;
    		while(list($cid3, $title3) = $db->sql_fetchrow($result3)) {
                $cid3 = intval($cid3);
                $title3 = filter($title3, "nohtml");
        	    if ($space>0) {
    				echo ",&nbsp;";
    	    	}
                $cresult2 = $db->sql_query("SELECT * FROM ".$prefix."_downloads_downloads WHERE cid='$cid3'");
                $cnumrows2 = $db->sql_numrows($cresult2);
    	    	echo "<font class=\"content\"><a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid3\">$title3</a> ($cnumrows2)</font>";
    	    	$space++;
    		}
    		if ($count<1) {
    	    	echo "</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
    	    	$dum = 1;
    		}
    		$count++;
    		if ($count==2) {
    	    	echo "</td></tr><tr>";
    	    	$count = 0;
    	    	$dum = 0;
    		}
        }
        if ($dum == 1) {
    		echo "</tr></table>";
        } elseif ($dum == 0) {
    		echo "<td></td></tr></table>";
        }
    
        echo "<hr noshade size=\"1\">";
        $orderbyTrans = convertorderbytrans($orderby);
        echo "<center><font class=\"content\">"._SORTDOWNLOADSBY.": "
            .""._TITLE." (<a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid&amp;orderby=titleA\">A</a>\<a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid&amp;orderby=titleD\">D</a>) "
            .""._DATE." (<a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid&amp;orderby=dateA\">A</a>\<a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid&amp;orderby=dateD\">D</a>) "
            .""._RATING." (<a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid&amp;orderby=ratingA\">A</a>\<a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid&amp;orderby=ratingD\">D</a>) "
            .""._POPULARITY." (<a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid&amp;orderby=hitsA\">A</a>\<a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid&amp;orderby=hitsD\">D</a>)"
    	."<br><b>"._RESSORTED.": $orderbyTrans</b></font></center><br><br>";
        $result=$db->sql_query("SELECT lid, title, description, date, hits, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage FROM ".$prefix."_downloads_downloads WHERE cid='$cid' order by $orderby limit $min,$perpage ");
        $fullcountresult=$db->sql_query("SELECT lid, title, description, date, hits, downloadratingsummary, totalvotes, totalcomments FROM ".$prefix."_downloads_downloads WHERE cid='$cid'");
        $totalselecteddownloads = $db->sql_numrows($fullcountresult);
        echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"10\" border=\"0\"><tr><td><font class=\"content\">";
        $x=0; 
        while(list($lid, $title, $description, $time, $hits, $downloadratingsummary, $totalvotes, $totalcomments, $filesize, $version, $homepage)=$db->sql_fetchrow($result)) {
            $lid = intval($lid);
            $hits = intval($hits);
            $totalvotes = intval($totalvotes);
            $totalcomments = intval($totalcomments);
    	$downloadratingsummary = number_format($downloadratingsummary, $mainvotedecimal);
    	$title = filter($title, "nohtml");
    	$description = filter($description);
            global $prefix, $db, $admin;
    	if (is_admin($admin)) {
    	    echo "<a href=\"".$admin_file.".php?op=DownloadsModDownload&amp;lid=$lid\"><img src=\"modules/$module_name/images/lwin.gif\" border=\"0\" alt=\""._EDIT."\"></a>&nbsp;&nbsp;";
    	} else {
    	    echo "<img src=\"modules/$module_name/images/lwin.gif\" border=\"0\" alt=\"\">&nbsp;&nbsp;";
    	}
            echo "<a href=\"modules.php?name=$module_name&amp;d_op=getit&amp;lid=$lid\">$title</a>";
    	newdownloadgraphic($datetime, $time);
    	popgraphic($hits);
    	/* INSERT code for *editor review* here */
    	detecteditorial($lid, $transfertitle, 1);
    	echo "<br>";
    	echo "<b>"._DESCRIPTION.":</b> $description<br>";
    	setlocale (LC_TIME, $locale);
    	ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
    	$datetime = strftime(""._LINKSDATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    	$datetime = ucfirst($datetime);
    	echo "<b>"._VERSION.":</b> $version <b>"._FILESIZE.":</b> ".CoolSize($filesize)."<br>";
    	echo "<b>"._ADDEDON.":</b> $datetime <b>"._UDOWNLOADS.":</b> $hits";
            $transfertitle = str_replace (" ", "_", $title);
            /* voting & comments stats */
            if ($totalvotes == 1) {
    	    $votestring = _VOTE;
            } else {
    	    $votestring = _VOTES;
    	}
            if ($downloadratingsummary!="0" || $downloadratingsummary!="0.0") {
    	    echo " <b>"._RATING.":</b> $downloadratingsummary ($totalvotes $votestring)";
    	}
            if (empty($homepage)) {
    	    echo "<br>";
    	} else {
    	    echo "<br><a href=\"$homepage\" target=\"new\">"._HOMEPAGE."</a> | ";
    	}
    	echo "<a href=\"modules.php?name=$module_name&amp;d_op=ratedownload&amp;lid=$lid\">"._RATERESOURCE."</a>";
            if (is_user($user)) {
    	    echo " | <a href=\"modules.php?name=$module_name&amp;d_op=brokendownload&amp;lid=$lid\">"._REPORTBROKEN."</a>";
    	}
    	echo " | <a href=\"modules.php?name=$module_name&amp;d_op=viewdownloaddetails&amp;lid=$lid\">"._DETAILS."</a>";
            if ($totalcomments != 0) {
    	    echo " | <a href=\"modules.php?name=$module_name&amp;d_op=viewdownloadcomments&amp;lid=$lid\">"._SCOMMENTS." ($totalcomments)</a>";
    	}
            detecteditorial($lid, $transfertitle, 0);
            echo "<br><br>";
    	$x++;
        }
        echo "</font>";
        $orderby = convertorderbyout($orderby);
        /* Calculates how many pages exist. Which page one should be on, etc... */
        $downloadpagesint = ($totalselecteddownloads / $perpage);
        $downloadpageremainder = ($totalselecteddownloads % $perpage);
        if ($downloadpageremainder != 0) {
                $downloadpages = ceil($downloadpagesint);
        	if ($totalselecteddownloads < $perpage) {
        		$downloadpageremainder = 0;
        	}
        } else {
        	$downloadpages = $downloadpagesint;
        }
        /* Page Numbering */
        if ($downloadpages!=1 && $downloadpages!=0) {
            echo "<br><br>";
          	echo ""._SELECTPAGE.": ";
         	$prev=$min-$perpage;
         	if ($prev>=0) {
        	    echo "&nbsp;&nbsp;<b>[ <a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid&amp;min=$prev&amp;orderby=$orderby&amp;show=$show\">";
        	    echo " &lt;&lt; "._PREVIOUS."</a> ]</b> ";
              }
        	$counter = 1;
     	$currentpage = ($max / $perpage);
           	while ($counter<=$downloadpages ) {
          	    $cpage = $counter;
          	    $mintemp = ($perpage * $counter) - $perpage;
          	    if ($counter == $currentpage) {
    		echo "<b>$counter</b>&nbsp;";
    	    } else {
    		echo "<a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid&amp;min=$mintemp&amp;orderby=$orderby&amp;show=$show\">$counter</a> ";
    	    }
           	    $counter++;
                   }
         	$next=$min+$perpage;
         	if ($x>=$perpage) {
        		echo "&nbsp;&nbsp;<b>[ <a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid&amp;min=$max&amp;orderby=$orderby&amp;show=$show\">";
        		echo " "._NEXT." &gt;&gt;</a> ]</b> ";
         	}
        }
        echo "</td></tr></table>";
        CloseTable();
        include("footer.php");
    }
    
    Code (markup):

    If it helps at all the categories display does show two columns. I think the code for it is the following

    function index() {
        global $prefix, $db, $show_links_num, $module_name;
        include("header.php");
        $maindownload = 0;
        menu($maindownload);
        echo "<br>";
        OpenTable();
        echo "<center><font class=\"title\"><b>"._DOWNLOADSMAINCAT."</b></font></center><br>";
        echo "<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\" align=\"center\"><tr>";
        $sql = "SELECT cid, title, cdescription FROM ".$prefix."_downloads_categories WHERE parentid='0' ORDER BY title";
        $result = $db->sql_query($sql);
        $count = 0;
        while ($row = $db->sql_fetchrow($result)) {
    	$cid = intval($row['cid']);
    	$title = filter($row['title'], "nohtml");
    	$cdescription = filter($row['cdescription']);
    	if ($show_links_num == 1) {
    	    $cnumrows = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_downloads_downloads WHERE cid='$cid'"));
    	    $cnumm = "($cnumrows)";
    	} else {
    	    $cnumm = "";
    	}
    	echo "<td><font class=\"option\"><strong><big>&middot;</big></strong> <a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid\"><b>$title</b></a>$cnumm</font>";
    	categorynewdownloadgraphic($cid);
    	if ($cdescription) {
    	    echo "<br><font class=\"content\">$cdescription</font><br>";
    	} else {
    	    echo "<br>";
    	}
    	$sql2 = "SELECT cid, title FROM ".$prefix."_downloads_categories WHERE parentid='$cid' ORDER BY title LIMIT 0,3";
    	$result2 = $db->sql_query($sql2);
    	$space = 0;
        $cnum = "";
    	while ($row2 = $db->sql_fetchrow($result2)) {
    		$cid = intval($row2['cid']);
    		$stitle = filter($row2['title'], "nohtml");
       	    if ($space>0) {
    			echo ",&nbsp;";
    	    }
            if ($show_links_num == 1) {
            	$cnumrows2 = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_downloads_downloads WHERE cid='$cid'"));
    			$cnum = " ($cnumrows2)";
    	    } else {
    			$cnumrows2 = "";
    	    }
    	    echo "<font class=\"content\"><a href=\"modules.php?name=$module_name&amp;d_op=viewdownload&amp;cid=$cid\">$stitle</a>$cnum</font>";
    	    $space++;
    	}
    	if ($count<1) {
    	    echo "</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
    	    $dum = 1;
    	}
    	$count++;
    	if ($count==2) {
    	    echo "</td></tr><tr>";
    	    $count = 0;
    	    $dum = 0;
    	}
        }
        if ($dum == 1) {
    	echo "</tr></table>";
        } elseif ($dum == 0) {
    	echo "<td></td></tr></table>";
        }
        $numrows = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_downloads_downloads"));
        $catnum = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_downloads_categories"));
        echo "<center><font class=\"content\">"._THEREARE." <b>$numrows</b> "._DOWNLOADS." "._AND." <b>$catnum</b> "._CATEGORIES." "._INDB."</font></center>";
        CloseTable();
        include("footer.php");
    }
    Code (markup):
     
    thewindmaster, Jan 11, 2007 IP
  2. brentl

    brentl Peon

    Messages:
    252
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In you ViewDownload function there is this code:

    $count++;
    if ($count==2) {
    echo "</td></tr><tr>";
    $count = 0;
    $dum = 0;
    }


    Since you only have 3 on that page count is not 2 until the third download is displayed (0,1,2). However, you need to check for each time there is an even number of downloads already displayed. Try using the fmod function in the if statement:


    if (fmod(count,2)=0) {
     
    brentl, Jan 11, 2007 IP
  3. thewindmaster

    thewindmaster The Man with the Plan

    Messages:
    845
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Brnetl,

    I appreciate your help and feedback but I believe the code you are referring to controls the subcategories to be displayed (if there were subcategories) above the listings. You can tell this code applies to the subcategories because it is identical to the main categories display part and it is above the code for echo "<hr noshade size=\"1\">"; which is the horizontal rule shown on the page.

    What needs to happen is some type of count function like this need to also apply to the code which displays the listings. I think it starts somewhere around the $X=0 line.
     
    thewindmaster, Jan 11, 2007 IP
  4. thewindmaster

    thewindmaster The Man with the Plan

    Messages:
    845
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thewindmaster, Jan 11, 2007 IP