Hello all,
Correct me if I mis-post or should have posted this somewhere else. This is my first thread here so bear with me. I have had a lot of luck just browsing other issues to get my problems solved in the past, but this time I am stumped. More so for my lack of knowledge than anything.
I built an SQL db, and a few php pages to interact with that database. You can create a new record, edit an existing record, or delete a record from various php pages. I can provide code for the new, edit, and delete php pages if required.
My main view page code is as follows.
<html>
<head>
<title>View Licenses</title>
</head>
<body>
<?php
/*
VIEW.PHP
Displays all data from 'sw_lic' table
*/
// connect to the database
include('connect-db.php');
// get results from database
$result = mysql_query("SELECT * FROM sw_lic ORDER by dept, username")
or die(mysql_error());
// display data in table
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>Username</th> <th>System Name</th> <th>Dept.</th> <th>Software Name</th> <th>Software Ver.</th> <th>LIC Key</th> <th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['username'] . '</td>';
echo '<td>' . $row['sysname'] . '</td>';
echo '<td>' . $row['dept'] . '</td>';
echo '<td>' . $row['sw_name'] . '</td>';
echo '<td>' . $row['sw_ver'] . '</td>';
echo '<td>' . $row['sw_key'] . '</td>';
echo '<td><a href="edit.php?sw_id=' . $row['sw_id'] . '">Edit</a></td>';
echo '<td><a href="delete.php?sw_id=' . $row['sw_id'] . '">Delete</a></td>';
echo "</tr>";
}
echo "</table>";
?>
</body>
<p><INPUT TYPE="BUTTON" VALUE="Add New Record"onClick="location.href='new.php'"></p>
<p><input TYPE="button" VALUE="Print" onClick="window.open('NB_sw_lic/view.php')"></p>
</html>
Next I have built a <select> field to populate based on the dept field values in the db, and then group by them to slim down the <options> shown...(code for that)
<?php
$sql = "SELECT dept, sw_id FROM sw_lic GROUP by dept";
$result = mysql_query($sql);
echo "<select name='dept_filter' id='dept_filter' onchange='this.form.submit()'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['dept'] . "'>" . $row['dept'] . "</option>";
}
echo "</select>";
?>
<p><INPUT TYPE="BUTTON" VALUE="Filter" onClick="SELECT * FROM sw_lic WHERE dept = $_POST['dept_filter']"></p>
I want to place the previous code at the end of the document. I can place the code with no issues at all, but it just doesn't fuction. I am a complete novice at coding and most of this code was used from other forums and open source coding sites.
I want to be able to select my option from the <select> field, and then have it run a SELECT command on the db, then take the results to a new page called view.php. Can anyone elaborate on what I might search for in order to accomplish my goal, or maybe give me some coding examples as to how I could accomplish this?
Thanks so much in advance!!