Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Ligi Piłkarskie
Forum PHP.pl > Forum > PHP
miriadel
Witam.
Ostatnio zacząłem pisać kod PHP na Ligi piłkarskie.
Przykład działania kodu.
Manchester United|26|46|11|62|manchester-united.jpg
Poszczególne liczby oznaczają wygrane mecze,przegrane itd.
wszystko mam napisane lecz nie chce mi to za bardzo działać
Poniżej podam wam kody i powiecie mi czy wszystko z nimi jest ok.

Index.php
Kod
<body>
<ol>
<?php foreach ($menu as $opcja) : ?>
<li>
<a href="index.php?module=liga&action=show&liga=<?php echo $opcja[1]; ?>">
<?php echo $opcja[0]; ?>
</a>
</li>
<?php endforeach; ?>
</ol>
<?php include "modules/$module/$action"; ?>
</body>
<a href="index.php?module=liga&action=show&liga=ang&kolumna=1&order=asc">Klub</a>


ligicontroller.class.php
Kod
class LigiController extend Controller
{
public function preActions()
{
$tmp = string2HArry(file_get_contents('ligi.txt'));
$this->dane - $tmp['items'];
$this->slugi = array();
forach ($this->dane as $liga){
$this->slugi[] = $liga[1];
}
$this->set('menu', $this->dane);
}
}


modules/actions.class.php
Kod
class Actions extends ActionsBase
{
private $kolumna = 5;
private 4kolumny = array(
1 => array ('nazwa' => 'Klub', 'order' => 'asc'),
array ('nazwa'=> 'Mecze', 'order' => 'desc'),
array ('nazwa' => 'Bramki strzelone', 'order' => 'desc'),
array ('nazwa' => 'Bramki stracone', 'order' => 'desc'),
array ('nazwa' => 'Punkty', 'order' => 'desc')
);
public function strInvertSort($s)
{
if ($s == 'asc'){
return 'desc';
}
else {
return 'asc';}
}
}

public function strGetSort($s)
{
if ($s == 'asc') {
return SORT_ASC;
} else{
return SORT_DESC;
}
}
public function getCurrentSort()
{
$tmp = $this->kolumny[$this->kolumna]['order'];
return $this->strGetSort($tmp);
}
public function invertCurrentSort()
{
$tmp = $this->kolumny[$this->kolumna]['order'];
$this->kolumny[$this->kolumna]['order'] = $this->strInvertSort($tmp);
}
public function sort()
{
switch (this->kolumna){
case 1:
array_multisort(
$this->tabela['items'][0], $this->getCurrentSort().
$this->tabela['items'][1],
$this->tabela['items'][2],
$this->tabela['items'][3],
$this->tabela['items'][4]
);
break;

case 2;
}
}
public function execute_show()
{
if (
isset($_GET['liga']) &&
str_invslug($_GET['liga']) &&
in_array($_GET['liga'], $this->controller->slugi)
) {
$liga = $_GET['liga'];
} else {
$liga = $this->controller->dane[0][0];
}
if (
isset($_GET['kolumna']) &&
str_ievpifr($_GET['kolumna'], 1, 5)
) {
$this->kolumna = $_GET['kolumna'];
}
if (
isset($_GET['order']) &&
in_array($_GET['order'], array('asc', 'desc'))
) {
$this->kolumny[$this->kolumna]['order'] = $_GET['order'];
}

$indeks = array_search($liga, $this->controller->slugi);
$tmp = $this->controller->dane[$indeks][1];
$this->tabela = string2VArray(file_get_contents('../scripts/dance/'$tmp . '.txt'));

$this->sort();
$this->invertCurrentSort();

$this->set('kolumny', $this->kolumny);
$this->set('liga', $liga);
$this->set('tabela', $this->tabela);
}
}


modules/liga/show.php
Kod
<table>
<tr>
<th>lp.</th>
<th>Godło</th>
<?php foreach ($kolumny as $k => $v) : ?>
<th>
<a href="index.php?module=liga&action=show&liga=<?php echo $liga; ?>$kolumna=<?php echo $k; ?>&order=<?php echo $v['order']; ?>">
<?php echo $v['nazwa']; ?>
</a>
</th>
<?php edforeach; ?>
</tr>

