Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Proste pytanie o php
artursztuka
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 11.04.2012

Ostrzeżenie: (0%)
-----




Prosze o pomoc

Mam baze postgre 9x i nie działa poniższe zapytanie o typ oferty "offerHasOfferType". Przy postgre 8x działało.

Jeśli na stałe tutaj dodam tabele offerHasOfferType to działa, ale jeżeli użytkownik nie wybierz typu oferty to nie pokazuje sie nic na stronie.

from
offers, cities, countries, "cantonmentTypes", "serviceHasOffers" "+offerHasOfferType"


Jak zrobić warunek żeby nie uwzgledniac w zapytaniu sql listy tabel - tabeli offerHasOfferType w momencie jak nie jest podany w wyszukiwarce typ oferty

czyli jezeli jest typ oferty to lista tabel z których ma pobrac dane:
offers, cities, countries, "cantonmentTypes", "serviceHasOffers", "offerHasOfferType"

a jak nie ma to:
offers, cities, countries, "cantonmentTypes", "serviceHasOffers"


================


if (is_numeric($link['typ']))
{
$tabela = ', "offerHasOfferType" ';
$dodaj = $dodaj.' and "offerHasOfferType"."offerId"=offers."offerId" and "offerHasOfferType"."offerTypeId"='.$link['typ'].' ';
}



$sql = 'select offers."offerId",offers.name,offers."galleryId",offers.description,offers."pictureId", cities.name as miasto, countries.name as kraj, "cantonmentTypes".name as nocleg, (select price from termins where termins."offerId"=offers."offerId" and termins."currencyId"=1 order by termins.price asc limit 1) as cena, (select "dateFrom" from termins where termins."offerId"=offers."offerId" and termins."dateFrom">\''.$dzis.'\' order by termins."dateFrom" asc limit 1) as terminod
from
offers, cities, countries, "cantonmentTypes", "serviceHasOffers"
where
offers."isActive"=true and
cities."cityId"=offers."cityId" and
countries ."countryId"=offers."countryId" and
"cantonmentTypes"."cantonmentTypeId"=offers."cantonmentTypeId" '.$dodaj.' and '.$warunek_dod.'
order by terminod,cena asc, offers."offerId" desc limit 15 offset '.$granica.' ';

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
!*!
post
Post #2





Grupa: Zarejestrowani
Postów: 4 298
Pomógł: 447
Dołączył: 16.11.2006

Ostrzeżenie: (0%)
-----


Wrzuć to w odpowiednie tagi.


--------------------
Nie udzielam pomocy poprzez PW i nie mam GG.
Niektóre języki programowania, na przykład C# są znane z niezwykłej przenośności (kompatybilność ze wszystkimi wersjami Visty jest wiele warta).
Go to the top of the page
+Quote Post
--artursztuka--
post
Post #3





Goście







A możesz coś więcej napisać?, bo nie mam zbyt dużej wiedzy na ten temat.
Go to the top of the page
+Quote Post
Evinek
post
Post #4





Grupa: Zarejestrowani
Postów: 280
Pomógł: 46
Dołączył: 23.03.2010

Ostrzeżenie: (0%)
-----


Czyli opraw ładnie temat.
Kod PHP w znaczniki [php][/php] itp.
Go to the top of the page
+Quote Post
artursztuka
post
Post #5





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 11.04.2012

Ostrzeżenie: (0%)
-----



