www.webdeveloper.com
Results 1 to 5 of 5

Thread: Newbie; some problem, can't find what

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    13

    Newbie; some problem, can't find what

    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:
    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>
    getrecordvalue.js:
    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();
    }
    find_highest_value.php:
    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);
    ?>

  2. #2
    Join Date
    Jan 2010
    Posts
    77
    Hi bud

    There is no function called getElementByName() in JavaScript

    There is in fact on called getElementsByName() and it returns an array which means that you would need to change the line
    Code:
    document.getElementByName('value1').value=response;
    For
    Code:
    document.getElementsByName("value1")[0].value=response;
    That is assuming that you only have one element named “value1”

    Hope this helps

    V

  3. #3
    Join Date
    Dec 2011
    Posts
    13
    Exactly what I needed. Thanks.

    Now I only have to get the second part of the array that is responded. I think I'll find that through google (though wouldn't mind a hint)

    Thanks anyway

    Arie

  4. #4
    Join Date
    Jan 2010
    Posts
    77
    Hi bud

    In your PHP your $row is an array but to get the value you need to use its index

    Code:
    echo $row[$column];

  5. #5
    Join Date
    Dec 2011
    Posts
    13
    Problem solved. Thanks so much.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles