Variable Column names
Posted: Thu Dec 15, 2005 2:49 pm
In this code cbocnty is a selection from a previous checkbox. In my table there are 35 columns that represent years. I can't have a column year with all the variables because the table would be too large. I am trying to use $col to match to the years that the user selected and $cnty_ch in the query to represent the counties that the user selected. This is not working. How can you put variable columns into a select statement?
Burrito: Please use
Code: Select all
$cnty_ch=$_GET['cbocnty'];
$yr_ch=$_GET['cboyear'];
$col = $yr_ch;
$query="select ecnty, major, $col FROM emp_major WHERE ecnty=$cnty_ch;";
$result_set = pg_Exec ($conn, $query);
$rows = pg_NumRows($result_set);
for($i=0;$i<$rows;$i++){
echo "<TD width=200><FONT size=2>" . pg_result($result_set,$i,"major") . "</FONT></TD>";
echo "<TD width=200><FONT size=2>" . pg_result($result_set,$i,"ecnty") . "</FONT></TD>";
echo "<TD width=200><FONT size=2>" .pg_result($result_set,$i, $yr_ch) . "</Font></TD>";
}
?>Code: Select all
tags when [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting PHP Code In The Forums[/url][/size]