Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP]Quick.Car a php
Forum PHP.pl > Forum > Przedszkole
danielk32
Potrzebuje dodać funkcje skracającą opis tzn. zajawke opisu znalazłem taką funkcję

Kod
<?php
function zajawka($txt, $dlugosc_zajawki){
    if(strlen($txt) <= $dlugosc_zajawki)
        return $txt;

    while($txt{$dlugosc_zajawki} != ' ' && strlen($txt) > $dlugosc_zajawki)
        ++ $dlugosc_zajawki;

    $str = substr($txt, 0, $dlugosc_zajawki);

    if(strlen($txt) > $dlugosc_zajawki){
        $str .= "&hellip;";
    }

    return $str;
}

echo zajawka($loremIpsum, 20);
?>


ten kod muszę umieścić w kodzie tej witryny we wskazanym miejscu.

Kod
<?
include("include/gora.php");
echo "
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-2\"

</head>

<body>
<CENTER>

<form action=\"rezultaty.php\" method=\"post\">
Szukaj wg:
</BR>
</BR>
<select name=\"metoda_szukania\">
<option value=\"przedmiot\">Przedmiot
<option value=\"autor\">Autor
<option value=\"kat\">Kategoria
<option value=\"nr_inw\">Nr. inw

</select>
</BR>
</BR>
WprowadĽ poszukiwane wyrażenie:<br />
<input name=\"wyrazenie\" type=\"text\">
</BR>
</BR>
<input type=\"submit\" value=\"Szukaj\">
</form>
</center>
</body>
</html>
";
?>
<html>
<head>
<title>Karta eksponatów - wyniki wyszukiwania</title>
<meta http-equiv="Content-Type" content="text/html; CHARSET=ISO-8859-2"
</head>
<body>
<table align="center" border="" width="95%" cellspacing="0" cellpadding="0" >
<tr>
<td width="91%" colspan="7" bgcolor="#C0C0C0">
<p align="center"><b><font size="2">Wykaz kart eksponatów</font></b></td>
</tr>
<tr>
<td width="4%" align="center" bgcolor="#E0E0E0"><p align="center"><font size="2">ID</font></td>
<td width="10%" align="center" bgcolor="#E0E0E0"><p align="center"><font size="2">Przedmiot</font></td>

<td width="8%" align="center" bgcolor="#E0E0E0"><font size="2">Fotografia</font></td>

<td width="10%" align="center" bgcolor="#E0E0E0"><font size="2">Autor</font></td>
<td width="8%" align="center" bgcolor="#E0E0E0"><font size="2">Kategoria</font></td>
<td width="10%" align="center" bgcolor="#E0E0E0"><font size="2">Nr inw.</font></td>

<td width="10%" align="center" bgcolor="#E0E0E0"><font size="2">skrócony opis</font></td>

<td width="8%" align="center" bgcolor="#E0E0E0"><p align="center"><font size="2">Działanie</font></td>

</body>
</HTML>
<?
include("include/globals.php");
require("paging_class.php");

$paging=new paging(8,3);
require("../config.php");


$qw=explode_keyword($_GET[keyword]);

$paging->query("select * from historia where $qw order by karta_id asc");

$page=$paging->print_info();

if (!empty($page["keyword"]))
echo "Keyword : <b>$page[keyword]</b><br>\n";

if (empty($page["total"])) {
echo "<u>Not Found</u>\n";
} else {
echo "Rekord $page[start] - $page[end] z $page[total] [wszystkich $page[total_pages] stron]<br>\n";
}



while ($result=$paging->result_assoc())
{
$color=$paging->print_color("#999999","#999999")
?>

<?


{




echo "<tr><div align=\"center\">
<td width=\"4%\">".$result['karta_id']."</td>
<td width=\"16%\">".$result['przedmiot']."</td>


<td width=\"10%\"><center><img src=../../../upload/hi/".$result['obrazek'].".jpg width='160'></center></td>

<td width=\"14%\">".$result['autor']."</td>
<td width=\"8%\">".$result['kat']."</td>
<td width=\"10%\">".$result['nr_inw']."</td>

<td width=\"10%\">".$result['opis']."</td> [i][b]<--ale wyświetla cały opis niestety a chce tylko zajawke[/b][/i]

<td width=\"8%\"><center><a href=\"karta.php?id=".$result['karta_id']."\">Pokaż kartę</a></center></td>
</tr></div>";
}

}

