jansonz Posted May 19, 2004 Report Share Posted May 19, 2004 Problema: Nepiecieshams ar sesijas palidzibu izveidot masiivu. Piemeram ja lietotajs ievada kadu noteiktu vertibu, ta tiek ierakstita masiva un peec 10 shadiem cikliem viss masivs tiek izvadits lauka. Varbut kads var palidzet..... :huh: Link to comment Share on other sites More sharing options...
Gacha Posted May 19, 2004 Report Share Posted May 19, 2004 Man liekas, ka nesapratu <_< 1 variants: $_SESSION['masivs'][0] = $vertiba1; $_SESSION['masivs'][1] = $vertiba2; $_SESSION['masivs'][2] = $vertiba3; Vai arii: for ($i=0; $i>=10; $i++;){ $_SESSION['masivs'][$i] = $vertiba[$i]; } Link to comment Share on other sites More sharing options...
jansonz Posted May 19, 2004 Author Report Share Posted May 19, 2004 Meeginaashu izteikties skaidraak :) : Yaatad, taisu mazu testu! Man vajag visas nepareizi atbildetas atbildes ievadit masivaa un testa beigas atkal zivadiit taas, lai lietotajs varetu apskatit ko atbildejis nepareizi... Masiivaa ievadiit maku, bet kaa lai atrod masiva pedejo elementu un tad nakoshajaa ievada, lai neparrakstitu rezultatus??? irmantot varbut ciklu, kas meklee '\0' ?? Zinu,ka uz C++ shadi var, bet kaa lai dara uz PHP???? :( Link to comment Share on other sites More sharing options...
bubu Posted May 19, 2004 Report Share Posted May 19, 2004 Variants 1) glabaa masiiva 0-taa elementaa vai citaa mainiigaa masiiva izmeeru Variants 2) klaat elementus liec ar $masivs[] = $mainigais; sintaksi, tad varees ar count($masivs) fju dabuut masiivaa ielikto elementu skaitu. Link to comment Share on other sites More sharing options...
jansonz Posted May 19, 2004 Author Report Share Posted May 19, 2004 bubu, isti nesapratu kaa ti to biji domaajis! <_< Link to comment Share on other sites More sharing options...
bubu Posted May 20, 2004 Report Share Posted May 20, 2004 nu 1.variantaa biju domaajis, ka ieksh $_SESSION['masivs'][0] glabaa $_SESSION['masivs'] masiiva garumu (elementu skaitu), un taadeejaadi, kad vajadzees pievienot jaunu, tad $cnt = ++$_SESSION['masivs'][0]; $_SESSION['masivs'][$cnt] = $jaunaVertiba; vai arii garumu glabaa ieksh $_SESSION['garums'] un tad $cnt = $_SESSION['garums']++; $_SESSION['masivs'][$cnt] = $jaunaVertiba; a 2.variantaa domaaju, ka ieksh kautkaada , glabaa masiiva garumu dabuu ar $cnt = count($_SESSION['masivs']); un tad peedeejais elements masiivaa buus $_SESSION['masivs'][$cnt-1] a ja jaunu vajag piemest klaat, tad $_SESSION['masivs'][] = $jaunaVertiba Link to comment Share on other sites More sharing options...
jansonz Posted May 20, 2004 Author Report Share Posted May 20, 2004 Kautkas isti nerukaa: //failaa index.php taatad, ja atbilde ir nepareiza: if($atb != $tmp){ $_SESSION['kludas']++; $ska = count($masivsa); $skb = count($masivsb); $_SESSION['masivsa'][]=$h; $_SESSION['masivsb'][]=$atb; } // $h ir jautajuma nr, bet $atb ir atbildes nr, ko lietotaajs ievadija... // failaa rezult.php if($cat == "rez"){ $a = count($_SESSION['masivsa']); $b = count($_SESSION['masivsb']); echo "<br><br>"; echo " Masivaa a ir $a elementi"; //izdrukaa 0, tik nezinu kaadeelj echo " Masivaa b ir $b elementi"; // arii izdrukaa 0 for($i=0;$i<=$a;$i++){ echo "$i"; echo $_SESSION['masivsa'][$i]; //un te arii izdrukaa tikai vienu 0 echo "\n"; } Kaareelj vinsh drukaa laukaa tikai nulles?? Vai tad masiivaa nekas nesaglabaajas??? <_< Link to comment Share on other sites More sharing options...
bubu Posted May 21, 2004 Report Share Posted May 21, 2004 a zin ko, kā tu inicializē šo $_SESSION['masivsa'] ? vajadzētu pamēģināt pašu pirmo reizi viņam piešķirt tukšu masīvu: $_SESSION['masivsa'] = array(); un tad tikai grūst datus iekšā Link to comment Share on other sites More sharing options...
Recommended Posts