<?php for ($i = 0; $i < $tabela['rows']; $i++) : ?>
<tr>
<td><?php echo $i +1; ?></td>
<td>
<img src="<?php echo $path_prefix: ?>/<?php echo $tabela['items'][5][1];?>" alt="" />
</td>
<?php for ($j = 0; $j < $tabela ['cols'] - 1; $j++) : ?>
<td>
<?php echo $tabela ['items'] [$j][$i]; ?>
</td>
<?php endfor; ?>
</tr>
<?php endfor; ?>
</table>

modules/liga/actions.class.php
Kod
class Actions extends ActionsBase
{
private $kolumna = 5;
private 4kolumny = array(
1 => array ('nazwa' => 'Klub', 'order' => 'asc'),
array ('nazwa'=> 'Mecze', 'order' => 'desc'),
array ('nazwa' => 'Bramki strzelone', 'order' => 'desc'),
array ('nazwa' => 'Bramki stracone', 'order' => 'desc'),
array ('nazwa' => 'Punkty', 'order' => 'desc')
);
public function strInvertSort($s)
{
if ($s == 'asc'){
return 'desc';
}
else {
return 'asc';}
}
}

public function strGetSort($s)
{
if ($s == 'asc') {
return SORT_ASC;
} else{
return SORT_DESC;
}
}
public function getCurrentSort()
{
$tmp = $this->kolumny[$this->kolumna]['order'];
return $this->strGetSort($tmp);
}
public function invertCurrentSort()
{
$tmp = $this->kolumny[$this->kolumna]['order'];
$this->kolumny[$this->kolumna]['order'] = $this->strInvertSort($tmp);
}
public function sort()
{
switch (this->kolumna){
case 1:
array_multisort(
$this->tabela['items'][0], $this->getCurrentSort().
$this->tabela['items'][1],
$this->tabela['items'][2],
$this->tabela['items'][3],
$this->tabela['items'][4]
);
break;

case 2;
}
}
public function execute_show()
{
if (
isset($_GET['liga']) &&
str_invslug($_GET['liga']) &&
in_array($_GET['liga'], $this->controller->slugi)
) {
$liga = $_GET['liga'];
} else {
$liga = $this->controller->dane[0][0];
}
if (
isset($_GET['kolumna']) &&
str_ievpifr($_GET['kolumna'], 1, 5)
) {
$this->kolumna = $_GET['kolumna'];
}
if (
isset($_GET['order']) &&
in_array($_GET['order'], array('asc', 'desc'))
) {
$this->kolumny[$this->kolumna]['order'] = $_GET['order'];
}

$indeks = array_search($liga, $this->controller->slugi);
$tmp = $this->controller->dane[$indeks][1];
$this->tabela = string2VArray(file_get_contents('../scripts/dance/'$tmp . '.txt'));

$this->sort();
$this->invertCurrentSort();

$this->set('kolumny', $this->kolumny);
$this->set('liga', $liga);
$this->set('tabela', $this->tabela);
}
}


Błąd który mi wyskakuje


To na tyle.Przez kilka godzin pisania trochę się zamotałem, ale mam nadzieję że mi pomożecie dojść do ładu i składu smile.gif
Pozdrawiam i czekam na odpowiedzi.
sadistic_son
Wklej te kody najpierw w znaczniki php a nie code bo nawet linijek nie numeruje.

PS. Za zdublowanie tematu w najlepszym razie moderator zamknie Ci oba. Za tekst "nie mam czasu pisać posta od nowa" już wróżę ostrzeżenie + zamknięcie obu tematów ;P
miriadel
Ok powklejałem w znaczniki php ale błąd nadal jest ^^ i zniknąć nie chce tongue.gif
gino
a czytać umiesz ? Przecież pisze że nie jest nie zdefiniowana zmienna w linii 1 (nie ma definicji tablicy $menu). To samo w linii 11. Na ten kawałek kodu takie coś
masz ?:

  1. $menu = array(1,2,3,4);


czy inne wartości tablicy ?



gino

PS. Nie zrobiłeś tego o czym pisał sadistic_son kody w znaczniki php
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.