Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: jak podzielić na kilka linii
Forum PHP.pl > Forum > PHP
kubal
Witam winksmiley.jpg

Ten kawałek kodu wyświetla u mnie jakieś tam kategorie:
Kod
<table class="cat_list hide" id="taglist">
             <tr class="genre_list">
             <?
             $i = 0;
             foreach ($cats as $cat)
             {
                 $catsperrow = 7;
                 print(($i && $i % $catsperrow == 0) ? "</tr><tr>" : "");
                 print("<td class=\"bottom\" style=\"padding-bottom: 2px; padding-left: 10px;\"><input name=\"c$cat[id]\" type=\"checkbox\" " . (in_array($cat[id],$wherecatina) ? "checked " : "") . "value=\"1\">" . htmlspecialchars($cat[name]) . "</td>\n");
                 $i++;
             }
             ?>
             </tr>
</table>

i wygląda to tak:

jak widać tylko góra jest "zamalowana" gdyż trzeba to tak podzielić aby w jednej linii było tylko 7 kategorii bo na razie podzieliło to się tak tylko dlatego że dałem tam style=\"padding-bottom: 2px; padding-left: 10px;\ a chce aby to wyglądało tak (w kodzie):
Kod
<tr class="genre_list">
7 kategorii
</tr>
<tr class="genre_list">
7 kategorii
</tr>

Właśnie nie wiem czy da się tak to zrobić... Gdyby jednak coś dało się zrobić to ułatwiłoby mi to dalsze "tworzenie" strony winksmiley.jpg Bardzo proszę o pomoc
Pozdrawiam

PS. jak potrzebujecie więcej kodu (pobieranie kategorii z bazy itp.) to podeśle winksmiley.jpg
PS2. mam nadzieje że zrozumieliście o co mi mniej-więcej chodzi winksmiley.jpg
ayeo
W foreach robisz zmienną, którą przy każdym przebiegu inkrementujesz. Sprawdzasz też czy czasem nie równa się 7. Jeśli tak to ustawiasz ją na 0 z powrotem i łamiesz linię.

Pozdrawiam!
kubal
hmm .. ;]

a trochę jaśniej. ? ;p bo nie za bardzo rozumiem
ayeo
  1. <?php
  2. x = 0;
  3.  
  4. foreach()
  5. {
  6. if($x == 7) $x = 0;
  7.  
  8. if( $x == 0) echo "<tr>";
  9. echo "<td>row</td>";
  10. if( $x == 0) echo "</tr>";
  11.  
  12. $x++;
  13. }
  14. ?>


