sega99 Posted February 4, 2012 Report Share Posted February 4, 2012 (edited) pirmo reizi esmu saskaries ar array, izmeklejos pusotru stundu google un visadi izmeginajos BET nu nekaa.. $cool = mysql_query("SELECT * FROM mantas ORDER BY time DESC limit 5") or die(mysql_error()); while($row = mysql_fetch_array( $cool )) { $time = date('m',$row["time"]); $id = $row["id"]; $dati = array(); $dati["$time"] = "$id"; } foreach ($dati as $m => $data) { if ($m == 01) { echo 'janvara mantas:'; echo $data; } else if ($m == 02) { echo 'februara mantas:'; echo $data; } } nesaprotu kā lai iztaisa lai galu galā iznāktu sakārtoti kas bijis piemēram pagašgad katrā mēnesī janvara mantas: menesis 01 id:12 menesis 01 id:13 februara mantas: menesis 02 id: 14 menesis 02 id: 16 menesis 02 id: 19 Edited February 4, 2012 by sega99 Quote Link to comment Share on other sites More sharing options...
briedis Posted February 4, 2012 Report Share Posted February 4, 2012 Papēti savu while ciklu. Kāda jēga ir no $dati mainīgā, ja tur katrā cikla iterācija šo masīvu pārraksti (nevis papildini) Quote Link to comment Share on other sites More sharing options...
vertex Posted February 5, 2012 Report Share Posted February 5, 2012 $dati["$time"] = "$id"; Papildinot briedis teiktu, kādēļ Tu viņus liec kā string, nevis kā parastu mainīgo? t.i. $dati[$time] = $id; Tad vēl vajadzētu Tev šo dati array iznest ārā no while. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted February 5, 2012 Report Share Posted February 5, 2012 Man gribas bļaut uz tevi ar tekstu RTFM!!!!!!! Bet es to nedarīšu. :) Quote Link to comment Share on other sites More sharing options...
Swear Posted February 5, 2012 Report Share Posted February 5, 2012 <?php $q = mysql_query("SELECT * FROM mantas ORDER BY time DESC limit 5") or die(mysql_error()); while($r = mysql_fetch_array($q)) { $month = date('m', $r["time"]); $dati[$month] = $r; } foreach ($dati as $m => $jaunumi) { echo "{$m}. menesa jaunumi:"; foreach($jaunumi as $x=> $news) { echo "> Jaunums id: {$news['id']}<br />"; } echo "<br />"; } netesteju, bet pec idejas vajadzetu stradat. Quote Link to comment Share on other sites More sharing options...
briedis Posted February 5, 2012 Report Share Posted February 5, 2012 <?php $q = mysql_query("SELECT * FROM mantas ORDER BY time DESC limit 5") or die(mysql_error()); while($r = mysql_fetch_array($q)) { $month = date('m', $r["time"]); $dati[$month] = $r; } foreach ($dati as $m => $jaunumi) { echo "{$m}. menesa jaunumi:"; foreach($jaunumi as $x=> $news) { echo "> Jaunums id: {$news['id']}<br />"; } echo "<br />"; } netesteju, bet pec idejas vajadzetu stradat. Strādās, tikai vienā mēnesī varēs būt tikai 1 ieraksts, iepriekšējais tiks vienkarši pārrakstīts. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.