hi anil and group members,
from all the discussions above i got what anil is looking for and i found out the solution for it. the code will be little bit to long. i have given the comment line where ever it is needed. hope every one can understand. by seeing this code if any one find solution with minimal code plz discuss with the same heading or if u feel difficult in understanding plz enquire with me.
**********************************************
Cod for the date display: (this will help if data type is varchar)
***********************************************
PHP Code:
$query_Newss = "SELECT id,`date` FROM nande WHERE type=news";
$Newss = mysql_query($query_Newss, $GBC) or die(mysql_error());
$row_Newss = mysql_fetch_assoc($Newss);
$totalRows_Newss = mysql_num_rows($Newss);
$arrids= array();
$arrdates= array();
$mkarrays= array(); //for storing mktime
$mkarrays1= array(); //for storing mktime, future reference
$results=array();
$arrdatees= array();
$is=0;
do
{
$arrids[$is]=$row_Newss['id'];
$arrdates[$is]=$row_Newss['date'];
$is++;
}while($row_Newss = mysql_fetch_array($Newss));
//code for splitting the date
$cnts1=count($arrdates);
for($is=0;$is<$cnts1;$is++)
{
$strings1=$arrdates[$is];
$arrdatees[$is]=substr($strings1,0,10); // for future reference
$dds=substr($strings1,0,2); //for date
$mms=substr($strings1,3,2); //for month
$yys=substr($strings1,6,4); // for year
$mkarrays[$is]= mktime(0, 0, 0, $mms, $dds, $yys);
$mkarrays1[$is]= mktime(0, 0, 0, $mms, $dds, $yys);
}
asort($mkarrays);
$sts=strftime("%m,%d,%Y"); // getting server time
$sts1= mktime(0, 0, 0, $sts); // getting timestamp for server time
// code for subtracting server time with the timestamp generated for value stored in database
for($is=0;$is<$cnts1;$is++)
{
$results[$is]=$sts1-$mkarrays1[$is];
}
asort($results); //sorting the subtracted value array
natsort($results); // performing the natuaral sorting algortim for the result array
// for diaplaying
$afs=array();
$afs=array_keys($results);
$newarrs=array();
for($is=0;$is<$cnts1;$is++)
{
$newarrs[$is]=$results[$afs[$is]];
}
// for finding if same date exist in the database
$zeroarrays=array();
$kks=0;
$mms=0;
$finalarrs=array();
$indexs=array();
for($is=0;$is<$cnts1;$is++)
{
if($newarrs[$is]==0)
{
$zeroarrays[$mms]=$is;
$mms++;
}
}
$cntzerarrs=count($zeroarrays);
if($cntzerarrs==0)
{
//finalarr will contain the result what we need
for($is=0;$is<$cnts1;$is++)
{
$finalarrs[$is]= date("j-n-Y",($sts1-$newarrs[$is]));
}
print_r($finalarrs);
// for getting the array index value. i.e not having o value
for($is=0;$is<$cnts1;$is++)
{
for($js=0;$js<$cnts1;$js++)
{
if($finalarrs[$is]==$arrdatees[$js])
$indexs[$is]=$arrids[$js];
}
}
} //end of if cntzerarr=0 condition
else
{
for($is=0;$is<$cntzerarrs;$is++)
{
$valuess=$zeroarrays[$is];
$finalarrs[$is]= date("j-n-Y",($sts1-$newarrs[$valuess]));
$kks=$is;
}
for($is=0;$is<$cnts1;$is++)
{
if(in_array($is,$zeroarrays))
{
}
else
{
$kks=$kks+1;
$finalarrs[$kks]= date("j-n-Y",($sts1-$newarrs[$is]));
}
}
for($is=0;$is<$cnts1;$is++)
{
for($js=0;$js<$cnts1;$js++)
{
if($finalarrs[$is]==$arrdatees[$js])
$indexs[$is]=$arrids[$js];
}
}
}// end of else
$lastids=$indexs[0];
$listings = "SELECT id, news, details, `date`, image, title, type FROM nande WHERE type='news' and id='$lastids'";
$listings1= mysql_query($listings, $GBC) or die(mysql_error());
$listings2 = mysql_fetch_assoc($listings1);
see i have display only the latest date in lastids. if u want the forthcoming date to be displayed then use the loop to select the query and display it.
hope it will solve the date problem.
Bye....
Azhagiri
India
Bookmarks