Skocz do zawartości

Wyświetlanie wyników z bazy danych


Przejdź do rozwiązania Rozwiązane przez Orri,

Rekomendowane odpowiedzi

Opublikowano

Siema.
Edytuje panel gracza na IPB i mam aplikację dotyczącą aukcji - dodajemy aukcje z posiadanych przedmiotów, pojazdów itp

Mam pewien problem ponieważ na liście aukcji wyświetla mi się tylko jedna, ostatnio dodana aukcja a chciałbym aby wyświetlały się np. 10 na pierwszej i kolejnych stronach. W kodzie mam tak.

 

Część pliku: modules_public/panel/market.php

<?php

class public_game_panel_market extends ipsCommand
{
    protected $page = 0;
    protected $per_page = 20;
    
    # CLOSE            1
    # BUY            2
    # OFFER            3
    # END             4

    public function doExecute(ipsRegistry $registry)
    {
        if(!$this->memberData['member_id'])
        {
            $this->registry->output->showError('treść błędy');
        }
        
        
        switch($this->request['do'])
        {
            default:
            case 'list':
                $this->showMarketList();
                break;
            case 'view':
                $this->showMarketDetails();
                break;    
            case 'create':
                $this->showMarketCreate();
                break;    
        }
        
        $this->registry->output->setTitle('Rynek');
        $this->registry->output->addNavigation('Rynek', 'app=game&module=panel&section=market', 'false', 'game_market', 'public');
        $this->registry->output->sendOutput();
        
    }
    
