Jump to content
php.lv forumi

array problema


sega99

Recommended Posts

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 by sega99
Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...