Taki pseudo kod smile.gif
kubal
niestety nie potrafię sobie poradzić z tym co dałeś... cały czas próbuje ale bezskutecznie sad.gif (albo wyskakuje błąd albo nie działa . ;/)
ayeo
No to niestety nie jesteśmy w stanie Ci pomóc. Może wkleisz swój kod? To bardzo by pomogło bo szklana kula się zepsuła. Pozdrawiam!
kubal
  1. <?
  2.  
  3. ob_start("ob_gzhandler");
  4.  
  5. require_once("include/func.php");
  6. require_once("functions/torrenttable.php");
  7.  
  8. dbconn(false);
  9.  
  10. loggedinorreturn();
  11. parked();
  12.  
  13. //wyswietla kategorie
  14. $cats = genrelist();
  15.  
  16.  
  17. $searchstr = unesc($_GET["search"]);
  18. $cleansearchstr = searchfield($searchstr);
  19. if (empty($cleansearchstr))
  20.    unset($cleansearchstr);
  21.  
  22. $orderby = "ORDER BY torrents.id DESC";
  23.  
  24. $addparam = "";
  25. $wherea = array();
  26. $wherecatina = array();
  27.  
  28. if ($_GET["incldead"] == 1)
  29. {
  30.    $addparam .= "incldead=1&amp;";
  31.    if (!isset($CURUSER) || get_user_class() < UC_ADMINISTRATOR)
  32.        $wherea[] = "banned != 'yes'";
  33. }
  34. elseif ($_GET["incldead"] == 2)
  35. {
  36.    $addparam .= "incldead=2&amp;";
  37.        $wherea[] = "visible = 'no'";
  38. }
  39.    else
  40.        $wherea[] = "visible = 'yes'";
  41.  
  42. $category = (int)$_GET["cat"];
  43.  
  44. if (count($wherecatina) > 1)
  45.    $wherecatin = implode(",",$wherecatina);
  46. elseif (count($wherecatina) == 1)
  47.    $wherea[] = "category = $wherecatina[0]";
  48.  
  49. $wherebase = $wherea;
  50.  
  51. if (isset($cleansearchstr))
  52. {
  53.    $wherea[] = "MATCH (search_text, ori_descr) AGAINST (" . sqlesc($searchstr) . ")";
  54.    //$wherea[] = "0";
  55.    $addparam .= "search=" . urlencode($searchstr) . "&amp;";
  56.    $orderby = "";
  57. }
  58.  
  59. $where = implode(" AND ", $wherea);
  60. if ($wherecatin)
  61.    $where .= ($where ? " AND " : "") . "category IN(" . $wherecatin . ")";
  62.  
  63. if ($where != "")
  64.    $where = "WHERE $where";
  65.  
  66. $res = mysql_query("SELECT COUNT(*) FROM torrents $where") or die(mysql_error());
  67. $row = mysql_fetch_array($res);
  68. $count = $row[0];
  69.  
  70. if (!$count && isset($cleansearchstr)) {
  71.    $wherea = $wherebase;
  72.    $orderby = "ORDER BY id DESC";
  73.    $searcha = explode(" ", $cleansearchstr);
  74.    $sc = 0;
  75.    foreach ($searcha as $searchss) {
  76.        if (strlen($searchss) <= 1)
  77.            continue;
  78.        $sc++;
  79.        if ($sc > 5)
  80.            break;
  81.        $ssa = array();
  82.        foreach (array("search_text", "ori_descr") as $sss)
  83.            $ssa[] = "$sss LIKE '%" . sqlwildcardesc($searchss) . "%'";
  84.        $wherea[] = "(" . implode(" OR ", $ssa) . ")";
  85.    }
  86.    if ($sc) {
  87.        $where = implode(" AND ", $wherea);
  88.        if ($where != "")
  89.            $where = "WHERE $where";
  90.        $res = mysql_query("SELECT COUNT(*) FROM torrents $where");
  91.        $row = mysql_fetch_array($res);
  92.        $count = $row[0];
  93.    }
  94. }
  95.  
  96. $torrentsperpage = $CURUSER["torrentsperpage"];
  97. if (!$torrentsperpage)
  98.    $torrentsperpage = 15;
  99.  
  100. if ($count)
  101. {
  102.    list($pagertop, $pagerbottom, $limit) = pager($torrentsperpage, $count, "browse.php?" . $addparam);
  103.    $query = "SELECT torrents.id, torrents.category, torrents.leechers, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments,torrents.numfiles,torrents.filename,torrents.owner,IF(torrents.nfo <> '', 1, 0) as nfoav," .
  104. "categories.name AS cat_name, categories.image AS cat_pic, users.username, users.anonymous FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id $where $orderby $limit";
  105.    "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";
  106.    $res = mysql_query($query) or die(mysql_error());
  107. }
  108. else
  109.    unset($res);
  110.  
  111. ?>
  112.  
  113. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  114. <html>
  115. <head>
  116. <title> My homepage </title>
  117.    <script src="torrents/jquery.js" type="text/javascript"></script>
  118.    <script src="torrents/jquery_ui.js" type="text/javascript"></script>
  119.    <script src="torrents/global.js" type="text/javascript"></script>
  120.    <script type="text/javascript">var $j = jQuery;</script>
  121.    <script src="torrents/browse.js" type="text/javascript"></script>
  122. </head>
  123.  
  124. <body>
  125. <div id="wrapper">
  126. <div id="naglowek">
  127.  
  128. <div id="grants"><br><br></div>
  129.  
  130.  
  131. </div>
  132. <div id="content">
  133.  
  134.  
  135.  
  136. <br><form name="filter" method="get" action="">
  137. <div class="filter_torrents">
  138.    <div class="box pad">
  139. <table>
  140.    <tr>
  141.        <td class="label">Search terms:</td>
  142.        <td colspan="3"><input type="text" size="40" style="width: 98%;" name="search" class="inputtext" value="" /></td>
  143.    </tr>
  144. </table>
  145.        <table class="cat_list hide" id="taglist">
  146.            <tr class="genre_list">
  147.            <?
  148.            $i = 0;
  149.            foreach ($cats as $cat)
  150.            {
  151.                $catsperrow = 7;
  152.                print(($i && $i % $catsperrow == 0) ? "</tr><tr>" : "");
  153.                print("<td class=\"bottom\" style=\"padding-bottom: 2px; padding-left: 10px;\"><input name=\"c$cat[id]\" type=\"checkbox\" " . (in_array($cat[id],$wherecatina) ? "checked " : "") . "value=\"1\">" . htmlspecialchars($cat[name]) . "</td>\n");
  154.                $i++;
  155.            }
  156.            ?>
  157.            </tr>
  158.            <tr class="cat_img">
  159.                <td class="label" colspan="2">Szukaj w:</td>
  160.                <td colspan="6">
  161.                    <select name="incldead">
  162.                        <option value="0">tylko aktywne</option>
  163.                        <option value="1"<? print($_GET["incldead"] == 1 ? " selected" : ""); ?>>wraz z martwymi</option>
  164.                        <option value="2"<? print($_GET["incldead"] == 2 ? " selected" : ""); ?>>tylko martwe</option>
  165.                    </select>
  166.                </td>
  167.            </tr>
  168.        </table>
  169.        <table class="cat_list" width="100%">
  170.             <tr class="cat_img">
  171.                <td class="label2">
  172.                <a href="#" onclick="$j('#taglist').toggle('blind', {}, 500); return false;" id="swaptags">Zaawansowane wyszukiwanie</a></td>
  173.            </tr>
  174.        </table>
  175.        <div class="submit">
  176.            <input type="submit" value="Filter Torrents">
  177.            <input type="button" value="Reset" onclick="location.href='browse.php'">
  178.        </div>
  179.    </div>
  180. </div>
  181. </form>
  182.  
  183.  
  184. </div></div>
  185. </body>
  186. </html>


