Chtěl bych se zeptat jak mám vyřešit to když na stránce používám např. pole goly
a pole hráči, při čemž obě pole nemají shodný počet položek, jak bych to měl co
nejlépe vyřešit s ukládáním do databáze
v db mám položky id_utkani,id_hrace,goly
Fórum › PHP
Jak pracovat s dvěma poli

Paja2
Možná by pro nechápajícího (jakým jsem například já) bylo dobré napsat trochu více. Hlavně v jakém vztahu jsou spolu položky pole góly s hráči? Lepší popis tabulek v databázi by se také hodil. Možná taky, odkud ti data vstupují? A přihodit nějaký příklad a popis, čeho chceš dosáhnout, by tomu dodalo třešinku. (Příklad ve smyslu: "Když tam dám tenhle vstup, chci, aby mi vylezlo tohle.")
To bukaj :
tak mám níže uvedený kod, kde host_h_id je id hráče a id_hostt který je id týmu, to pak rozděluji pomocí explode
echo"<tr><td><input type='checkbox' $checked2 value='".$hraci2["host_h_id"]."_".$hraci2["id_hostt"]."' name='hraci[]'>".$hraci2["hostujicihraci"]."</td><td><input type='text' size='2'name='goly[]'></td></tr>";
a pak mám¨
$ideutkani=$_POST['zapas'];
for($i=0;$i<=count($_POST['goly']);$i++){
$x=$_POST['hraci'][$i];
$l=explode("_",$x);
$k=$l[0];
$team=$l[1];
echo $x;
mysql_query("insert into system_goly values ('$ideutkani','$k','$team','".$_POST['goly'][$i]."')");
}
ale bude se mi podaří uložit jen goly nebo jen id hrače a týmu
No nejlepsi by to samozrejme bylo vlozit to do jedne tabulky. Druhe reseni jsou transakce, podivej se na to - to je presne to co hledas - zajistuji, aby se provedly bud vsechny nebo zadny prikaz.

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Jak pracovat se dvěma po sobě jdoucími řádky? — založil hlucheucho
Jak pracovat s array? — založil fix
Jak pracovat s MPlabem? — založil Brejloun
Jak pracovat s knihovnou stdarg.h? — založil Petey
Jak pracovat s bufferem s pixely — založil oxidián
Moderátoři diskuze