Skocz do zawartości
"Idzie nowe..." - o zmianach i nie tylko ×
Przeniesienie zakupów z IPS Marketplace / Moving bought items from IPS Marketplace ×

Tworzenie wpisu do bazy danych


Rekomendowane odpowiedzi

Hej ponownie, miałem problem z kodem który opisałem w innym temacie. Chciałbym stworzyć dodawanie ofert ale kompletnie nie wiem jak się za to zabrać

Mój szablon:

<h2 class="ipsType_sectionTitle ipsType_reset cForumTitle">Market / W trakcie budowy.</h2>
<hr class="ipsHr"> 
{{if \IPS\Request::i()->action == 'makeOffert' }}
	Tutaj będziesz mógł dodać ofertę.
{{else}}
<div class="ipsTabs saTabs ipsClearfix" id="ticketsTabs" data-ipstabbar="" data-ipstabbar-contentarea="#ticketsTabContent"> 
  <ul role="tablist" class="ipsList_reset" style="float: left">	
    <a class="ipsTabs_item saTabs_item ipsTabs_activeItem" id="cat_items" role="tab" aria-selected="true">
      <span class="saTabs_count" data-action="quickToggleCount"> <i class="fa fa-phone"></i></span>
      Przedmioty
    </a>
    <a class="ipsTabs_item saTabs_item" id="cat_cars" role="tab">
      <span class="saTabs_count" data-action="quickToggleCount"> <i class="fa fa-car"></i></span>
      Pojazdy
    </a>
    <a class="ipsTabs_item saTabs_item" id="cat_doors" role="tab">
      <span class="saTabs_count" data-action="quickToggleCount"><i class="fa fa-home"></i></span>
      Posiadłości
    </a>	
  </ul>
  <a href="index.php?/character/&tab=market&action=makeOffert" data-ipsdialog-title="Dodawanie oferty" style="float: right; padding-top: 10px; padding-right: 10px;">
    <span class="ipsBadge ipsBadge_large ipsBadge_intermediary">
      <i class="fa fa-plus"></i> Dodaj oferte
    </span>
  </a>