echo" </table>\n";
echo "<A HREF=\"szukaj.php?&page=1\">pierwsza </A>";
echo $paging->print_link();

//FUNCTION
function explode_keyword($q)
{
//trim
$q=trim($q);
$q=preg_replace("/[\s]+/"," ",$q);

$mode="AND";
$q2=explode(" ",$q);
for ($i=0;$i<count($q2);$i++) {
$condition=$condition."nr_inw"." like '%".$q2["$i"]."%' ".$mode." ";
}
$condition=substr($condition,0,-4);
return $condition;
}
?>
<?
echo "<A HREF=\"szukaj.php?&page=$page[total_pages]\">ostatnia</A>";
?>
<?php
include("count.php")
?>


Proszę o pomoc
pedro84
A może powiesz co Ci się wykrzacza bo pytania żadnego nie widzę.
danielk32
Potrzebuję dopisać tą funkcję pierwszą do kodu poniżej i ją wywołać jak tworzy się dynamiczna tabela.
pedro84
No i z czym masz problem? Dodaj ją po prostu do tego kodu a w miejscu gdzie wyświetlasz treść dodaj
  1. zajawka($tresc, długość)
danielk32
próbowałem to robić tak, ale nie działa

  1. <?
  2. include("include/gora.php");
  3. <html>
  4. <head>
  5. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-2\"
  6.  
  7. </head>
  8.  
  9. <body>
  10. <CENTER>
  11.  
  12. <form action=\"rezultaty.php\" method=\"post\">
  13. Szukaj wg:
  14. </BR>
  15. </BR>
  16. <select name=\"metoda_szukania\">
  17. <option value=\"przedmiot\">Przedmiot
  18. <option value=\"autor\">Autor
  19. <option value=\"kat\">Kategoria
  20. <option value=\"nr_inw\">Nr. inw
  21.  
  22. </select>
  23. </BR>
  24. </BR>
  25. WprowadĽ poszukiwane wyrażenie:<br />
  26. <input name=\"wyrazenie\" type=\"text\">
  27. </BR>
  28. </BR>
  29. <input type=\"submit\" value=\"Szukaj\">
  30. </form>
  31. </center>
  32. </body>
  33. </html>
  34. ";
  35. ?>
  36. <html>
  37. <head>
  38. <title>Karta eksponatów - wyniki wyszukiwania</title>
  39. <meta http-equiv="Content-Type" content="text/html; CHARSET=ISO-8859-2"
  40. </head>
  41. <body>
  42. <table align="center" border="" width="95%" cellspacing="0" cellpadding="0" >
  43. <tr>
  44. <td width="91%" colspan="7" bgcolor="#C0C0C0">
  45. <p align="center"><b><font size="2">Wykaz kart eksponatów</font></b></td>
  46. </tr>
  47. <tr>
  48. <td width="4%" align="center" bgcolor="#E0E0E0"><p align="center"><font size="2">ID</font></td>
  49. <td width="10%" align="center" bgcolor="#E0E0E0"><p align="center"><font size="2">Przedmiot</font></td>
  50.  
  51. <td width="8%" align="center" bgcolor="#E0E0E0"><font size="2">Fotografia</font></td>
  52.  
  53. <td width="10%" align="center" bgcolor="#E0E0E0"><font size="2">Autor</font></td>
  54. <td width="8%" align="center" bgcolor="#E0E0E0"><font size="2">Kategoria</font></td>
  55. <td width="10%" align="center" bgcolor="#E0E0E0"><font size="2">Nr inw.</font></td>
  56.  
  57. <td width="10%" align="center" bgcolor="#E0E0E0"><font size="2">skrócony opis</font></td>
  58.  
  59. <td width="8%" align="center" bgcolor="#E0E0E0"><p align="center"><font size="2">Działanie</font></td>
  60.  
  61. </body>
  62. </HTML>
  63. <?
  64. include("include/globals.php");
  65. require("paging_class.php");
  66.  
  67. $paging=new paging(8,3);
  68. require("../config.php");
  69.  
  70.  
  71. $qw=explode_keyword($_GET[keyword]);
  72.  
  73. $paging->query("select * from historia where $qw order by karta_id asc");
  74.  
  75. $page=$paging->print_info();
  76.  
  77. if (!empty($page["keyword"]))
  78. echo "Keyword : <b>$page[keyword]</b><br>\n";
  79.  
  80. if (empty($page["total"])) {
  81. echo "<u>Not Found</u>\n";
  82. } else {
  83. echo "Rekord $page[start] - $page[end] z $page[total] [wszystkich $page[total_pages] stron]<br>\n";
  84. }
  85.  
  86.  
  87.  
  88. while ($result=$paging->result_assoc())
  89. {
  90. $color=$paging->print_color("#999999","#999999")
  91. ?>
  92.  
  93. <?
  94.  
  95. function zajawka($txt, $dlugosc_zajawki){
  96. if(strlen($txt) <= $dlugosc_zajawki)
  97. return $txt;
  98.  
  99. while($txt{$dlugosc_zajawki} != ' ' && strlen($txt) > $dlugosc_zajawki)
  100. ++ $dlugosc_zajawki;
  101.  
  102. $str = substr($txt, 0, $dlugosc_zajawki);
  103.  
  104. if(strlen($txt) > $dlugosc_zajawki){
  105. $str .= "&hellip;";
  106. }
  107.  
  108. return $str;
  109. }
  110.  
  111. {
  112.  
  113.  
  114.  
  115.  
  116. echo "<tr><div align=\"center\">
  117. <td width=\"4%\">".$result['karta_id']."</td>
  118. <td width=\"16%\">".$result['przedmiot']."</td>
  119.  
  120.  
  121. <td width=\"10%\"><center><img src=../../../upload/hi/".$result['obrazek'].".jpg width='160'></center></td>
  122.  
  123. <td width=\"14%\">".$result['autor']."</td>
  124. <td width=\"8%\">".$result['kat']."</td>
  125. <td width=\"10%\">".$result['nr_inw']."</td>
  126.  
  127. <td width=\"10%\">"zajawka(.$result['opis']., 20)"</td> <-- tutaj potrzebuje to wyłować
  128.  
  129. <td width=\"8%\"><center><a href=\"karta.php?id=".$result['karta_id']."\">Pokaż kartę</a></center></td>
  130. </tr></div>";
  131. }
  132.  
  133. }
  134.  
  135. echo" </table>\n";
  136. echo "<A HREF=\"szukaj.php?&page=1\">pierwsza </A>";
  137. echo $paging->print_link();
  138.  
  139. //FUNCTION
  140. function explode_keyword($q)
  141. {
  142. //trim
  143. $q=trim($q);
  144. $q=preg_replace("/[\s]+/"," ",$q);
  145.  
  146. $mode="AND";
  147. $q2=explode(" ",$q);
  148. for ($i=0;$i<count($q2);$i++) {
  149. $condition=$condition."nr_inw"." like '%".$q2["$i"]."%' ".$mode." ";
  150. }
  151. $condition=substr($condition,0,-4);
  152. return $condition;
  153. }
  154. ?>
  155. <?
  156. echo "<A HREF=\"szukaj.php?&page=$page[total_pages]\">ostatnia</A>";
  157. ?>
  158. <?php
  159. include("count.php")
  160. ?>
pedro84
Człowieku, przecież to podstawy:
  1. ".zajawka($result['opis'], 20)."
danielk32
działa ale tylko troszke bo skróciło pierwszy opis ale nie wyświetla reszty opisów... i jest błąd

Fatal error: Cannot redeclare zajawka() (previously declared in /srv/home/y81390yb/public_html/zbiory2/historia/szukaj.php:95) in /srv/home/y81390yb/public_html/zbiory2/historia/szukaj.php on line 95

w tej lini zaczyna się deklaracja funkcji zajawka...

gdzie jest błąd w funkcji zajawka??
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.