soap_box
05-06-2009, 06:18 PM
Hi, I have a code someone made me a while ago, it works fine on the site I was making back then, but for some reason it doesn't work on the one I'm doing now.
Its main function is to list all months from now and then when you click a month, show all entries in a database from that month.
For some reason it is just showing "May 2009" twice and when I click on that it's bringing up nothing (there are entries made in May 2009)
<?
//get desired month and year
if (isset($_GET['month']))
{
$desiredMonth = $_GET['month'];
} else {
$desiredMonth = '';
}
if (isset($_GET['year']))
{
$desiredYear = $_GET['year'];
} else {
$desiredYear = '';
}
if($desiredMonth && $desiredYear)
{
$db=mysql_connect("*****","*****","*****") or die ('cant connect');
mysql_select_db("*****",$db) or die ("cant change");
$news=mysql_query("SELECT * FROM news WHERE 1 AND date LIKE '%".$desiredMonth."%".$desiredYear."%' ORDER BY id DESC") or die ("cant get table");
while($rows=mysql_fetch_array($news)){
$title=$rows["title"];
$body=$rows["body"];
$date=$rows["date"];
$id=$rows["id"];
echo "<h3>$title</h3>
<p>$date</p>
<p>$body</p>";
}
} else {
$time1 = strtotime('2009-05-06');
$time2 = strtotime("now");
$my = date('mY', $time2);
$months = array(date('F Y', $time1));
while($time1 < $time2) {
$time1 = strtotime(date('Y-m-d', $time1).' +1 month');
if(date('mY', $time1) != $my && ($time1 < $time2))
$months[] = date('F Y', $time1);
}
$months[] = date('F Y', $time2);
foreach ($months as $value){
echo "<a href='archive.php?month=".substr($value, 0, 3)."&year=".substr($value, -4)."'>".$value."</a>";
}
}
?>
it could be something really simple but I dont actually know php and I cant ask the person who made it originally, I would be very grateful for any help
~sb
Its main function is to list all months from now and then when you click a month, show all entries in a database from that month.
For some reason it is just showing "May 2009" twice and when I click on that it's bringing up nothing (there are entries made in May 2009)
<?
//get desired month and year
if (isset($_GET['month']))
{
$desiredMonth = $_GET['month'];
} else {
$desiredMonth = '';
}
if (isset($_GET['year']))
{
$desiredYear = $_GET['year'];
} else {
$desiredYear = '';
}
if($desiredMonth && $desiredYear)
{
$db=mysql_connect("*****","*****","*****") or die ('cant connect');
mysql_select_db("*****",$db) or die ("cant change");
$news=mysql_query("SELECT * FROM news WHERE 1 AND date LIKE '%".$desiredMonth."%".$desiredYear."%' ORDER BY id DESC") or die ("cant get table");
while($rows=mysql_fetch_array($news)){
$title=$rows["title"];
$body=$rows["body"];
$date=$rows["date"];
$id=$rows["id"];
echo "<h3>$title</h3>
<p>$date</p>
<p>$body</p>";
}
} else {
$time1 = strtotime('2009-05-06');
$time2 = strtotime("now");
$my = date('mY', $time2);
$months = array(date('F Y', $time1));
while($time1 < $time2) {
$time1 = strtotime(date('Y-m-d', $time1).' +1 month');
if(date('mY', $time1) != $my && ($time1 < $time2))
$months[] = date('F Y', $time1);
}
$months[] = date('F Y', $time2);
foreach ($months as $value){
echo "<a href='archive.php?month=".substr($value, 0, 3)."&year=".substr($value, -4)."'>".$value."</a>";
}
}
?>
it could be something really simple but I dont actually know php and I cant ask the person who made it originally, I would be very grateful for any help
~sb