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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP view only selected records using OBDC with Access DB

Status
Not open for further replies.

bigcat48

Programmer
Aug 27, 2008
72
0
0
US
All - Usually I use mysql databases, but i'm doing a special assignment in which i have to use an Access database using an odbc connection.

My Goal:
-have a select menu with options populated from the database
-when an option is selected, view only selected records
-have all of this on one page

This is what I have so far.
Select Menu (php include that is not included yet)
Code:
<p><form action="trainsymbols.php" method="post" id="selectForm">		
		<label>By LSize:</label>
			<select name="id" multiple="multiple" id="multipleSelect">
				<option selected value="">Any LSize</option>
				<?php
				$conn=odbc_connect('crewforecast20080804','','');
				if (!$conn)
				  {exit("Connection Failed: " . $conn);}
				  
				//call data to be viewed
				$sql = "SELECT * FROM tbl4combo_symbols ORDER BY LSize ASC";
				$rs = odbc_exec($conn, $sql);
				if (!$rs)
				  {exit("Error in SQL");}
				while (odbc_fetch_row($rs)) 
				{
				  $id = odbc_result($rs,"ID");
				  $LSize = odbc_result($rs,"LSize");
				  echo "<option value='$id'>$LSize</option>\n"; 
				}
				odbc_close($conn);	
				?>
			</select><br />
		<p><input type="submit" id="submitbutton130" class="button positive" value="Search" /></p>
	</form></p>

Display page
Code:
<table id="SortTable" class="tablesorter">
			<thead>
				<tr>
					<!--<th class="w70">ID</th>-->
					<th class="w325">4combo</th>
					<th class="w70">LSymbol</th>
					<th class="w70">ESymbol</th>
					<th class="w70">LSize</th>
					<th class="w70">ESize</th>
					<th class="w70" colspan="2">Action</th>
				</tr>
			<tbody>
<?php
		// create database connection
		$conn=odbc_connect('crewforecast20080804','','');
		if (!$conn)
		  {exit("Connection Failed: " . $conn);}
		
		// call data to be viewed
		$sql="SELECT * FROM tbl4combo_symbols ORDER BY '4combo' ASC";
		
		// submit the query
		$rs=odbc_exec($conn,$sql);
		// if query is invalid do this 
		if (!$rs)
		  {exit("Error in SQL");}
		// if query is valid do this 
		while (odbc_fetch_row($rs))
		{
		  $id=odbc_result($rs,"ID");
		  $fcombo=odbc_result($rs,"4combo");
		  $lsym=odbc_result($rs,"LSymbol");
		  $esym=odbc_result($rs,"ESymbol");
		  $lsize=odbc_result($rs,"LSize");
		  $esize=odbc_result($rs,"ESize");
		  //echo "<tr><td>$id</td>";
		  echo "<td>$fcombo</td>";
		  echo "<td>$lsym</td>";
		  echo "<td>$esym</td>";
		  echo "<td>$lsize</td>";
		  echo "<td>$esize</td>";
		  echo "<td class=\"center\"><a href=\"update_trnsym.php?id=$id\"><img src=\"images/edit-page-blue.gif\" title=\"Edit\" /></a></td>";
		  echo "<td class=\"center\"><a href=\"delete_trnsym.php?id=$id\"><img src=\"images/delete.png\" title=\"Delete\" /></a></td></tr>";
		}
		odbc_close($conn);
		?>

A select page not connecting to the display page.

I assume this would work if I had two things:
1. <?php echo $_SERVER['PHP_SELF']; ?>
2. A Loop


Thanks in advance.
BC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top