Hi,
I've been trying to get this code working, but it doesn't ;-) I searched for information on the get method and used the w3 validator to find the problem. The sql syntax does show the wanted value (when I fill in the variables), so I think it's in the combination of files. Since I think it's in the .js file, I post here for help.
What it should do is this:
1. after selecting an option in the dropdown, it does get the column names of the table from the dbase. so far, so good.
2. I want it to get the highest number in a certain column (fyi; the unique number in this case) , for example 9,
3. and show the number 10 as a value in the textbox.
It might/should be possible to do it all at the same time, which I also want to understand/learn, but the one after the other would be quite a learning point as well.
Any help is highly appreciated.
this is the code:
getrecordvalue.js:HTML Code:<html> <script src="gettablelist.js"></script> <script src="getrecordvalue.js"></script> <body> <form action="insert.php" method="post"> Table name: <?php include ('tabledroplist.php') ?><br> Waarde 1: <input type="text" id="row1" name="row1" value="-" onChange="showRecordValue(this.value)"><input type="text" name="value1" value="."/><br> Waarde 2: <input type="text" id="row2" name="row2" value="-" ><input type="text" name="value2" /><br> Waarde 3: <input type="text" id="row3" name="row3" value="-" ><input type="text" name="value3" /><br> Waarde 4: <input type="text" id="row4" name="row3" value="-" ><input type="text" name="value3" /><br> Waarde 5: <input type="text" id="row5" name="row3" value="-" ><input type="text" name="value3" /><br> Waarde 6: <input type="text" id="row6" name="row3" value="-" ><input type="text" name="value3" /><br> Waarde 7: <input type="text" id="row7" name="row3" value="-" ><input type="text" name="value3" /><br> Waarde 8: <input type="text" id="row8" name="row3" value="-" ><input type="text" name="value3" /><br> Waarde 9: <input type="text" id="row9" name="row3" value="-" ><input type="text" name="value3" /><br> Waarde 10: <input type="text" id="row10" name="row3" value="-" ><input type="text" name="value3" /><br> Waarde 11: <input type="text" id="row11" name="row3" value="-" ><input type="text" name="value3" /><br> <input type="submit" /> </form> </body> </html>
find_highest_value.php:Code:function showRecordValue(str) { var column = str; var table = document.getElementById('users').value; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var response = xmlhttp.responseText + 1; document.getElementByName('value1').value=response; } }; xmlhttp.open('GET', 'find_highest_value.php?column=' + str +'&table=' + table, true); xmlhttp.send(); }
PHP Code:<?php
$column=$_GET["column"];
$table=$_GET["table"];
//create connection with db
include('db_connect.php');
//build query
$query = "SELECT MAX(".$column.") AS ".$column."FROM ".$table;
$result = mysql_query($query) or die(mysql_error());
// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
echo $row;
mysql_close($con);
?>


Reply With Quote
Bookmarks