This is a code in PHP which is fetching a record from a database:
<?php
include("dbconn.inc");
$data = mysql_query(
"SELECT `subtitle`, `mian-title`, `page_num`, `note_path`, `flash_path`
FROM `main-page`
WHERE `page_num` =".$r." LIMIT 1";
echo $data;
if (mysql_num_rows($data) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
while ($row = mysql_fetch_assoc($data)) {
echo $row['page_num'];
}
include("close.php");
?>
And this is the HTML:
<form method="post" action="data.php">
<input name="Button1" type="submit" value="<<" />
<input name="test" style="width: 31px; height: 23px" type="text" /> // this is a value of page_num in DB.
<input name="Button2" type="submit" value=">>" >
</form>
I want to add Ajax code to retrieve the record from PHP code, and then change the input values depends on returned data and also want to preventing the page from refreshing!
You have to use jQuery to call the function, and push the information into the
div, pushing the old information out. (If this is what you mean. Otherwise, you just put it into anotherdiv). This would be something like this:This should do the trick. If it doesn’t, you can always add a
$.ajaxinstead of$.get.I’m not entirely sure this code will work 100%. You might have to change one or two things. But the idea should be right.
(I’m not sure if you’ve noticed, but you’ve typed “mian-title”. It might be a typo.)