Hi guys,

I have a table that outputs all my contacts via a while loop from my database.

my syntax is like this:

SELECT * FROM contacts WHERE id = $_SESSION['user_id'] ORDER BY name ASC LIMIT 5

that pulls out all my data and only gives me 5 results.

Now my goal is to have a little button that opens up a model box with jquery (this I can manage on my own) with a form asking the user to input a number then that number will be sent via post or get to $PHP_SELF and update a local variable with the number the user inputed, then that variable will be used to update the database to increase or decrease the LIMIT value.

I have looked all over the web (with google) to look for submitting a form using AJAX but all the examples i've found don't work for me.

When the user submits the number and the sql query is executed and updated for the outputed table to dynamically update according to the new LIMIT value all without ever refreshing the page to the user.

my jquery code is:

				$("form#form").submit(function() {
					// we want to store the values from the form input box, then send via ajax below
					var val = $('input[name=new_value]').attr('value');
						type: "post",
						url: "process.php",
						data: "val="+ val,
						cache: false,
						success: function(){
				return false;

then my php code is:

$new_val = $_POST['new_val'];

$_val  = "UPDATE `settings` SET `display_limit` = {$new_val} WHERE `user_id` = {$_SESSION['user_id']}";
mysql_query($_val) or die(mysql_error());

and my form is simple:

<form id="form">
							<input type="text" id="new_val" name="new_val" class="text" />
							<input type="submit" name="limit" id="submit" />

any suggestions? I haven't come to how to have my outputed table dynamically update yet so if anyone can point me in the right direction or provide some help that would be awesome.


Edited by s2xi: n/a

7 Years
Discussion Span
Last Post by s2xi

For one, your PHP code does not return anything. You should construct an array of all your results and echo them with json_encode() or just output HTML.

Second. Your success function does not contain a data parameter. You can use this to access the returned json or html and output them.


Hi, ok i fixed alot in the mean time

this is my PHP code:

$json = array('rows' => array());

	while ($row = mysql_fetch_assoc($last_five_listings)) {
		$json['rows'][] = $row;

	echo json_encode($json);

and this is my new jquery:

					var val = $("input[name=recent_val-seller]").val();
					$.getJSON("process.php?val=" + val, function(data){
							$("#last_five_sellers").append('<tr><td>' + this.column_a + '</td><td>' + this.column_b + '</td></tr>');
					return false;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.