mam taki kod :

  1. <?php
  2. echo &#092;"<tr><td width=\"20%\"><b>Kategoria </b></td><td width=\"5\">:</td><td>\";
  3. echo &#092;"<select name=\"kategoria\">\";
  4. $result = mysql_query(&#092;"select idk,nazwa from oferta_kat order by nazwa\",$dbi);
  5. while (list($xidk,$xnazwa) = mysql_fetch_row($result,$dbi)) { 
  6. $result2 = mysql_query(&#092;"select idpk,pnazwa from oferta_pkat where idk='$xidk' order by pnazwa\",$dbi);
  7. while (list($xidpk,$xpnazwa) = mysql_fetch_row($result2,$dbi)) {
  8. echo &#092;"<option value=\"$xidk\".\"_\".\"$xidpk\">$xnazwa-$xpnazwa</option>n\";
  9. }
  10. }
  11.  mysql_free_result($result);
  12. echo &#092;"</select></td></tr>\";
  13. ?>



no i za chiny nie chce dzialac, sprawdzilem juz wszystko, nazwy pol sa wpisane dobrze , nazwy tabel tez , nie widze bledu a pole select jest dalej puste.

Zadanie jest takie ze do jednego selecta ma byc pobierana kategoria i podkategoria przyporzadkowana kategorii. Dane maja byc zlaczone . potem po przeslaniu je rozdziele .

Fragment kodu pochodzi z gotowca z modulu phpnuke, jednak przerobilem go i powinien takze dzialac, kod oryginalu:


  1. <?php
  2.  
  3. echo&#092;"\"
  4. .&#092;"<select name=\"catgforprocess\">\";
  5. $result = sql_query(&#092;"select id_catg,catg from $prefix\".\"_ads_category where language='$currentlang' order by catg\",$dbi);
  6. while (list($xid_catg,$xcatg) = sql_fetch_row($result,$dbi)){ 
  7. $result2 = sql_query(&#092;"select id_subcatg,subcatg from $prefix\".\"_ads_subcatg where id_catg='$xid_catg' order by subcatg\",$dbi);
  8. while (list($xid_subcatg,$xsubcatg) = sql_fetch_row($result2,$dbi)) {
  9. echo &#092;"<option value=\"$xid_catg\".\"_\".\"$xid_subcatg\">$xcatg-$xsubcatg</option>n\";
  10.  }
  11.  sql_free_result($result2);
  12. }
  13.  sql_free_result($result);
  14.  echo &#092;"</select>\"
  15.  .&#092;"</td></tr>\";
  16. ?>




Juz sobie poradzilem


  1. <?php
  2.  echo &#092;"<select name=\"kategoria\">\";
  3.  echo &#092;"<option value=\"0\".\"_\".\"0\">Kategorie/podkategorie</option>n\";
  4. $result = mysql_query(&#092;"select * from oferta_kat order by nazwa\",$dbi);
  5.  while ($kat = mysql_fetch_array($result)) { 
  6. echo &#092;"<option value=\"$kat[idk]\".\"_\".\"0\">$kat[nazwa]</option>n\";
  7.  $result2 = mysql_query(&#092;"select * from oferta_pkat where idk='$kat[idk]' order by pnazwa\",$dbi);
  8. while ($kat2 = mysql_fetch_array($result2)) {
  9. echo &#092;"<option value=\"$kat[idk]\".\"_\".\"$kat2[idpk]\">$kat[nazwa]-$kat2[pnazwa]</option>n\";
  10. } 
  11.  
  12.  
  13. mysql_free_result($result2);
  14. }
  15.  
  16. echo &#092;"</select></td></tr>\";
  17. ?>