php undefined variable in option value
<p>i'm sorry for asking this question because i think it has a really simple answer, but i really don't know php at all. I want to install bandwidthd for network monitoring, and i wanted the option which lets you run the bandwidthd daemon on the gateway and all the info is exported to a postgres database on another machine. Also on that machine, the one with the database i've set up an apache server for displaying the webapp of bandwidthd. The web up is a bunch of php files which don't seem to work at all so i'm just spending my time corecting them. I've been able to get a few of the right but now i'm stuck. I have the following code:</p>

<pre><code>&lt;td&gt;&lt;SELECT name="sensor_name"&gt;

&lt;OPTION value="none"&gt;--Select A Sensor--
&lt;?php
$dbh = pg_pconnect("host=localhost dbname=BandwidthD user=postgres");
$sql = "SELECT sensor_name from sensors order by sensor_name;";
$result = pg_query($dbh, $sql);
while ($r = pg_fetch_array($result))
    echo "&lt;option value=\"".$r[0]."\" ".($sensor_name==$r[0]?"SELECTED":"")."&gt;".$r[0]."\n";
?&gt;
</code></pre>

<p>And when the page executes it is saying that sensor_name is undefined, but from what i see, it looks to me that the variable should be initialized there right at that line. If you have any suggestions please let me know but bear in mind that i don't know any php, i'm just venturing guesses because it's a programming language and it's supposed to be logical. </p>

<p>I was thinking that $sensor_name would be initialized in that peace of code because i also have this code:</p>

<pre><code> &lt;td&gt;&lt;SELECT name="limit"&gt;
 &lt;OPTION value="none"&gt;--How Many Results--
 &lt;OPTION value=20 &lt;?php=$limit==20?"SELECTED":""?&gt;&gt;20
 &lt;OPTION value=50 &lt;?php=$limit==50?"SELECTED":""?&gt;&gt;50
 &lt;OPTION value=100 &lt;?php=$limit==100?"SELECTED":""?&gt;&gt;100
 &lt;OPTION value=all &lt;?php=$limit=="all"?"SELECTED":""?&gt;&gt;All
 &lt;/select&gt;
</code></pre>

<p>and limit is not declared anywhere else and doesn't give an error. </p>
