hi <br>I have a table in postgresql that it has topology and I want to display it as line in openlayers.<br>I use php to connect and convert my data to Geojson. this the codes.but I can not  get the result.who can help me.where is wrong in my codes,this is the code.<br>
<br><br><span style="color: rgb(204, 0, 0);">&lt;?php</span><br style="color: rgb(204, 0, 0);"><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   // Database connection settings</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">   define(&quot;PG_DB&quot;  , &quot;tehran&quot;);</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   define(&quot;PG_HOST&quot;, &quot;localhost&quot;); </span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">   define(&quot;PG_USER&quot;, &quot;postgres&quot;);</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   define(&quot;PG_PORT&quot;, &quot;5432&quot;); </span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">   define(&quot;TABLE&quot;, &quot;close&quot;);</span><br style="color: rgb(204, 0, 0);"><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">  </span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">?&gt;</span><br style="color: rgb(204, 0, 0);"><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">&lt;?php</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">// Connect to database</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">   $dbcon = pg_connect(&quot;dbname=&quot;.PG_DB.&quot; host=&quot;.PG_HOST.&quot; user=&quot;.PG_USER);</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   $sql = &quot;SELECT gid, ST_AsGeoJSON(the_geom) AS geojson, length(the_geom) AS length FROM &quot;.TABLE.&quot;&quot;</span><br style="color: rgb(204, 0, 0);">
<br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   // Perform database query</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   $query = pg_query($dbcon,$sql); </span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">   </span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">?&gt;</span><br style="color: rgb(204, 0, 0);"><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">&lt;?php</span><br style="color: rgb(204, 0, 0);">
<br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   // Return route as GeoJSON</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   $geojson = array(</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">      &#39;type&#39;      =&gt; &#39;FeatureCollection&#39;,</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">      &#39;features&#39;  =&gt; array()</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">   ); </span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">  </span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   // Add edges to GeoJSON array</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">   while($edge=pg_fetch_assoc($query)) {  </span><br style="color: rgb(204, 0, 0);"><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">      $feature = array(</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">         &#39;type&#39; =&gt; &#39;Feature&#39;,</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">         &#39;geometry&#39; =&gt; json_decode($edge[&#39;geojson&#39;], true),</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">         &#39;crs&#39; =&gt; array(</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">            &#39;type&#39; =&gt; &#39;EPSG&#39;,</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">            &#39;properties&#39; =&gt; array(&#39;code&#39; =&gt; &#39;4326&#39;)</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">         ),</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">         &#39;properties&#39; =&gt; array(</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">            &#39;id&#39; =&gt; $edge[&#39;id&#39;],</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">            &#39;length&#39; =&gt; $edge[&#39;length&#39;]</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">         )</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">      );</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">      </span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">      // Add feature array to feature collection array</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">      array_push($geojson[&#39;features&#39;], $feature);</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   }</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);"></span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">   // Close database connection</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   pg_close($dbcon);</span><br style="color: rgb(204, 0, 0);"><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">   // Return routing result</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   header(&#39;Content-type: application/json&#39;,true);</span><br style="color: rgb(204, 0, 0);">
<span style="color: rgb(204, 0, 0);">   echo json_encode($geojson);</span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">   </span><br style="color: rgb(204, 0, 0);"><span style="color: rgb(204, 0, 0);">?&gt;</span><br>
<br>