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);

//to pick the dates
for ($i=0; $i <$num_result; $i++)
{
$story = mysql_fetch_assoc($result);
print '<table width = "385" border="1" align = "center">';
print '<tr>';
print '<td>';echo '$num_result';
$my_date = mysql_result($result, $i);
echo "<a href=month.php?month=$my_date>$my_date</a>";
print '</td>';
print '</tr>';
print '</table>';
}
}
?> 

Recommended Answers

All 3 Replies

When you display $num_result to the page, what's the value?

echo var_dump($num_result), '<br />';

Hy,
Try with the $year as number in sql query, without quotes:

$query = "select distinct MONTH(publicationdate) from agricultural_research_journal where year(publicationdate) = $year order by id asc";

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.