    public function    showMarketList()
    {
        $this->page = isset($this->request['st']) ? intval($this->request['st']) : 0;
        # REDIRECT + CHAR
        if(isset($this->request['t_char']))
        {
            $this->registry->output->silentRedirect('index.php?app=game&module=panel&section=market&do=create&sort='.$this->request['sort'].'&char='.$this->request['t_char'].'');
        }
        
        # WYSWIETLANIE POSTACI
        $this->DB->query('SELECT `char_gid`, `char_uid`, `char_name` FROM end_character WHERE char_gid = '.(int)$this->memberData['member_id'].' AND !(char_block & 1)');
        $this->DB->execute();
        while($data = $this->DB->fetch())
        {
            $data['charname'] = str_replace('_', ' ', $data['char_name']);
            $characterList[] = $data;
        }
        
        #PAGINACJA
        require_once(IPSLib::getAppDir('game').'/sources/classes/gamelib.php');
    
        # WYSWIETLANIE LISTY AUKCJI WZGLÄ?DEM SORTOWANIA
        if($this->request['sort'] == 1)
        {
            #PAGINACJA
            $pages = $this->registry->output->generatePagination( array('totalItems'        => GameLib::countMarketItems(),
            'itemsPerPage'        => $this->per_page,
            'currentStartValue' => $this->page,
            'seoTitle'            => 'false',
            'seoTemplate'        => 'game_market',
            'baseUrl'            => 'app=game&module=panel&section=market&sort='.$this->request['sort'].''
            ));
        
            $this->DB->query('SELECT market_bid, market_uid, market_title, market_sub, market_type, market_extraid, market_price, market_end, char_name, member_id, members_display_name, members_seo_name FROM end_character, end_market, ipb_members WHERE char_uid = market_owner AND member_id = char_gid AND market_type = 1 AND market_status = 0 ORDER BY market_start DESC LIMIT '.$this->page.','.$this->per_page.'');
            $this->DB->execute();
        }
        if($this->request['sort'] == 2)
        {
            #PAGINACJA
            $pages = $this->registry->output->generatePagination( array(
            'totalItems'        => GameLib::countMarketVehicles(),
            'itemsPerPage'        => $this->per_page,
            'currentStartValue' => $this->page,
            'seoTitle'            => 'false',
            'seoTemplate'        => 'game_market',
            'baseUrl'            => 'app=game&module=panel&section=market&sort='.$this->request['sort'].'',
            ));
        
            $this->DB->query('SELECT market_bid, market_uid, market_title, market_sub, market_type, market_extraid, market_price, market_end, char_name, member_id, members_display_name, members_seo_name FROM end_character, end_market, ipb_members WHERE char_uid = market_owner AND member_id = char_gid AND market_type = 2 AND market_status = 0 ORDER BY market_uid DESC LIMIT '.$this->page.','.$this->per_page.'');
            $this->DB->execute();
        }
Opublikowano
# WYSWIETLANIE LISTY AUKCJI WZGLÄ?DEM SORTOWANIA
		if($this->request['sort'] == 1)
		{
			#PAGINACJA
			$pages = $this->registry->output->generatePagination( array('totalItems'		=> GameLib::countMarketItems(),
			'itemsPerPage'		=> $this->per_page,
			'currentStartValue' => $this->page,
			'seoTitle'			=> 'false',
			'seoTemplate'		=> 'game_market',
			'baseUrl'			=> 'app=game&module=panel&section=market&sort='.$this->request['sort'].''
			));
		
			$this->DB->query('SELECT market_bid, market_uid, market_title, market_sub, market_type, market_extraid, market_price, market_end, char_name, member_id, members_display_name, members_seo_name FROM end_characters, end_market, ipb_members WHERE char_uid = market_owner AND member_id = char_gid AND market_type = 1 AND market_status = 0 ORDER BY market_start DESC LIMIT '.$this->page.','.$this->per_page.'');
			$this->DB->execute();
		}

Szablon w stylu:

<if test="game:|:is_array($marketList) and count($marketList)">
					<table class="ipb_table">
						<tbody>
							<tr class="header">
								<th scope="col" width="31%">Nazwa</th>
								<th scope="col" width="20%">Sprzedający</th>
								<th width="18%" scope="col">Kończy się</th>
								<th scope="col">Cena</th>
								<th scope="col">Licytacja od</th>

							</tr>
							<foreach loop="game:$marketList as $data">
							<tr>
								<td><a href="index.php?app=game&module=panel&section=market&do=view&sort={$this->request['sort']}&uid={$data['market_uid']}">{$data['market_title']}</a><br /><span class="desc">{$data['mini_desc']}</span></td>
								<td class="col_f_post">
		
								<a href="{parse url="showuser={$data['member_id']}" template="showuser" seotitle="{$data['members_seo_name']}" base="public"}" class="ipsUserPhotoLink left">{IPSMember::buildProfilePhoto($data['member_id'], 'mini')}</a>

									<ul class="last_post ipsType_small">
										
											<li><span itemprop="name">{$data['char_name']}</span></li>
											<li>
												{IPSMember::makeProfileLink($data['members_display_name'],$data['member_id'])}
											</li>
										
									</ul>
								</td>
								<td>{$data['market_end']}</td>
								<td><a data-tooltip="Cena kup teraz"><span class="ipsTag" style="background: url(public/style_game/auction/kupteraz.png); text-shadow: none;">$ {$data['market_price']}</span></a></td>
								<td>
								<a data-tooltip="Licytacja"><span class="ipsTag" style="text-shadow: none;">
								<if test="game:|:$data['market_bid'] == 0">
									Tylko kup teraz
								<else />
									$ {$data['market_bid']}
								</if>
								</span></a>
								</td>
							</tr>
							</foreach>
							
						
						</tbody>
					</table>
					<else />
					<div class="ipsPad">
						Nie znaleziono żadnych aukcji.
					</div>
				</if>
Opublikowano

Aby wyświetlić więcej niż jeden wynik, musisz użyć pętli. Przypisz sobie wynik zapytania do jakiejś zmiennej, tą zmienną przekaż do szablonów a następnie:

<foreach loop="$variable as $key => $value">
    Tutaj wyświetlasz dane ze zmiennej $value albo $key
</foreach>
Opublikowano

No mam zmienną i nadal wyświetla jeden wynik.

while($data = $this->DB->fetch())
		{
			$data['char_name'] = str_replace('_', ' ', $data['char_name']);
			$data['market_end'] = $this->registry->getClass('class_localization')->getDate($data['market_end'], 'TINY', 0, 1);
			$data['mini_desc'] = IPSText::getTextClass('bbcode')->preDisplayParse($data['market_sub']);
			$marketList[] = $data;
		}
		
		

		
		
		$template = $this->registry->output->getTemplate('game')->gameShowMarket($marketList, $characterList, $pages);
		$this->registry->output->addContent($template);
	}
	
Opublikowano

Już wiem na czym polega problem.

Mam kod:

while($data = $this->DB->fetch())
		{
		
		$data['char_name'] = str_replace('_', ' ', $data['char_name']);
			$data['market_end'] = $this->registry->getClass('class_localization')->getDate($data['market_end'], 'TINY', 0, 1);
			$data['mini_desc'] = IPSText::getTextClass('bbcode')->preDisplayParse($data['market_sub']);
			$marketList[] = $data;

		}

Po usunięciu w nim
 

$data['char_name'] = str_replace('_', ' ', $data['char_name']);
			$data['market_end'] = $this->registry->getClass('class_localization')->getDate($data['market_end'], 'TINY', 0, 1);
			$data['mini_desc'] = IPSText::getTextClass('bbcode')->preDisplayParse($data['market_sub']);

Wyświetlają się aukcje lecz nie wyświetla się poprawnie opis aukcji oraz data zakończenia. Jak go przekształcić żeby działał?

Aktualnie wyglada to tak: http://prntscr.com/b483vy
Powinno tak: http://prntscr.com/b4841h

Opublikowano


$execute = $this->DB->execute();

}

while($data = $this->DB->fetch($execute))

{

$data['char_name'] = str_replace('_', ' ', $data['char_name']);

$data['market_end'] = $this->registry->getClass('class_localization')->getDate($data['market_end'], 'TINY', 0, 1);

$data['mini_desc'] = IPSText::getTextClass('bbcode')->preDisplayParse($data['market_sub']);

$marketList[] = $data;

}

  • Rozwiązanie
Opublikowano

Problem dotyczy tej linijki:
 

$data['mini_desc'] = IPSText::getTextClass('bbcode')->preDisplayParse($data['market_sub']);

Po usunięciu jej wyświetla się kilka wyników lecz nie ma opisu aukcji za które odpowiada powyższy kod. Jak go przekształcić?

Opublikowano

I jeszcze taki problem bo gdy wyświetlają mi się np. 5 wyników na stronie pierwszej, przechodzę na drugą i te same wyniki się wyświetlają.

Gość
Ten temat został zamknięty. Brak możliwości dodania odpowiedzi.
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...

Powiadomienie o plikach cookie

Umieściliśmy na Twoim urządzeniu pliki cookie, aby pomóc Ci usprawnić przeglądanie strony. Możesz dostosować ustawienia plików cookie, w przeciwnym wypadku zakładamy, że wyrażasz na to zgodę.