Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Problem ze formularzem i foreach, w skrypcie wyswietlającym produkty
Rahman
post
Post #1





Grupa: Zarejestrowani
Postów: 20
Pomógł: 0
Dołączył: 10.01.2008

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


Witam

Chciałem na swojej stronie zrobić panelik do wyświetlanie produktow z danej kategorii i/lub dyscypliny.
(robię taki mini sklepik sportowy) i mam mały dylemat ze skryptem.

Może najpierw forma w html:

  1. <form id="frmPokaz" action="pokaz.php" method="get" >
  2. <fieldset id="Pokaz"><legend>Wybierz swoja kategorie</legend>
  3. <table id="tblPokaz" >
  4. <tr>
  5. <td class="underline">Dyscyplina:</td>
  6. <td>
  7. <select name="dyscyplina" id="select">
  8. <option selected value="0"><strong>Wszystkie</strong></option>
  9. <option value="1">Koszykówka</option>
  10. <option value="2">Pilka Nozna</option>
  11. <option value="3">Sztuki walki</option>
  12. <option value="4">Lekkoatletyka</option>
  13. <option value="5">Siatkówka</option>
  14. <option value="6">Futbol Amerykański</option>
  15. <option value="7">Suplementy</option>
  16. </select> </td>
  17. <td class="underline">Kategoria:</td>
  18. <td>Odziez</td>
  19. <td><input name="kategoria" type="checkbox" class="checkbox" value="1"/></td>
  20. <td>Sprzet</td>
  21. <td><input name="kategoria" type="checkbox" class="checkbox" value="2"/></td>
  22. <td>Inne</td>
  23. <td><input name="kategoria" type="checkbox" class="checkbox" value="3"/></td>
  24. <td><input type="submit" class="submit" name="submit" id="pokaz" value="Pokaz"></td>
  25. </tr>


Skrypt:

  1. <?php
  2.  
  3. require_once ("include/polaczenie.php");
  4.  
  5.  
  6.  
  7. foreach ($_GET['kategoria'] as $pt) { 
  8.  $in1 .= "'" . $pt . "',"; 
  9.  
  10.  }
  11. $in1 = substr($in1,0,strlen($pt)-1); 
  12.  
  13. $sql = "SELECT ID_prod, ID_kat, ID_dyscyplina, nazwa_prod, cena, dostepny, opis_pro
    d
  14.  FROM produkty WHERE ID_kat IN (" . $in1 . ") AND ID_dyscyplina=" . $_GET['dyscyplina'] . ");";
  15. //echo $sql;
  16.  
  17. $query = mysql_query($sql);
  18.  
  19. $query = mysql_query($sql) or die(mysql_error());
  20. if(mysql_num_rows($query) > 0) 
  21. {
  22.  
  23. while ($row = mysql_fetch_assoc($query)) 
  24.  { 
  25.  echo '<p class="p_szukaj_php">',$row['nazwa_prod'],'</p> 
  26.  <table class="szukaj_php" cellpadding="5">
  27. <tr>
  28. <td rowspan="2" valign="top" align="left" cellpadding="5"><img src="images/img_male/',$row['ID_prod'],'.jpg"/> </td>
  29. <td colspan="4" valign="top" width="400" align="left">',$row['opis_prod'],'</td>
  30. </tr>
  31. <tr>
  32. <td align="left" valign="top">Cena: ',$row['cena'],'</td>
  33.  
  34.  
  35.  <td align="left" valign="top">Dostepny: ',$row['dostepny'],'</td>
  36.  <td align="left" valign="top"><a href="opinie.php"><input type="submit" class="submit" value="Opinie"></a></a></td>
  37.  <td align="left" valign="top" align="right"><a href=""><input type="submit" class="submit" value="Do Koszyka"></a></td>
  38.  </tr>
  39. </table>
  40. <p class="p_szukaj_php"></p>';
  41.  
  42. }
  43. }
  44. ?>


I pluje mi takim błędem:

[b]
  1. <?php
  2. Warning[/b]: Invalid argument supplied for foreach() in [b]C:WebServhttpdRunners2pokaz.php[/b] on line [b]213[/b]
  3. Something is wrong in your syntax obok ') AND ID_dyscyplina=)' w linii 2
  4. ?>


Nie wiem co jest grane już.
Pomoże ktoś?


Pozdrawiam
Powód edycji: dodałem tag i zmodyfikowałem temat (cysiaczek)
Go to the top of the page
+Quote Post
zzeus
post
Post #2





Grupa: Zarejestrowani
Postów: 441
Pomógł: 71
Dołączył: 3.09.2007
Skąd: wrocław

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


Spróbuj tak

  1. <input name="kategoria[]" type="checkbox" class="checkbox" value="1"/>
  2. .
  3. .
  4. .


--------------------
Go to the top of the page
+Quote Post
Rahman
post
Post #3





Grupa: Zarejestrowani
Postów: 20
Pomógł: 0
Dołączył: 10.01.2008

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


próbowałem, bez powodzenia
Go to the top of the page
+Quote Post
Cysiaczek
post
Post #4





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Przed tą linijką
  1. <?php
  2. foreach ($_GET['kategoria'] as $pt) {
  3. ?>


Daj sobie
  1. <?php
  2. print_r($_GET);
  3. ?>


Zobaczysz wtedy, dlaczego pętla foreach() zgłasza błąd... tylko nie pisz potem, że dalej nie rozumiesz smile.gif

Pozdrawiam.

Przenosze na Przedszkole

Nastepnym razem zakładaj topiki z sensowymi nazwami tematów


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
Rahman
post
Post #5





Grupa: Zarejestrowani
Postów: 20
Pomógł: 0
Dołączył: 10.01.2008

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


zrobiłem tak jak podałaś i mam tak, np po wybraniu dyscypliny i zaznaczeniu 2 checkboxów:

Kod
Array ( [dyscyplina] => 2 [kategoria] => 2 [submit] => Pokaz )
Warning: Invalid argument supplied for foreach() in C:\WebServ\httpd\Runners2\pokaz.php on line 227
select ID_prod, ID_kat, ID_dyscyplina, nazwa_prod, cena, dostepny, opis_prod from produkty where ID_kat IN () and ID_dyscyplina=2


Niestety nie potrafię z tego dojść co jest nie tak, chyba jednak zrezygnuje z tych checkboxów, nie wiem czemu nie widzi mi tych checkboxów:/

Ten post edytował Rahman 24.05.2008, 21:50:46
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 - 09:50