Yeah, it's actually pretty easy.
just have an if statement that looks for the variable.
if( !isset($my_var) )
{ echo("You have accessed this page incorrectly, crack head!"); }
else
{
$result = mysql_query("SELECT * FROM table_name WHERE table_id='$my_var'");
$row = mysql_fetch_assoc($result);