PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
shivam0101
Forum Contributor
Posts: 197 Joined: Sat Jun 09, 2007 12:09 am
Post
by shivam0101 » Fri Jul 13, 2007 6:35 am
How can i check whether any changes (update, deleted) has been made?
I have an infinite loop, inside this loop i should be able to keep on checking the database
some what like this,
Code: Select all
while(1)
{
checkdatabase
if(res)
{
}
else
{
}
}
Thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 13, 2007 6:44 am
Unless you store the previous pass, there's no way for you to compare outside of reading the log (if it's enabled.)
shivam0101
Forum Contributor
Posts: 197 Joined: Sat Jun 09, 2007 12:09 am
Post
by shivam0101 » Fri Jul 13, 2007 6:58 am
Code: Select all
while(1)
{
$num=0;
$query=mysql_query("SELECT * FROM online ORDER BY userid DESC");
$num=mysql_num_rows($query);
}
i stored in $num, how do i check the next time
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 13, 2007 7:18 am
Using an if or some other conditional would seem logical.
shivam0101
Forum Contributor
Posts: 197 Joined: Sat Jun 09, 2007 12:09 am
Post
by shivam0101 » Fri Jul 13, 2007 7:41 am
how do i compare, suppose $num=6, in the next loop it does not change and after that it changes to 8
Code: Select all
while(1)
{
$num=0;
$query=mysql_query("SELECT * FROM online ORDER BY userid DESC");
$num=mysql_num_rows($query);
if($num==)//what to compare?
{
echo 'Changed';
}
else
{
echo 'Not changed';
}
}
Gente
Forum Contributor
Posts: 252 Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:
Post
by Gente » Fri Jul 13, 2007 8:25 am
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Fri Jul 13, 2007 9:05 am
Checking the number of rows is only going to let you know about inserts and deletes, updates won't show up.
What are you trying to do anyway? I can't think of any reason you'd want a script running forever doing something when any row changes.
shivam0101
Forum Contributor
Posts: 197 Joined: Sat Jun 09, 2007 12:09 am
Post
by shivam0101 » Fri Jul 13, 2007 12:44 pm
trying to do reverse ajax
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Fri Jul 13, 2007 2:14 pm
Err. Ok. Why would you want to do this? I still see no reason for it.
ocpamit
Forum Newbie
Posts: 7 Joined: Fri Jul 13, 2007 6:53 am
Location: Punjab, India
Post
by ocpamit » Sat Jul 14, 2007 1:38 am
as Gente suggested use SHOW TABLE STATUS.
SELECT ALL TABLES FROM THE DATABASE
IN A LOOP RUN ANOTHER QUERY TO SHOW TABLE STATUS
CHECK for UPDATE_TIME
MATCH WITH CURRENT TIME
i think it should solve the problem.
shivam0101
Forum Contributor
Posts: 197 Joined: Sat Jun 09, 2007 12:09 am
Post
by shivam0101 » Sat Jul 14, 2007 5:17 am
Err. Ok. Why would you want to do this? I still see no reason for it.
I searched google, saw information of doing it. It says to create an infinite loop and inside it put the query and flush the results. If you know a better way please let me know.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jul 14, 2007 7:19 am
What's the reason behind wanting to infinitely query your database? I think it would serve better to use the logging system built into MySQL.
shivam0101
Forum Contributor
Posts: 197 Joined: Sat Jun 09, 2007 12:09 am
Post
by shivam0101 » Sat Jul 14, 2007 9:44 am
logging system means checking the database at pre-defined regular interval?
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Sat Jul 14, 2007 2:41 pm
You could just make a table to store when a table was last updated and check against that date.
smudge
Forum Contributor
Posts: 151 Joined: Sun May 20, 2007 12:13 pm
Post
by smudge » Sat Jul 14, 2007 2:56 pm
You said you were doing this for ajax. I presume that your goal is to let a client know immediately that the database has changed. Instead of running a loop infinitely, try using ajax to poll the server every 2 sec or so, and the server then checks for updates. If there is, it sends the updated results. Is that what you're looking for?