</div>
<section id="ticketsTabContent">
  <div id="ipsTabs_ticketsTabs_cat_items_panel" class="ipsTabs_panel" aria-labelledby="cat_items" aria-hidden="false" style="display: block;" animating="false">		
    <ol class="ipsBox ipsDataList ipsDataList_large ipsDataList_zebra ipsAreaBackground_reset cForumList" data-role="market" style="border-top: 0;">
      
        <div style="padding: 25px;">	
           {{foreach $results as $row}}
          <li class="cForumRow ipsDataItem ipsDataItem_responsivePhoto  ipsClearfix">
            <div class="ipsDataItem_main" style="vertical-align: middle">
                <h4 class="ipsDataItem_title ipsType_large ipsType_break">
                  {{if $row['auction_priority'] == 1}}
                  <span class="ipsBadge ipsBadge_large ipsBadge_intermediary">Sponsorowane</span>  
                  {{endif}}
                  <a href="index.php?/character/&tab=market&viewMarketItem={$row['auction_id']}">{$row['auction_uid']}</a>
                </h4>
            </div>
           <ul class="ipsDataItem_lastPoster ipsDataItem_withPhoto" style="text-align: center">
              <li class="ipsType_success">
                 <span class="ipsBadge ipsBadge_medium ipsBadge_positive">
                <strong><i class="fa fa-handshake-o"></i> &nbsp; <i class="fa fa-usd" style="font-size: 95%"></i>{$row['auction_buynow']}</strong>
                </span>
              </li>
              {{if $row['auction_startprice'] == 0}}
               <li class="ipsType_light">
              	 -
              </li>
              {{else}}
              <li class="ipsType_light">
               <span class="ipsBadge ipsBadge_medium ipsBadge_neutral">
                <strong><i class="fa fa-gavel"></i> &nbsp; <i class="fa fa-usd" style="font-size: 95%"></i>{$row['auction_startprice']}</strong>
                </span>
              </li>
               {{endif}}
            </ul>
            <ul class="ipsDataItem_lastPoster ipsDataItem_withPhoto" style="text-align: center">
              <li>
                <strong>{$row['auction_owner']}</strong>
              </li>
              <li>
                {datetime="$row['auction_date']"}
              </li>
            </ul>
          </li>
        {{endforeach}}
        </div>
      
    </ol>
  </div>
  <div id="ipsTabs_ticketsTabs_cat_cars_panel" class="ipsTabs_panel" aria-labelledby="cat_cars" aria-hidden="false" style="display: block;" animating="false">
    <ol class="ipsBox ipsDataList ipsDataList_large ipsDataList_zebra ipsAreaBackground_reset cForumList" data-role="market" style="border-top: 0;">
      
        <div style="padding: 25px;">
{{if !$results}}

          	Brak wystawionych ofert
          {{else}}
          {{foreach $results as $row}}
          <li class="cForumRow ipsDataItem ipsDataItem_responsivePhoto  ipsClearfix">
            <div class="ipsDataItem_main" style="vertical-align: middle">
                <h4 class="ipsDataItem_title ipsType_large ipsType_break">
                  {{if $row['auction_priority'] == 1}}
                  <span class="ipsBadge ipsBadge_large ipsBadge_intermediary">Sponsorowane</span>  
                  {{endif}}
                  <a href="index.php?/character/&tab=market&viewMarket={$row['auction_id']}">{$row['name']}</a>
                </h4>
            </div>
           <ul class="ipsDataItem_lastPoster ipsDataItem_withPhoto" style="text-align: center">
              <li class="ipsType_success">
                 <span class="ipsBadge ipsBadge_medium ipsBadge_positive">
                   <strong><i class="fa fa-handshake-o"></i> &nbsp; <i class="fa fa-usd" style="font-size: 95%"></i>{$row['auction_buynow']}</strong>
                </span>
              </li>
              {{if $row['auction_startprice'] == 0}}
               <li class="ipsType_light">
              	 -
              </li>
              {{else}}
              <li class="ipsType_light">
               <span class="ipsBadge ipsBadge_medium ipsBadge_neutral">
                <strong><i class="fa fa-gavel"></i> &nbsp; <i class="fa fa-usd" style="font-size: 95%"></i>{$row['auction_startprice']}</strong>
                </span>
              </li>
               {{endif}}
            </ul>
            <ul class="ipsDataItem_lastPoster ipsDataItem_withPhoto" style="text-align: center">
              <li>
                <strong>{$row['auction_owner']}</strong>
              </li>
              <li>
                {datetime="$row['auction_date']"}
              </li>
            </ul>
          </li>
        {{endforeach}}
           {{endif}}
        </div>
      
    </ol>
  </div>
  <div id="ipsTabs_ticketsTabs_cat_doors_panel" class="ipsTabs_panel" aria-labelledby="cat_doors" aria-hidden="false" style="display: block;" animating="false">
    <ol class="ipsBox ipsDataList ipsDataList_large ipsDataList_zebra ipsAreaBackground_reset cForumList" data-role="market" style="border-top: 0;">
      
         <div style="padding: 25px;">
          {{if !$results}}
          	Brak wystawionych ofert
          {{else}}
          {{foreach $results as $row}}
          <li class="cForumRow ipsDataItem ipsDataItem_responsivePhoto  ipsClearfix">
            <div class="ipsDataItem_main" style="vertical-align: middle">
                <h4 class="ipsDataItem_title ipsType_large ipsType_break">
                  {{if $row['auction_priority'] == 1}}
                  <span class="ipsBadge ipsBadge_large ipsBadge_intermediary">Sponsorowane</span>  
                  {{endif}}
                  <a href="index.php?/character/&tab=market&viewMarket={$row['auction_id']}">{$row['nazwa']}</a>
                </h4>
            </div>
            <ul class="ipsDataItem_lastPoster ipsDataItem_withPhoto" style="text-align: center">
              <li class="ipsType_success">
                 <span class="ipsBadge ipsBadge_medium ipsBadge_positive">
                <strong><i class="fa fa-handshake-o"></i> &nbsp; <i class="fa fa-usd" style="font-size: 95%"></i>{$row['auction_buynow']}</strong>
                </span>
              </li>
              {{if $row['auction_startprice'] == 0}}
               <li class="ipsType_light">
              	 -
              </li>
              {{else}}
              <li class="ipsType_light">
               <span class="ipsBadge ipsBadge_medium ipsBadge_neutral">
                <strong><i class="fa fa-gavel"></i> &nbsp; <i class="fa fa-usd" style="font-size: 95%"></i>{$row['auction_startprice']}</strong>
                </span>
              </li>
               {{endif}}
            </ul>
            <ul class="ipsDataItem_lastPoster ipsDataItem_withPhoto" style="text-align: center">
              <li>
                <strong>{$row['auction_owner']}</strong>
              </li>
              <li>
                {datetime="$row['auction_date']"}
              </li>
            </ul>
          </li>
        {{endforeach}}
           {{endif}}
        </div>
      
    </ol>
  </div>