Dzięki, już wrzucam

  1. <?
  2. $_GET['cachewalker'] = NULL;
  3. include ("funkcje/cache_start.php");
  4. include ("funkcje/funkcje.php");
  5.  
  6. foreach ($_GET as $klucz => $wartosc)
  7. {
  8. if (!checkField($_GET[$klucz])) {header ("Location: index.php"); exit;}
  9. }
  10. #przygotowanie zmiennych
  11. foreach ($_GET as $klucz => $wartosc)
  12. {
  13. $link[$klucz] = przygotoj($_GET[$klucz]);
  14. }
  15.  
  16. if ($link['kraj'])
  17. {
  18. if (is_numeric($link['kraj'])) $dodaj = $dodaj.' and offers."countryId"='.$link['kraj'].' ';
  19. }
  20. if ($link['miejscowosc'])
  21. {
  22. if (is_numeric($link['miejscowosc'])) $dodaj = $dodaj.' and offers."cityId"='.$link['miejscowosc'].' ';
  23. }
  24. if ($link['obiekt'])
  25. {
  26. if (is_numeric($link['obiekt'])) $dodaj = $dodaj.' and offers."cantonmentTypeId"='.$link['obiekt'].' ';
  27. }
  28. if ($link['dojazd'])
  29. {
  30. if (is_numeric($link['dojazd'])) $dodaj = $dodaj.' and offers."journeyTypeId"='.$link['dojazd'].' ';
  31. }
  32. if ($link['typ'])
  33. {
  34. if (is_numeric($link['typ']))
  35. {
  36. $tabela = ', "offerHasOfferType" ';
  37. $dodaj = $dodaj.' and "offerHasOfferType"."offerId"=offers."offerId" and "offerHasOfferType"."offerTypeId"='.$link['typ'].' ';
  38. }
  39. }
  40.  
  41. $naglowek = "Tekst przykładowy tytułu";
  42. include ("layout.php");
  43. ?>
  44. <center>
  45. <div class="wysz">
  46. <form action="szukaj.php" method="get" style="margin:0px;padding:0px;">
  47. <div><b>Wyszukiwarka</b></div>
  48. <div style="margin:8px;">
  49. <?
  50. $warunek_dod = ' "serviceHasOffers"."serviceId"=40 and "serviceHasOffers"."offerId"=offers."offerId" ';
  51. ?>
  52.  
  53. <select name="kraj" onchange="getMiasto(this)">
  54. <option value="">- kraj -</option>
  55. <?
  56. $sql = 'select distinct(countries.name) as kraj, countries."countryId"
  57. from
  58. offers, countries, "serviceHasOffers"
  59. where
  60. offers."isActive"=true and
  61. countries."countryId"=offers."countryId" and '.$warunek_dod.' order by countries.name asc ';
  62.  
  63. $wynik = pg_query($sql);
  64. $ilosc = pg_num_rows($wynik);
  65. for ($i=0;$i<$ilosc;$i++)
  66. {
  67. $re = pg_fetch_array($wynik);
  68. echo "<option value='".$re['countryId']."'>".$re['kraj']."</option>";
  69. }
  70. ?>
  71. </select> &nbsp; &nbsp; &nbsp;
  72. <select name="miejscowosc" id="miejscowosc" style="width:200px;"><option value="">wybierz kraj</option></select> &nbsp; &nbsp; &nbsp;
  73. <select name="obiekt">
  74. <option value="">- rodzaj obiektu -</option>
  75. <?
  76. $sql = 'select distinct("cantonmentTypes"."cantonmentTypeId"), "cantonmentTypes".name as nocleg
  77. from
  78. offers, "cantonmentTypes", "serviceHasOffers"
  79. where
  80. offers."isActive"=true and
  81. "cantonmentTypes"."cantonmentTypeId"=offers."cantonmentTypeId" and '.$warunek_dod.' order by "cantonmentTypes".name asc';
  82.  
  83. $wynik = pg_query($sql);
  84. $ilosc = pg_num_rows($wynik);
  85. for ($i=0;$i<$ilosc;$i++)
  86. {
  87. $re = pg_fetch_array($wynik);
  88. echo "<option value='".$re['cantonmentTypeId']."'>".$re['nocleg']."</option>";
  89. }
  90. ?>
  91. </select><br /><br />
  92. <select name="dojazd">
  93. <option value="">- dojazd -</option>
  94. <option value='2'>Bus</option>
  95. <option value='3'>Dojazd własny</option>
  96. <option value='4'>Pociąg</option>
  97. <option value='1'>Lot</option>
  98. </select> &nbsp; &nbsp; &nbsp;
  99. <select name="typ">
  100. <option value="">- typ oferty -</option>
  101. <?
  102. $sql = 'select distinct("offerTypes"."offerTypeId"), "offerTypes".name as typ
  103. from
  104. offers, "offerTypes", "serviceHasOffers"
  105. where
  106. offers."isActive"=true and '.$warunek_dod.' order by "offerTypes".name asc';
  107.  
  108. $wynik = pg_query($sql);
  109. $ilosc = pg_num_rows($wynik);
  110. for ($i=0;$i<$ilosc;$i++)
  111. {
  112. $re = pg_fetch_array($wynik);
  113. echo "<option value='".$re['offerTypeId']."'>".$re['typ']."</option>";
  114. }
  115. ?>
  116. </select>
  117. </div>
  118. <div style="margin-top:12px;text-align:right;">
  119. <input type="submit" name="go" value="szukaj">
  120. </div>
  121. </form>
  122. </div>
  123. <?
  124. if ($page) $granica = $page * 30;
  125. if (!$page) {$granica=0;$page=0;}
  126.  
  127. $sql = 'select count(offers."offerId")
  128. from
  129. offers, cities, countries, "cantonmentTypes"
  130. where
  131. offers."isActive"=true and
  132. cities."cityId"=offers."cityId" and
  133. countries ."countryId"=offers."countryId" and
  134. "cantonmentTypes"."cantonmentTypeId"=offers."cantonmentTypeId" '.$dodaj.' and '.$warunek_dod.' ';
  135. $wynik = pg_query($sql);
  136. $ilosc_calk = pg_fetch_array($wynik);
  137.  
  138. $strony = $ilosc_calk[0]/30;
  139. $strony = ceil($strony);
  140. $dzis = date("Y-m-d");
  141.  
  142.  
  143. $sql = 'select offers."offerId",offers.name,offers."galleryId",offers.description,offers."pictureId", cities.name as miasto, countries.name as kraj, "cantonmentTypes".name as nocleg, (select price from termins where termins."offerId"=offers."offerId" and termins."currencyId"=1 order by termins.price asc limit 1) as cena, (select "dateFrom" from termins where termins."offerId"=offers."offerId" and termins."dateFrom">\''.$dzis.'\' order by termins."dateFrom" asc limit 1) as terminod
  144. from
  145. offers, cities, countries, "cantonmentTypes", "serviceHasOffers"
  146. where
  147. offers."isActive"=true and
  148. cities."cityId"=offers."cityId" and
  149. countries ."countryId"=offers."countryId" and
  150. "cantonmentTypes"."cantonmentTypeId"=offers."cantonmentTypeId" '.$dodaj.' and '.$warunek_dod.'
  151. order by terminod,cena asc, offers."offerId" desc limit 15 offset '.$granica.' ';
  152.  
  153.  
  154. $wynik = pg_query($sql);
  155. $ilosc = pg_num_rows($wynik);
  156.  
  157. if ($ilosc==0) echo "Nie znaleziono ofert spełniających Twoje kryteria.";
  158.  
  159. for ($i=0;$i<$ilosc;$i++)
  160. {
  161. $re = pg_fetch_array($wynik);
  162.  
  163. $temp = $i/2;
  164. if (is_int($temp)) $back = "#ffffff";
  165. else $back = "#f3f9fe";
  166.  
  167. $url = tworz_url($re['name'], $re['offerId']);
  168. if (!$re['terminod'])
  169. {
  170. $sql = 'select "dateFrom" from termins where "offerId"='.$re['offerId'].' and "isActive"=true order by "dateFrom" desc limit 1';
  171. $dat = pg_query($sql);
  172. $datt = pg_fetch_array($dat);
  173. if (!$datt['dateFrom']) $re['terminod'] = "-";
  174. else $re['terminod'] = $datt['dateFrom'];
  175. }
  176.  
  177.  
  178.  
  179. echo "<div class='oferta1'>
  180. <div class='oferta2'>";
  181. echo "<table style='width:100%;' cellspacing='2' cellpadding='2'>";
  182. echo "<tr>
  183. <td width='110' valign='top'><a href='".$url.".html' class='none'>";
  184. if (is_file("../img/gallery/".$re['galleryId']."/small".$re['pictureId'].".jpg")) echo "<img src='/gallery/".$re['galleryId']."/small".$re['pictureId'].".jpg' alt='".$re['miasto']."' border='0' width='120' height='90'>";
  185. else echo "<img src='gfx/brak.png' alt=' ' border='0' />";
  186. echo "</a></td>
  187. <td valign='top'>
  188. <div style='line-height:19px;'>
  189. <a href='".$url.".html' class='none'><b style='color:#b0d224;font-size:13px;'>".$re['name']."</b></a><br>
  190. <div class='oferta3'>
  191. Lokalizacja: <b>".$re['kraj']."</b> -> <b>".$re['miasto']."</b><br>
  192. Obiekt: <b>".$re['nocleg']."</b>,<br>";
  193. if ($re['cena']>=1) echo "Cena od: <b>".$re['cena']."</b> PLN, <br>";
  194. else
  195. {
  196. $sql = 'select price from termins where "offerId"='.$re['offerId'].' and "currencyId"=3 order by price asc limit 1';
  197. $odp = pg_query($sql);
  198. $cena_eur = pg_fetch_array($odp);
  199. if ($cena_eur['price']) echo "Cena od: <b>".$cena_eur['price']."</b> EUR, <br>";
  200. else echo "Cena od: <b>-</b> <br>";
  201. }
  202. echo "Termin od: <b>".$re['terminod']."</b>";
  203. echo "</div>
  204. <div style='text-align:right;'><a href='".$url.".html' style='color:#fe6e00;text-decoration:none;'>[zobacz]</a></div>
  205. </td>
  206. </tr>
  207. </table>";
  208. echo "</div>";
  209. $opis = str_replace("<br />", " ", $re['description']);
  210. $opis = str_replace("<br>", " ", $opis);
  211. $opis = strip_tags($opis);
  212. $opis = substr($opis, 0, 370);
  213. $spacja = explode(" ", $opis);
  214. $max = sizeof($spacja);
  215. $opis = str_replace($spacja[$max-1], "", $opis);
  216. echo "<div class='ofertaopis'>
  217. ".$opis."...
  218. </div><br style='clear:both;' /></div>";
  219. }
  220.  
  221.  
  222.  
  223. if ($strony>1)
  224. {
  225. echo "|";
  226.  
  227. $pp = 0;
  228. $start = 0;
  229. $pp = $page/23;
  230. $pp = floor($pp);
  231. $start = $page - 11;
  232. if ($start<0) $start = 0;
  233. if ($page<=9) $plus = 11 - $page;
  234. else $plus = 0;
  235.  
  236. $temp = $page + 11 + $plus;
  237. if ($temp>$strony) $end = $strony;
  238. else $end = $temp;
  239.  
  240. for ($i=$start;$i<$end;$i++)
  241. {
  242. $j = $i+1;
  243. if ($page==$i) echo " <b>[".$j."]</b> |";
  244. else echo " <a href='szukaj.php?kraj=".$link['kraj']."&miejscowosc=".$link['miejscowosc']."&obiekt=".$link['obiekt']."&dojazd=".$link['dojazd']."&typ=".$link['typ']."&go=szukaj&page=".$i."' class='pages'>".$j."</a> |";
  245. }
  246. }
  247. ?>
  248. </center>
  249. <?
  250. include ("layout_dol.php");
  251. include ("funkcje/cache_end.php");
  252. ?>
