|
|
|
<?
//using MySQL
//unzip and put somewhere
//This chunk of code uses a calendar type navigation to bring results from a db or other
//
//This example snags a database result using a date field
//
//and an example of snagging directories by name/date (courtesy of CNN)
//
//Codes a bit sloppy - not really tightened up - ok for a few hours chomping
// Paul Routledge qube@proqc.com
//do your stuff here
//$where="this_dir_and_filename";// the filename or use next one
$where=$PHP_SELF;?>
$con=mysql_connect("host","user","pass");
mysql_select_db("database",$con);
<html>
<head>
<title>Calendar Navigator</title>
</head><body text=white bgcolor=#222222 marginwidth=0 marginheight=0 topmargin=0 leftmargin=0>
<table border=0 cellspacing=1><tr><td width=178>
<?
//set the calendar initial vars
if($nextm==">"){if($month==12){$month=1;$year++;}else{$month++;}}
if($previousm=="<"){if($month==1){$month=12;$year--;}else{$month--;}}
if($day<="9"&ereg("(^[1-9]{1})",$day)){$day="0".$day;}
if($month<="9"&ereg("(^[1-9]{1})",$month)){$month="0".$month;}
if(!$year){$year=date("Y",mktime());}
if(!$month){$month=date("m",mktime());}
if(!$day){$day=date("d",mktime());}
$thisday="$year-$month-$day";
$day_name=array("M","T","W","Th","F","S","<font color=red>S</font>");
$month_abbr=array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");// set an initial bogey for loop beginning 1 not 0
echo"<form action='$where' method=post >\n";
echo"<table width=177 cellpadding=0 cellspacing=2 border=0 bgcolor=#777777>\n";
echo"<td align=center colspan=8><input type=submit style='font-family: verdana,Arial; font-size: 10px' name=previousm value=\"<\" >\n";
echo"<select name=month style='font-family: verdana,Arial; font-size: 10px'>\n";
// use a bogey here a=1 last=13 then we keep the correct month number in the array
for($a=1; $a<13; $a++)
{
$mo=date("n",mktime(0,0,0,$a,1,$year));
$name_of_month=$month_abbr[$mo];
if($mo==$month)
{
echo"<option value=$a selected>$name_of_month\n";
}else{echo"<option value=$a>$name_of_month\n";}
}
echo"</select>\n";
echo"<input type=hidden name=s value=1>";
echo"<input type=submit value=go style='font-family: verdana,Arial; font-size: 10px'>\n";
echo"<select name=year style='font-family: verdana,Arial; font-size: 10px'>\n";
$y=date("Y");
if($year<$y-2){echo"<option value=$year selected >$year\n";}
for($i=$y-2;$i<=$y+5;$i++){if($i==$year){echo"<option value=$i selected>$i\n";}else{echo"<option value=$i>$i\n";}}
if($year>$y+5){echo"<option value=$year selected>$year\n";}
echo"</select>\n";
if($day){echo"<input type=hidden name=day value=$day>";}
echo "<input type=submit name=nextm value=\">\" style='font-family: verdana,Arial; font-size: 10px'>";
echo "</td>\n";
echo "</tr>\n";
//week day names
echo"<tr align=center>\n<td width=25 align=center bgcolor=orange><i>Wk</i></td>\n";
for($i=0;$i<7;$i++){echo"<td width=25 bgcolor=darkorange>$day_name[$i]</td>\n";}
echo "</tr><tr>\n";
//first week if in previous month
if(date("w",mktime(0,0,0,$month,1,$year))==0){$da=-6;}
elseif(date("w",mktime(0,0,0,$month,1,$year))<>1){$da= - date("w",mktime(0,0,0,$month,1,$year))+1;}
else{$da = 1;}
//week number //iron out the 00/53 week number
if(strftime('%W',mktime(0,0,0,$month,($da+2),$year))==00)
{
echo(strftime("<td align=center bgcolor=#666666><i><a href=\"$where?s=2&year=%Y&month=%m&w=%W&day=%d\"><font
color=orange><b>%W</b></font></a></i></td>\n", mktime(0,0,0,$month,$da+1,$year)));
}
else
{
echo(strftime("<td align=center bgcolor=#666666><i><a href=\"$where?s=2&year=%Y&month=%m&w=%W&day=%d\"><font
color=orange><b>%W</b></font></a></i></td>\n", mktime(0,0,0,$month,$da+1,$year)));
}
// show overlap days of previous month
if(date("w",mktime(0,0,0,$month,1,$year))==0){$start=7;}else{$start=date("w",mktime(0,0,0,$month,1,$year));}
for($a=($start-2);$a>=0;$a--)
{
$d=date("t",mktime(0,0,0,$month,0,$year))-$a;
echo"<td bgcolor=#AAAAAA align=center>$d</td>\n";
}
//days of the month
for($d=1;$d<=date("t",mktime(0,0,0,($month+1),0,$year));$d++)
{
//day link - today with different color bg
if($month==date("m")&$year==date("Y")&$d==date("d")){$bg="bgcolor=orange";}else{$bg="bgcolor=#FFFFFF";}
echo"<td $bg align=center><a href=\"$where?year=$year&month=$month&day=$d&s=0\">$d</a></td>\n";
if(date("w",mktime(0,0,0,$month,$d,$year))==0&date("t",mktime(0,0,0,($month+1),0,$year))>$d)
{
echo"</tr><tr>\n";
$da=$d+1;
//iron out the 00/53 week number
if(strftime('%W',mktime(0,0,0,$month,($d+2),$year))==00){echo"<td align=center bgcolor=#666666><i><a
href=\"$where?s=2&year=$year&month=$month&w=53&day=$da\"><font color=orange><b>53</b></font></a></i></td>\n";}
else{echo(strftime("<td align=center bgcolor=#666666><i><a href=\"$where?s=2&year=%Y&month=%m&w=%W&day=%d\"><font
color=orange><b>%W</b></font></a></i></td>\n",mktime(0,0,0,$month,($d+1),$year)));}
}
}
// days of next month
if(date("w",mktime(0,0,0,$month+1,1,$year))<>1)
{
$d=1;
while(date("w",mktime(0,0,0,($month+1),$d,$year))<>1)
{
echo"<td bgcolor=#AAAAAA align=center>$d</td>\n";
$d++;
}
}
echo"</form>";
echo "</tr></table>\n";
echo"</td><td valign=bottom class=g>";
echo"<h2>$thisday</h2>";
//put the sql here
if($s==2){$sql_select = "select stuff from table where datefield like '$year%' and week(open_date,1)='$w' order by open_date desc";}
if($s==0){$sql_select = "select stuff from table where datefield='$thisday' order by open_date desc";}
if($s==1){$sql_select = "select stuff from tablewhere datefield like '$year-$month%' order by open_date desc";}
//make the call
$result = mysql_query ($sql_select);
if($s==2){echo(mysql_num_rows($result));echo" Results in Week $w, $year";}
if($s==0){echo(mysql_num_rows($result));echo" Results on ".strftime("%A, %B $day",mktime(0,0,0,$month,$day,$year))." $year";}
if($s==1){echo(mysql_num_rows($result));echo" Results in ".strftime("%B",mktime(0,0,0,$month,$day,$year)).", $year";}
echo"</td></tr>";
echo"<tr><td colspan=1 class=g valign=top>";
if(!mysql_num_rows($result)==0){echo"<hr noshade><b>Database Results</b>";}
//put the db return results here
echo"<pre>";
while ($row = mysql_fetch_array($result))
{
$date = $row["date"];
$stuff = $row["stuff"];echo"$date | $stuff \n";
}
?>
<hr noshade></PRE></td><td class=g valign=top>
<?
//snag some directories by date from CNN using calendar navigation - cnn's a bit slow =)
$cnn="http://www.cnn.com/";
$ni=array("US","WORLD/europe","WORLD/africa","WORLD/americas","WORLD/meast");
$nl=array("US","European","African","Americas","Middle-East");
$nwls=count($ni);
for($id=0;$id<$nwls;++$id)
{
echo"<BASE HREF=\"$cnn$year/$ni[$id]/$month/$day/\">";
$filo=@fopen("$cnn$year/$ni[$id]/$month/$day","r");
// remove some stuff
echo(
@eregi_replace("Index of ","<HR NOSHADE>CNN $nl[$id] News ",
@preg_replace("/<\/?(TITLE).*>/","",
@eregi_replace("<A HREF=\"","<A TARGET=_news HREF=\"",
@eregi_replace("H1","H3",
@fread($filo,10000))))));
}
mysql_close();
?></td></tr></td></table></body></html> |
|
/home/WWW/new/get_example.php3 (531)
SELECT counter,titl sum FROM examples WHERE counter <> 3175 GROUP BY category1,category2,category3,category4,category5 HAVING sum >= 2 ORDER BY sum DESC LIMIT 15
Unknown column 'titl' in 'field list'
Click Here to try again |