Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic SQL querys using select boxes....

Status
Not open for further replies.

BPMan

Programmer
Jun 25, 2002
163
US
ok i am trying to post a table that i get from a database. I want to be able to dynamicially update the table based on the selections from my two select boxes...
I have no idea on how to do this since i am very new to php.
The code i am using right now creates the two select boxes and the table but all it does is look nice, it is not functional....
can anyone help...
thanks



// make connection to database
$db_connection = new COM("ADODB.Connection");

$db_connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".
realpath("../ceq/CEDatabase.mdb") ." ;DefaultDir=". realpath("../ceq");
$db_connection->open($db_connstr);

// make forms to select with
echo &quot;<form method=\&quot;post\&quot; action=\&quot;index.php\&quot;><table><tr><td>Company Name</td><td>&quot;.
&quot;<SELECT NAME=\&quot;compName\&quot;>&quot;;

$rs1 = $db_connection->execute(&quot;SELECT [Company Name] FROM Presentation GROUP BY [Company Name]&quot;);
$rs1_fld0 = $rs1->Fields(0);


while (!$rs1->EOF) {
echo&quot;<OPTION VALUE=\&quot;$rs1_fld0->value\&quot;>$rs1_fld0->value&quot;;
$rs1->MoveNext();
}
echo&quot;</SELECT></td>&quot;;

echo &quot;<td>Commodity</td><td>&quot;.
&quot;<SELECT NAME=\&quot;commodity\&quot;>&quot;;

$rs2 = $db_connection->execute(&quot;SELECT [Commodity] FROM Presentation GROUP BY [Commodity]&quot;);
$rs2_fld0 = $rs2->Fields(0);

while (!$rs2->EOF) {
echo&quot;<OPTION VALUE=\&quot;$rs2_fld0->value\&quot;>$rs2_fld0->value&quot;;
$rs2->MoveNext();
}

echo&quot;</SELECT></tr></td>&quot;;
echo&quot;</table></form>&quot;;


// build table based on selections above
$rs = $db_connection->execute(&quot;SELECT * FROM Presentation&quot;);
$rs_fld0 = $rs->Fields(0);
$rs_fld1 = $rs->Fields(1);
$rs_fld2 = $rs->Fields(2);
$rs_fld3 = $rs->Fields(3);
$rs_fld4 = $rs->Fields(4);
$rs_fld5 = $rs->Fields(5);
echo &quot;<table border=1><tr><th>ID</th><th>Company Name</th>&quot;.
&quot;<th>Description</th><th>Date Recieved</th><th>Commodity</th><th>Location</th></tr>\n&quot;;

while (!$rs->EOF) {
echo &quot;<tr><td>$rs_fld0->value</td><td>$rs_fld1->value</td>&quot;.
&quot;<td>$rs_fld2->value</td><td>$rs_fld3->value</td><td>$rs_fld4->value</td><td>$rs_fld5->value</td></tr>\n&quot;;

$rs->MoveNext(); /* updates fields! */
}
echo &quot;<tr><td colspan=2> </td></tr></table>&quot;;
$rs->Close();
$db_connection->Close();
echo&quot;</div>&quot;;

?>
 
i dont see why u must update the database here, maybe u r speaking bout displaying the table according to the compnay and commodity?
 
the table is displayed and i want to update the table that is being displayed based on the selection that is made....
so essentilly i have the SQL statement...
SELECT * FROM Presentation
and then the user makes a selection from the combo box commodity and then we get
SELECT * FROM Presentation WHERE Presentation.Commodity = &quot;Wheels&quot;
so i want to reformulate the SQL statement based on the user's selection then redisplay the table...
thanks
 
i still dont get it,
i can understand utpto display of the table but after that what do u mean by updating? in ur code i do not see any text boxes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top