farshidmokh
Member
سلام... من يه سيستم بلاگ نوشتم الان تو قسمت سيستم آرشيوش موندم... اگه كسي مي دونه چه جوري مي شه نوشت كمك كنه... در ضمن آرشيو ماهيانه هم مي خوام باشه...
function NewsArchiveList()
{
$return_array=array();
$end_date=jmaketime(23,59,59,jdate('m'),jdate('t'),jdate('Y'));
$num=0;
$query_begin_date="select n_date from ".TABLE_PREFIX."news ORDER BY `n_date` ASC limit 0,1";
$result_begin_date=db_query($query_begin_date);
if($row_begin_date=db_fetch_array($result_begin_date))
{
$start_date=$row_begin_date[0];
while ($start_date<=$end_date) {
$star=jmaketime(0,0,0,jdate('m',$start_date),1,jdate('Y',$start_date));
$end=jmaketime(23,59,59,jdate('m',$start_date),jdate('t',$start_date),jdate('Y',$start_date));
$result_check_post=db_query("select count( * ) from ".TABLE_PREFIX."news where n_date>'$star' and n_date<'$end' ");
$row_check_post=db_fetch_array($result_check_post);
if($row_check_post[0]!=0)
{
$return_array[$num]['Date']= jdate('F Y',$start_date);
$return_array[$num]['Year']= jdate('Y',$start_date);
$return_array[$num]['Month']= jdate('m',$start_date);
$num++;
}
$start_date=jmaketime(0,0,0,(jdate('m',$start_date)+1),jdate('d',$start_date),jdate('Y',$start_date));
}
}
return $return_array;
}
CREATE TABLE `tbl_news` (
`n_id` int(11) NOT NULL auto_increment,
`n_title` longtext NOT NULL,
`n_description` longtext NOT NULL,
`n_date` varchar(250) NOT NULL default '',
`n_pic` varchar(250) NOT NULL default '',
`l_id` int(11) NOT NULL default '0',
KEY `n_id` (`n_id`)
) TYPE=MyISAM ;
function NewsArchiveList()
{
$return_array=array();
$end_date=jmaketime(23,59,59,jdate('m'),jdate('t') ,jdate('Y'));
$num=0;
$query_begin_date="select year from blog_entries ORDER BY `year` ASC limit 0,1";
$result_begin_date=dbcaller($query_begin_date);
if($row_begin_date=mysql_fetch_array($result_begin_date))
{
$start_date=$row_begin_date[0];
while ($start_date<=$end_date) {
$star=jmaketime(0,0,0,jdate('m',$start_date),1,jdate('Y',$start_date));
$end=jmaketime(23,59,59,jdate('m',$start_date),jdate('t',$start_date),jdate('Y',$start_date));
$result_check_post=dbcaller("select count( * ) from blog_entries where year>'$star' and year<'$end' ");
$row_check_post=mysql_fetch_array($result_check_post);
if($row_check_post[0]!=0)
{
$return_array[$num]['Date']= jdate('F Y',$start_date);
$return_array[$num]['Year']= jdate('Y',$start_date);
$return_array[$num]['Month']= jdate('m',$start_date);
$num++;
}
$start_date=jmaketime(0,0,0,(jdate('m',$start_date)+1),jdate('d',$start_date),jdate('Y',$start_date));
}
}
return $return_array;
}
Warning: mktime(): Windows does not support negative values for this function in D:\xampp\htdocs\pars\include\jalali.php on line 219
include ("dbconnect.php"); //retrieves the file that holds your database user info and password
//Now we need to set up the Next and Previous links which we can use to navigate through the archive. First lets define the variables we will use for them.
if($newsarchive) $newsarchive = 0; //If the variable $newsarchive is not defined, define it as 0
$archivenext = ($newsarchive + 10); //Define the variable $archivenext as the variable $newsarchive with 10 added to it
$archiveprevious = ($newsarchive - 10); //Define the variable $archiveprevious as the variable $newsarchive with 10 subtracted from it
//Time to run the query
$result = mysql_query("SELECT * FROM tablename ORDER BY id DESC LIMIT $newsarchive,10"); //Grab everything out of the table holding all of your data, but limit it to the first 10 entries starting at whatever your $newsarchive is currently equal to
//this means that if your $newsarchive = 10, this will display the news id's 10 to 20
//or if $newsarchive = 60, it will display the news id's 60-70
$totalresult = mysql_query("SELECT id FROM tablename"); //retrieve every row from your table
$num = mysql_num_rows($totalresult); //Number all of the rows in your database
//Now lets set up the actual visible previous and next links. We only want to set this up once. We dont want different links for every individual page.
//We will use the variables defined above ro make these links automatically change for each seperate page
if ($archiveprevious >=0) //if the variable $archiveprevious (which is equal to $newsarchive - 10) is greater than or equal to 0...
{//do this function...
echo "Previous Page";//display a link to the same page your at, except take 10 away from the $newsarchive variable
echo "
"; //break after the link
} //end this function
else {//however, if $archiveprevious is not greater than or equal to zero, we do not want to display a link.
//if we had a link to $PHP_SELF?newsarchive=-10, we would be displaying variables -10 through 0
//obviously, this is incorrect, so we use this else function to correct this
echo " ";
}
if ($archivenext < $num) //if $archive next is less than the total number of data, we want to display a link for people to go to the next page
{ //start function
echo "Next Page";//Display the link going to the next page, or next 10 pieces of data
echo "
";//break after the link
} //end this function
else {//however, if $archivenext is = or greater than total number of pieces of data, we do not want a link
echo " ";
}//end function
//Now that we have our Next and Previous links, we should display the actual data
while($row = mysql_fetch_assoc($result))//while there are rows in the table
{//do this
echo "$row[title]
$row[date]
$row[article]
"; //This will change for your archive results.
//change everything in the echo tag to display the data you want to display.
//This takes knowledge of using variables, so if your not sure what to do, go read more about php in our other tutorials
}//end this function
//OPTIONAL
//IF YOU WANT THE NEXT AND PREVIOUS LINKS DISPLAYED AGAIN AT THE BOTTOM OF YOUR PAGE
//JUST REMOVE THE /* AND */ BELOW. THIS IS THE EXACT CODE AS ABOVE!
/*
if ($archiveprevious >=0) //if the variable $archiveprevious (which is equal to $newsarchive - 10) is greater than or equal to 0...
{//do this function...
echo "Previous Page";//display a link to the same page your at, except take 10 away from the $newsarchive variable
echo "
"; //break after the link
} //end this function
else {//however, if $archiveprevious is not greater than or equal to zero, we do not want to display a link.
//if we had a link to $PHP_SELF?newsarchive=-10, we would be displaying variables -10 through 0
//obviously, this is incorrect, so we use this else function to correct this
echo " ";
}
if ($archivenext < $num) //if $archive next is less than the total number of data, we want to display a link for people to go to the next page
{ //start function
echo "Next Page";//Display the link going to the next page, or next 10 pieces of data
echo "
";//break after the link
} //end this function
else {//however, if $archivenext is = or greater than total number of pieces of data, we do not want a link
echo " ";
}//end function
*/
?>