</section>

{{endif}}

 

Mój kod PHP:

protected function _market()
{
    $results = [];
    foreach( \IPS\Db::i()->select( '*', 'auctions' ) as $row ) {
        $results[] = $row;
    }
    
    return \IPS\Theme::i()->getTemplate('character')->tabMarket($results);
}

 

Odnośnik do komentarza
Udostępnij na innych stronach

  • Manager

Sekundę o co tu chodzi? Tworzysz takie kody, a wstawiania nie zrobisz? Wyjaśnij, bo Ty tu nie szukasz porady, a wyręczenia.

Dałeś szablon i kod z poprzedniego tematu - fajnie, ale nijak się on ma do tworzenia.

 

Dodawanie wpisu do bazy - jaki to typ jaki chcesz dodać? Cokolwiek w tym temacie masz wiedzę? Ogólne dodawanie do bazy podejrzysz w system/Db/Db.php:

	/**
	 * Run INSERT statement and return insert ID
	 *
	 * @see		<a href='http://dev.mysql.com/doc/refman/5.1/en/insert.html'>INSERT Syntax</a>
	 * @param	string					$table			Table name
	 * @param	array|\IPS\Db\Select	$set			Values to insert or array of values to set for multiple rows (NB, if providing multiple rows, they MUST all contain the same columns) or a statement to do INSERT INTO SELECT FROM
	 * @param	bool					$odkUpdate		Append an ON DUPLICATE KEY UPDATE clause to the query.  Similar to the replace() method but updates if a record is found, instead of delete and reinsert.
	 * @param	bool					$ignoreErrors	Ignore errors?
	 * @see		replace
	 * @return	int
	 * @throws	\IPS\Db\Exception
	 */
	public function insert( $table, $set, $odkUpdate=FALSE, $ignoreErrors=FALSE )
	{

 

intermedia - profesjonalne rozwiązania Invision Power Board

---

Chcesz uzyskać szybko i sprawnie pomoc? Uzupełnij wersję i adres w profilu.

Odnośnik do komentarza
Udostępnij na innych stronach

Zrobiłem coś takiego

  public function makeOffert()
    {
        if (isset(\IPS\Request::i()->AddOffer)) {
            $offer = \IPS\Request::i()->AddOffer;
            $member = \IPS\Member::loggedIn()->member_id;
            $date = time();
            \IPS\Db::i()->insert('auctions', [
    'auction_id' => $auctionId,
    'auction_uid' => $auctionUid,
    'auction_priority' => $auctionPriority,
    'auction_buynow' => $auctionBuyNow,
    'auction_startprice' => $auctionStartPrice,
    'auction_owner' => $member,
    'auction_date' => $auctionDate,
    'auction_type' => $auctionType
]);


            // Redirect to main
        \IPS\Output::i()->redirect(\IPS\Http\Url::internal("app=game&module=character", 'front'), \IPS\Member::loggedIn()->language()->addToStack('Pomyślnie dodano zmianę.'));
    }
}

I tutaj HTML:

{{if \IPS\Request::i()->action == 'makeOffert' }}
<div>
    <h2>Dodaj ofertę</h2>
    <form action="https://v-inside.pl/forum/index.php?app=game&module=character&controller=makeOffert" method="POST">
        <input type="text" name="offer_title" placeholder="Tytuł oferty" required>
        <textarea name="offer_description" placeholder="Opis oferty" required></textarea>
        <input type="submit" value="Dodaj ofertę">
    </form>
</div>
{{else}}[DALSZA CZĘŚĆ KODU]

 

Pojawia mi się Brak strony, nie wiem co robię źle ponieważ po naciśnięciu DODAJ pokazuje mi się 

Ta strona nie istnieje.

Odnośnik do komentarza
Udostępnij na innych stronach

  • Manager
  • Dziękuję 1

intermedia - profesjonalne rozwiązania Invision Power Board

---

Chcesz uzyskać szybko i sprawnie pomoc? Uzupełnij wersję i adres w profilu.

Odnośnik do komentarza
Udostępnij na innych stronach

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Posiadasz już konto? Zaloguj się poniżej.

Zaloguj się
  • 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ę.