to jak pomoże ktoś.? winksmiley.jpg
ayeo
~kubal, przestań podbijać swój temat. Jak ktoś będzie chciał Ci pomóc to Ci pomoże. Nie tylko Ty masz tutaj problem. Czekaj cierpliwie na odpowiedź. Nie ma nic złego w podbijaniu tematu, ale nie po 10 minutach!
kubal
no ok sory winksmiley.jpg ale ja to naprawdę potrzebuje jak najszybciej bo bez tego nie mogę dalej nic robić... sad.gif

Pomoże ktoś? Proszę o pomoc sad.gif
bartg
To
  1. <?
  2.           $i = 0;
  3.           foreach ($cats as $cat)
  4.           {
  5.               $catsperrow = 7;
  6.               print(($i && $i % $catsperrow == 0) ? "</tr><tr>" : "");
  7.               print("<td class=\"bottom\" style=\"padding-bottom: 2px; padding-left: 10px;\"><input name=\"c$cat[id]\" type=\"checkbox\" " . (in_array($cat[id],$wherecatina) ? "checked " : "") . "value=\"1\">" . htmlspecialchars($cat[name]) . "</td>\n");
  8.               $i++;
  9.           }
  10.           ?>
zamien na
  1. <?
  2.           $i = 0;
  3.           foreach ($cats as $k => $cat)
  4.           {
  5.                if($k%7==0) echo '</tr><tr class="genre_list">';
  6.               $catsperrow = 7;
  7.               print(($i && $i % $catsperrow == 0) ? "</tr><tr>" : "");
  8.               print("<td class=\"bottom\" style=\"padding-bottom: 2px; padding-left: 10px;\"><input name=\"c$cat[id]\" type=\"checkbox\" " . (in_array($cat[id],$wherecatina) ? "checked " : "") . "value=\"1\">" . htmlspecialchars($cat[name]) . "</td>\n");
  9.               $i++;
  10.           }
  11.           ?>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.