I have tried to use this code but I can get it to work well in my server. When I run the mysql query in mysql it gives me the result that I want but within the code it does not output anything. It just gives a blank page. What can be wrong please.
<?php
if(isset($_GET[‘page2’]))
{
include ‘dbconnect.inc’;
$year = $_GET[‘page2’];
$query = “select distinct MONTH(publicationdate) from agricultural_research_journal where year(publicationdate) = ‘$year’ order by id asc”;
$result = mysql_query($query) or die(‘Error, query failed’);
$num_result = mysql_num_rows($result);
Step 2: Ignoring for the moment that your query is a security risk waiting to happen (always clean up user input. If you’re expecting an integer, do an is_int check), I have trouble following the logic for retrieving your results. Let’s try simplifying that first.
$query = "select distinct MONTH(publicationdate) AS themonth FROM agricultural_research_journal WHERE YEAR(publicationdate) = '$year' order by id asc";
$result = mysql_query($query) or die('Error, query failed');
while($story = mysql_fetch_assoc($result)) {
print '<table width = "385" border="1" align = "center">';
print '<tr>';
print '<td>';echo '$num_result';
echo "<a href=month.php?month=".$story['themonth'].">".$story['themonth']."</a>";
print '</td>';
print '</tr>';
print '</table>';
}
Thanks I have checked the codes again. I got the codes wrong from the variable aspect. I called $_Get [‘page2’] instead of calling for $_Get[‘year’] which is what I expected from the page I am getting the variable from. Thanks for your suggestions.
Learn from this, and like DaveMaxwell intimates get used to using some debug as you work along.
If you have a script which is going to be dependent upon incoming variables such as GET or POST then get used to echoing them out onto the page at the top of your script.
<?php
// comment this out or remove it when you have affirmed that the incoming
// vars actually meet your expectation
var_dump($_GET);
echo '<hr />';
Do the same for $_POST too …
Get into the swing of having PHP prove to you that what you think should be happening matches what PHP is doing.