Trouble with function in PHP not being recognized
<p>I have a few simple php scripts that I am writing for a website and I am having an issue that I can't figure out the cause of.</p>

<p>Error:  </p>

<pre><code>Notice: Undefined variable: votePosts in C:\wamp\www\fec\displaytable.php on line 23
</code></pre>

<p>which I imagine is the reason this also happens:</p>

<pre><code>Warning: Invalid argument supplied for foreach() in C:\wamp\www\fec\displaytable.php on line 2
</code></pre>

<p>This is the code of the index page:</p>

<pre><code>&lt;html&gt;
&lt;?php
include ("includes.php");
include ("displaytable.php");
$votePosts = GetVotePosts();
?&gt;
&lt;/html&gt;
</code></pre>

<p>This is the GetVotePosts function which is in the includes file</p>

<pre><code>function GetVotePosts($inId=null)
{
if(isset($_POST['sort'])) 
{
    $sort = $_POST['sort'];
}
else 
{
    $sort = "district ASC";
}
$query = mysql_query("SELECT reports.comm_name, reports.fec_id, reports.form_type, reports.file_id, reports.id,  reports.line101,  reports.line81,  reports.line22, reports.line16,  reports.line15,  reports.line13a,  reports.line11c,  reports.line11aiii, campaigns.incumbency, campaigns.party, campaigns.candidate, campaigns.district FROM  reports,campaigns WHERE reports.fec_id = campaigns.fecid ORDER BY " . $sort);
$postArray = array();
while ($row = mysql_fetch_assoc($query))
{
    $myPost = new VotePost($row['comm_name'], $row['fec_id'], $row['form_type'], $row['file_id'], $row['id'], $row['line101'], $row['line81'], $row['line22'], $row['line16'], $row['line15'], $row['line13a'], $row['line11c'], $row['line11aiii'], $row['incumbency'], $row['party'], $row['candidate'], $row['district']); 
        array_push($postArray, $myPost);
}
return $postArray;
}
</code></pre>

<p>this is line23 that is the source of the error:</p>

<pre><code>foreach ($votePosts as $post)
</code></pre>

<p>Any idea what is causing this problem.</p>
