I have a page where I am using a parameter in the URL as a filter for my SQL query. I created a variable from the URL parameter:
$station = htmlspecialchars($_GET["station"]);
Then set up a conditional query depending on whether or not the URL parameter is set:
if(isset($_GET['station'])) {
$query = "SELECT * FROM song_of_the_day WHERE station = '$station'";
}
else {
$query = "SELECT * FROM song_of_the_day WHERE end_date >= CURDATE()";
}
$result = mysql_query($query) or die(mysql_error());
$num_rows = mysql_fetch_row($result);
Then I display the results in a table:
echo "<table width='758' border='0' cellpadding='10' cellspacing='0' class='myTable'>";
while($row = mysql_fetch_array( $result )) {
echo '<tr>';
echo '<td align="left" width="48">' . $row['station'] . '</td>';
echo '<td align="left">' . date('M j, Y',strtotime($row['end_date'])) . '</td>';
echo '<td width="24" align="left"><a href="edit.php?id=' . $row['id'] . '"><img src="http://yourligas.yourli.com/ad-inventory/edit.png" border="0"></a></td>';
echo '<td width="24" align="left"><a href="delete.php?id=' . $row['id'] . '" data-confirm="Are you sure you want to delete this entry?" ><img src="http://yourligas.yourli.com/ad-inventory/remove.png" border="0"></a></td>';
echo "</tr>";
echo '</tbody>';
}
echo "</table>";
The query works find when the ELSE command uses the query, where I'm not relying on the parameter in my SQL, but the problem I am seeing when the URL parameter ISSET is only one row gets displayed from the query when there is more than one row that matches the criteria in the actual database. Does anybody know why this is happening?
Thank you