evolvea
12 May 2011, 03:21 AM
Hi so im in need of help in getting this query and update working with ajax so that there isnt a page refresh. Here is the code.
This is the page, it is being included in various other pages.
<head>
<script type="text/javascript" src="../scripts/ajax_functions.js"></script>
</head>
<script type="text/javascript">
var myReq = getXMLHTTPRequest();
</script>
<?php
include "connect.php";
include "feedback.php";
?>
<div class="sidebar">
<div class="clientwrapper">
<h2>Client Feedback</h2>
<div class="box">
<?php
while($row=mysqli_fetch_array($result)){
echo '<p> '.$row["Comments"].' <span class="name"> By '.$row["Organisation"].' </span></p>';
}
?>
<?php if ($feedback < $num_rows) echo '<a class="nodecoration" href=" '.$_SERVER['PHP_SELF'].'?feedback='.($feedback+4).'" ><span class="next-button">More</span></a>' ?>
<?php if ($prev >= 0) echo '<a class="nodecoration" href=" '.$_SERVER['PHP_SELF'].'?feedback='.$prev.'" ><span class="prev-button">Prev</span></a>' ?>
<div class="clear"></div>
</div>
</div>
This is to determine if the httprequest is possible and for which browser.
function getXMLHTTPRequest() {
var req = false;
try {
/*for firefox*/
req = new XMLHTTPRequest();
} catch (err) {
try {
/* for some versions of IE*/
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (err) {
try {
/*for some other version os IE*/
req= newActiveXObject("Microsoft.XMLHTTP");
} catch (err) {
req = false;
}
}
}
return req;
}
connect.php connect to my database, i use procedural coding not oo.
This is the query, the output is in the first code block.
<?php
//check if the starting row variable was passed in the URL or not
if (!isset($_GET['feedback']) or !is_numeric($_GET['feedback'])) {
//we give the value of the starting row to 0 because nothing was found in URL
$feedback = 0;
//otherwise we take the value from the URL
} else {
$feedback = (int)$_GET['feedback'];
}
$prev = $feedback - 4;
$query = "SELECT * FROM clients, orders WHERE clients.ID = orders.ID ORDER BY Date DESC LIMIT $feedback,4";
$result = mysqli_query($link,$query);
$num_rows = mysqli_num_rows($result);
?>
now how do i use ajax to stop page refresh and instead update automatically on button press. i understand i have to use onclick to call a function but i dont know what to include in the function and how to incremement the feedback variable based on whether the more or prev button is pressed.
Thanks to anyone that can help.
This is the page, it is being included in various other pages.
<head>
<script type="text/javascript" src="../scripts/ajax_functions.js"></script>
</head>
<script type="text/javascript">
var myReq = getXMLHTTPRequest();
</script>
<?php
include "connect.php";
include "feedback.php";
?>
<div class="sidebar">
<div class="clientwrapper">
<h2>Client Feedback</h2>
<div class="box">
<?php
while($row=mysqli_fetch_array($result)){
echo '<p> '.$row["Comments"].' <span class="name"> By '.$row["Organisation"].' </span></p>';
}
?>
<?php if ($feedback < $num_rows) echo '<a class="nodecoration" href=" '.$_SERVER['PHP_SELF'].'?feedback='.($feedback+4).'" ><span class="next-button">More</span></a>' ?>
<?php if ($prev >= 0) echo '<a class="nodecoration" href=" '.$_SERVER['PHP_SELF'].'?feedback='.$prev.'" ><span class="prev-button">Prev</span></a>' ?>
<div class="clear"></div>
</div>
</div>
This is to determine if the httprequest is possible and for which browser.
function getXMLHTTPRequest() {
var req = false;
try {
/*for firefox*/
req = new XMLHTTPRequest();
} catch (err) {
try {
/* for some versions of IE*/
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (err) {
try {
/*for some other version os IE*/
req= newActiveXObject("Microsoft.XMLHTTP");
} catch (err) {
req = false;
}
}
}
return req;
}
connect.php connect to my database, i use procedural coding not oo.
This is the query, the output is in the first code block.
<?php
//check if the starting row variable was passed in the URL or not
if (!isset($_GET['feedback']) or !is_numeric($_GET['feedback'])) {
//we give the value of the starting row to 0 because nothing was found in URL
$feedback = 0;
//otherwise we take the value from the URL
} else {
$feedback = (int)$_GET['feedback'];
}
$prev = $feedback - 4;
$query = "SELECT * FROM clients, orders WHERE clients.ID = orders.ID ORDER BY Date DESC LIMIT $feedback,4";
$result = mysqli_query($link,$query);
$num_rows = mysqli_num_rows($result);
?>
now how do i use ajax to stop page refresh and instead update automatically on button press. i understand i have to use onclick to call a function but i dont know what to include in the function and how to incremement the feedback variable based on whether the more or prev button is pressed.
Thanks to anyone that can help.