I'm working on a tool that describes the tables in a database through a web interface. I have a drop down where the user selects a version of the database. That selection populates a form select with the columns from the table. The problem is, when I select a column from that list, which pulls appropriately through Ajax, the results of the select are run against my default database from my else statement, rather than the database selected by the user. I have a breakdown somewhere when I try to send the db version to search.php
My jQuery:
$(document).on("click", '.version', function() {
var myVersion = $(this).attr('id');
//$.post('conn.php', {'myVersion': myVersion});
$('#select').load('selectdb.php', {'myVersion': myVersion});
$.post('search.php', {'dbVersion': myVersion});
});
$(document).on('click', '#search', function() {
var formData = $('#schemaSearch').serializeArray();
$('#searchResults').load('search.php', formData);
});
selectdb.php:
<?php
include('conn.php');
if ($myVersion == '9.93') {
$dbVersion = 'goals';
} else {
$dbVersion = 'jamfsoftware';
}
$columnOnly = mysql_query("select distinct(column_name) from information_schema.columns where table_schema='" . $dbVersion . "' order by column_name");
$result = mysql_query("select table_name, column_name from information_schema.columns where table_schema='" . $dbVersion . "' order by column_name");
echo '<option></option>';
while($row = mysql_fetch_array($columnOnly)) {
echo "<option value=" . $row['column_name'] . ">" . $row['column_name'] . "</option>";
}
?>
search.php:
<?php
include('conn.php');
include('selectdb.php');
$lookingFor = $_POST['select'];
if (isset($_POST['dbVersion'])) {
$dbVersion = $_POST['dbVersion'];
} else {
$dbVersion = 'jamfsoftware';
}
$lookingForQuery = mysql_query("select table_name, column_name from information_schema.columns where table_schema='" . $dbVersion . "' and column_name like '" . $lookingFor . "'");
echo $dbVersion;
?>