Go to the top of the page
+Quote Post
!*!
post
Post #6





Grupa: Zarejestrowani
Postów: 4 298
Pomógł: 447
Dołączył: 16.11.2006

Ostrzeżenie: (0%)
-----


Zakładam że zapytanie SQL masz źle i się gubisz. Spróbuj je przepisać https://pl.wikibooks.org/wiki/PHP/Zarządzanie_rekordami pisząc to co trzeba z dużej litery

  1. $sql="SELECT " //koniecznie z cudzysłowem


Sprawdź też wartości domyślne, wstaw dane na czysto.

Ten post edytował !*! 31.07.2012, 16:49:40


--------------------
Nie udzielam pomocy poprzez PW i nie mam GG.
Niektóre języki programowania, na przykład C# są znane z niezwykłej przenośności (kompatybilność ze wszystkimi wersjami Visty jest wiele warta).
Go to the top of the page
+Quote Post
artursztuka
post
Post #7





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 11.04.2012

Ostrzeżenie: (0%)
-----



Zapytanie działa.

jak dodam w lini 145 w pliku: tabele "offerHasOfferType"
czyli:
offers, cities, countries, "cantonmentTypes", "serviceHasOffers", "offerHasOfferType"

to zapytanie: szukaj.php?kraj=24&miejscowosc=&obiekt=&dojazd=&typ=50&go=szukaj&cachewalker=1 o typ oferty działa

ale zapytania bez podania typu oferty nie, ciągle mieli i nic nie wyświetla.
/szukaj.php?kraj=24&miejscowosc=&obiekt=&dojazd=&typ=&go=szukaj&cachewalker=1

Jak to można poprawić? Żeby dla obu przypadków działało? czyli z podaniem typu oferty i bez podawania?

Czy ktoś może pomóc?

Czy naprawde nie znajdzie się nikt kto mógłby mi pomóc ?
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 19:04