views:

19

answers:

1

im trying to get a post from a php file when it has something from the database.

this is the js script that sends the post request (im using jquery and the smartupdater plugin)

function update(){

$(document).ready(function(){

$("#myp").smartupdater({

url:"listen.php",

type: POST

minTimeout:2000
},function(data){

$("#myp").before(data);

};

});
return false;
};

and my php file:

<?php
include_once("connect.php");

$date=date();

while($date=>$ddate)
{

usleap(10000);
clearstatcache();

$search=mysql_query("SELECT * FROM chat ORDER BY date DESC LIMIT 1");

$row=mysql_fetch_assoc($search);

$ddate=$row['date'];

}


echo $row['message'] . "<br/>";



?>

i dont know whats wrong, am i doing the whole thing wrong?

+1  A: 

Yes, there is not SORT BY, it is ORDER BY

$search = mysql_query("SELECT * FROM chat ORDER BY date DESC LIMIT 1");

You are also missing mysql_fetch_assoc to get variable like $search['date'];

Here is how it should be:

$search = mysql_query("SELECT * FROM chat ORDER BY date DESC LIMIT 1") or die(mysql_error());

$row = mysql_fetch_assoc($search);
echo $row['date'];
Sarfraz
thanks i cahnged it but it still doesnt work.
Petre
@Petre: See my updated answer please.
Sarfraz
yes, i forgot about that too, but it still doesnt ever give a response, i dont know if i did the while loop correctly.
Petre
@Petre: Try removing the while loop and then see because you are getting only one record anyway with `limit 1`
Sarfraz
i removed the while loop but i still dont get a response.in my head section i have 2 scripts, one sends the data to the server and works fine, and the one i posted here for the update, but if i dont but them inside separate script tags, the browser makes a GET request and i can see the input in the adress bar.is this how i should do it? spearate them with script tags or is this a problem too and they should be ok in the same script tag?
Petre