Jump to content
php.lv forumi

Dropdown Kontrolji Formaas


cuuu

Recommended Posts

Man ir datubaazes tabula ar laukiem prece_id (unikaals) un prece_vaards (var atkaartoties). skripts izveido formu ar dropdown listiiti kuraa ir visi prece_vaards lai var izveeleeties. Rezultaataa no formas ieguustam lietotaaja izveeleeto prece_vaards lauka veertiibu, bet taalaakajam darbam eertaak izmantojams buutu atbilstoshais prece_id. lietojot, piem. Delphi, dropdown listam bija katram "vienumam" ;) 2 propertijas - "caption" (vai "text" neatceros) un "value", bet ieksh html ir tikai value. ko iesaakt lai lietotaajs vareetu izveeleeties prece_vaards, bet skriptam peec tam nebuutu jaameegina peec taa prece_vaards izziileet kaads tad ir atb. prece_id?

Link to comment
Share on other sites

patiesiibaa funktieris ljoti vienkaarshs....

<code><font color="#000000">
<font color="#0000CC"><?
</font><font color="#006600">if(</font><font color="#0000CC">$ok</font><font color="#006600">) { </font><font color="#0000CC">[url=http://lv.php.net/header]header[/url]</font><font color="#006600">(</font><font color="#CC0000">"location: view.php?id=$id"</font><font color="#006600">); exit; }
</font><font color="#0000CC">?>
</font><form name="blablabla">
<select name=id>
<option value="0" selected>----------</option>
<font color="#0000CC"><?
$result </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/mysql_query]mysql_query[/url]</font><font color="#006600">(</font><font color="#CC0000">"SELECT prece_id,prece_vaards from tabula"</font><font color="#006600">) or die(</font><font color="#CC0000">"Invalid query: " </font><font color="#006600">. </font><font color="#0000CC">[url=http://lv.php.net/mysql_error]mysql_error[/url]</font><font color="#006600">());
while (</font><font color="#0000CC">$row </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/mysql_fetch_array]mysql_fetch_array[/url]</font><font color="#006600">(</font><font color="#0000CC">$result</font><font color="#006600">)) { echo </font><font color="#CC0000">"<option value=</font><font color="#006600">"</font><font color="#CC0000">$row</font><font color="#006600">[</font><font color="#CC0000">prece_id</font><font color="#006600">]"</font><font color="#CC0000">>$row</font><font color="#006600">[</font><font color="#CC0000">prece_vaards</font><font color="#006600">]</font><font color="#CC0000"></option>"</font><font color="#006600">; }
</font><font color="#0000CC">?>
</font><input type=submit name=ok value="Parādīt">
</form></font>
</code>

 

un view.php attieciigi saakas ar shaadu tekstu:

<code><font color="#000000">
<font color="#0000CC"><?
$result</font><font color="#006600">=</font><font color="#0000CC">mysql_query</font><font color="#006600">=(</font><font color="#CC0000">"select prece_vaards from tabula where prece_id=$id"</font><font color="#006600">);
</font><font color="#0000CC">$row</font><font color="#006600">=</font><font color="#0000CC">[url=http://lv.php.net/mysql_fetch_array]mysql_fetch_array[/url]</font><font color="#006600">(</font><font color="#0000CC">$result</font><font color="#006600">);
</font><font color="#0000CC">$preces_nosaukums</font><font color="#006600">=</font><font color="#0000CC">$row</font><font color="#006600">[</font><font color="#0000CC">prece_vaards</font><font color="#006600">];
</font><font color="#0000CC">?></font>
</font>
</code>

un taalaak jau vari njemties kaa vien sirds veelaas :)

Link to comment
Share on other sites

×
×
  • Create New...