budimir Posted August 12, 2008 Share Posted August 12, 2008 Ok guys, I have seen this once, but I can't find it any more. So, that is a paging system but works on that way it's separating records by year - month. Example is bellow: 2008 | 2009 | 2010 | ... January | February | March | April | May | ... When clicked on 2008 and April it will display all records that where made in April 2008. Does anyone nows anything about this, or can someone point me to the right direction how to do this??? It really simplifies your life... Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/119352-solved-paging-by-year-month/ Share on other sites More sharing options...
spasme Posted August 12, 2008 Share Posted August 12, 2008 Here's what o would do: <?PHP $year = $_GET[year]; $month = $_GET[month]; ?> <a href="records.php?year=2008<?PHP if ($month) echo "&month=$month" ?> ">2008</a> | <a href="records.php?year=2009<?PHP if ($month) echo "&month=$month" ?> ">2009</a> | <a href="records.php?year=2010<?PHP if ($month) echo "&month=$month" ?> ">2010</a> | <a href="records.php?<?PHP if ($year) echo "year=$year" ?>&month=january">January</a> | <a href="records.php?<?PHP if ($year) echo "year=$year" ?>&month=february">February</a> | <a href="records.php?<?PHP if ($year) echo "year=$year" ?>&month=march">March</a> | <?PHP if ($year && $month) { mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $result = mysql_query("SELECT * FROM $table WHERE year='$year' AND month='$month'") or die ("Could not read data because ".mysql_error()); while ($qry = mysql_fetch_array($result)) { echo $qry[record]; } } else { echo "Please select both Year and Month"; } ?> NOTE: You might want to have DB fields in you records table such as 'month' and 'year' to be able to select the ones you need... Let me know if this is of any help. Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/119352-solved-paging-by-year-month/#findComment-614827 Share on other sites More sharing options...
budimir Posted August 12, 2008 Author Share Posted August 12, 2008 Yep, something like that. I'll give it a try and let you know if I could make it. Thanks, anyway. Good suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/119352-solved-paging-by-year-month/#findComment-614835 Share on other sites More sharing options...
budimir Posted August 12, 2008 Author Share Posted August 12, 2008 OK, this is my modified code: <?PHP $year = $_GET['year']; $month = $_GET['month']; ?> <a href="pregled_obilazaka.php?year=2008<?PHP if ($month) echo "&month=$month" ?> ">2008</a> | <a href="pregled_obilazaka.php?year=2009<?PHP if ($month) echo "&month=$month" ?> ">2009</a> | <a href="pregled_obilazaka.php?year=2010<?PHP if ($month) echo "&month=$month" ?> ">2010</a> | <a href="pregled_obilazaka.php?year=2011<?PHP if ($month) echo "&month=$month" ?> ">2011</a> | <a href="pregled_obilazaka.php?year=2012<?PHP if ($month) echo "&month=$month" ?> ">2012</a> <p> <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=01">Siječanj</a> | <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=02">Veljača</a> | <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=03">Ožujak</a> | <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=04">Travanj</a> | <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=05">Svibanj</a> | <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=06">Lipanj</a> | <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=07">Srpanj</a> | <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=08">Kolovoz</a> | <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=09">Rujan</a> | <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=10">Listopad</a> | <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=11">Studeni</a> | <a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=12">Prosinac</a> </p> <?PHP if ($year && $month) { $upit = "SELECT * FROM obilasci WHERE datum='$year' AND datum='$month'"; $rezultat = mysql_query($upit) or die (mysql_error()); while ($qry = mysql_fetch_array($rezultat)) { echo $qry[record]; } } else { echo "Please select both Year and Month"; } ?> But, my problem is in the fields in DB. This is example of the entry in DB: ID DATE NAME MESSAGE REF ID 12 2008-08-08 Ivica Makarovski A ivica je iÅ¡ao u... 23 Can we strip DATE so we could store into variable $year = 2008 and in $month = 08???? If I manage to do that, then it's done??? Quote Link to comment https://forums.phpfreaks.com/topic/119352-solved-paging-by-year-month/#findComment-614858 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 SELECT * FROM obilasci WHERE YEAR(datum) = '$year' AND MONTH(datum) = '$month' Quote Link to comment https://forums.phpfreaks.com/topic/119352-solved-paging-by-year-month/#findComment-614865 Share on other sites More sharing options...
budimir Posted August 12, 2008 Author Share Posted August 12, 2008 OK guys, Here is the code: <?PHP $year = $_GET['year']; $month = $_GET['month']; ?> <table width="938" border = "0"> <tr> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2008<?PHP if ($month) echo "&month=$month" ?> ">2008</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2009<?PHP if ($month) echo "&month=$month" ?> ">2009</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2010<?PHP if ($month) echo "&month=$month" ?> ">2010</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2011<?PHP if ($month) echo "&month=$month" ?> ">2011</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2012<?PHP if ($month) echo "&month=$month" ?> ">2012</a></td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=01">Siječanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=02">Veljača</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=03">Ožujak</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=04">Travanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=05">Svibanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=06">Lipanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=07">Srpanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=08">Kolovoz</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=09">Rujan</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=10">Listopad</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=11">Studeni</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=12">Prosinac</a></td> </tr> </table> <?PHP if ($year && $month) { $upit = "SELECT * FROM obilasci WHERE YEAR(datum) = '$year' AND MONTH(datum) = '$month'"; $rezultat = mysql_query($upit) or die (mysql_error()); while ($qry = mysql_fetch_array($rezultat)) { echo $qry["upisao"]; $b = $qry["id"]; echo "$b"; } echo "$b"; } else { echo "Please select both Year and Month"; } ?> The page is not displaying any data, whatever I click. When I copy/paste the query to phpmyadmin, everything is working fine. I can't figure out, what is wrong here??? Can you see it? Quote Link to comment https://forums.phpfreaks.com/topic/119352-solved-paging-by-year-month/#findComment-614890 Share on other sites More sharing options...
budimir Posted August 12, 2008 Author Share Posted August 12, 2008 Oh, never mind guys. I'm an idiot. So here is the complete code if somebody will need it. I works perfectly. Thanks a lot @spasme <?PHP $year = $_GET['year']; $month = $_GET['month']; ?> <table width="938" border = "0"> <tr> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2008<?PHP if ($month) echo "&month=$month" ?> ">2008</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2009<?PHP if ($month) echo "&month=$month" ?> ">2009</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2010<?PHP if ($month) echo "&month=$month" ?> ">2010</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2011<?PHP if ($month) echo "&month=$month" ?> ">2011</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2012<?PHP if ($month) echo "&month=$month" ?> ">2012</a></td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=01">Siječanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=02">Veljača</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=03">Ožujak</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=04">Travanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=05">Svibanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=06">Lipanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=07">Srpanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=08">Kolovoz</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=09">Rujan</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=10">Listopad</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=11">Studeni</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=12">Prosinac</a></td> </tr> </table> <?PHP if ($year && $month) { $upit = "SELECT * FROM obilasci WHERE YEAR(datum) = '$year' AND MONTH(datum) = '$month'"; $rezultat = mysql_query($upit) or die (mysql_error()); while ($qry = mysql_fetch_array($rezultat)) { $id = $qry["id"]; } } else { echo "Please select both Year and Month"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/119352-solved-paging-by-year-month/#findComment-614909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.