Jump to content
php.lv forumi

Kļūda darbībā


Raivis.purins

Recommended Posts

Situācija ir sekojoša, esmu izveidojis arhīva bloku, kur ar get metodi cenšos izvilkt attiecīgo mēnešu ierakstus, bet rezultāts ir neizprotams, jo pie vecāka mēneša tiek izmesti visi tā gada ieraksti, savukārt pie jaunākā linka, izmet tikai pēdējā mēneša ierakstu

 

Kods:

 

<?php include ('blocks/db.php'); 

if (isset($_GET['date']))
{
$date = $_GET['date'];	
}
else
{
exit("<p>Jūs ievadījāt nepareizus datus</p>");	
}


$date_begin = $date;
$date++;
$date_end = $date;

$date_begin = $date_begin."-01";
$date_end = $date_end."-01";
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo "Attiecīgā mēneša ieraksti"; ?></title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>

<table width="690" border="0" align="center" bgcolor="#FFFFFF" class="main_border">
 <?php include ("blocks/header.php");?>
 <tr>
   <td valign="top"><table width="100%" border="0">
     <tr>
       <?php include ("blocks/tdleft.php");?>
       <td valign="top"><?php 

       $result9 = mysql_query("SELECT id,title,description,date,author,mini_img,view FROM data WHERE date>'$date_begin' AND date<'date_end'",$db);
	if (!$result9)
{
echo "<p>Loģiskais pieprasījums nav nostrādājis, uzrakstiet e-pastu [email protected]<br><strong>Kļūdas kods ir:</strong>  </p>";	
exit(mysql_error());
}
if (mysql_num_rows($result9) > 0)
{
$myrow9 = mysql_fetch_array($result9);

do 
{
printf ("<br><table align='center' class='post'>

	 <tr>
        <td class='post_title'>
	 <p class='post_name'><img class='mini' align='left' src='%s'><a href='view_post.php?id=%s'>%s</a></p>
	 <p class='post_adds'>Pievienošanas datums: %s</p>
	 <p class='post_adds'>Ieraksta autors: %s</p></td>
        </tr>

	 <tr>
        <td><p>%s</p><p class='post_view'>Skatīts: %s</p></td>
        </tr>

	 </table><br><br>",$myrow9["mini_img"], $myrow9["id"], $myrow9["title"],$myrow9["date"],$myrow9["author"],$myrow9["description"],$myrow9["view"]); 

}
while ($myrow9 = mysql_fetch_array($result9));


}
else
{
echo "<p>informācija nevar tikt izvilkta, jo nav db ieraksti  </p>";
exit();
}


    ?>   


       </td>
     </tr>
   </table></td>
 </tr>
 <?php include ("blocks/footer.php");?>
</table>
</body>
</html>

Edited by Raivis.purins
Link to comment
Share on other sites

Jā, $date ir tieši tā kā tu saki,man arī bija klusas aizdomas, ka tur arī ir viss tas suns aprakts, bet šajā gadījumā es tikai mācos un eju soli pa solim pēc tutoriāļiem. Kāds ir iespējamais labojums? pārtaisīt datubāzē datumu uz šādu formātu 20100101?

Edited by Raivis.purins
Link to comment
Share on other sites

Es izmantotu strtotime(), kas pārveido uz timestamp un tad pieskaitītu attiecīgo laika posmu. Pēc tam, jau ar date() vari dabūt atpakaļ kādā formātā gribi.

Tikai ar strtotime() pārliecinies, vai viņš pareizi ir sapratis datumu. YYYY-mm-dd, noteikti saprastu, bet par YYYY-mm neesmu drošs.

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