tebrown Posted September 18, 2012 Share Posted September 18, 2012 Hey Guys, I have setup a mysql query that is run everytime the page is refreshed. Its on my page called secure.php, which is on everypage within my website. At the moment it finds all the fixtures in the database and checks if the current time has passed its specific time. It all works fine but im wanting to get that specific fixture_id so that i can then send a notification to the manager saying that the current time has passed ur fixture time. $fixture = ("SELECT * FROM `fixtures`") or die(mysql_error()); $resultfixture=mysql_query($fixture); if (mysql_num_rows($resultfixture) != 0) { while($rows = mysql_fetch_array($resultfixture)) { mysql_query("UPDATE `fixtures` SET `status` = '2', `result`='TBA' WHERE UNIX_TIMESTAMP() > `time` AND `status`='1'") or die(mysql_error()); } } Any help much appreciated! Cheers Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/ Share on other sites More sharing options...
Barand Posted September 18, 2012 Share Posted September 18, 2012 So if you have 1000 rows in the table you want to run the same update query 1000 times? Is this a Denial Of Service attack? Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379123 Share on other sites More sharing options...
tebrown Posted September 18, 2012 Author Share Posted September 18, 2012 How could I improve this to do the same effect then? - and also the question that i had asked? Much regards, tebrown Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379135 Share on other sites More sharing options...
Barand Posted September 18, 2012 Share Posted September 18, 2012 mysql_query("UPDATE `fixtures` SET `status` = '2', `result`='TBA' WHERE UNIX_TIMESTAMP() > `time` AND `status`='1'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379136 Share on other sites More sharing options...
tebrown Posted September 18, 2012 Author Share Posted September 18, 2012 And how would i find that fixture that it actually gets if the current time passes the fixture time? Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379137 Share on other sites More sharing options...
Barand Posted September 18, 2012 Share Posted September 18, 2012 The code you posted reads every row in the table, then for every row in that table if performs the same update. You only need to perform the update once. You mention "that fixture" but give no details on what that means. What are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379139 Share on other sites More sharing options...
tebrown Posted September 18, 2012 Author Share Posted September 18, 2012 Ok so lets say that msyql query runs and it finds 1 fixture that has passed its fixture time, i want to be able to get the id of that fixture so i can then run a another mysql_query that will notify the manager to let him know the current time has passed the fixture time. Hope that makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379141 Share on other sites More sharing options...
Barand Posted September 18, 2012 Share Posted September 18, 2012 So shouldn't the SELECT query contain a WHERE clause to find the rows that meet that condition? Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379142 Share on other sites More sharing options...
tebrown Posted September 18, 2012 Author Share Posted September 18, 2012 Would that go beneath the UPDATE? Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379143 Share on other sites More sharing options...
Barand Posted September 18, 2012 Share Posted September 18, 2012 What has the update got to do with notifying anyone? Forget coding for a while. What do you want to do and what do you need to to do to achieve that? Plain English, not PHP. Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379144 Share on other sites More sharing options...
tebrown Posted September 18, 2012 Author Share Posted September 18, 2012 I need to update all fixtures where the current time has passed the fixture time. The query will then update the column 'status' to '2'. I then need to GET the fixtures that it just updated so i can run another query that will notify the managers of those fixtures. Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379146 Share on other sites More sharing options...
Barand Posted September 19, 2012 Share Posted September 19, 2012 What does this query give SHOW CREATE TABLE fixtures; Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379148 Share on other sites More sharing options...
tebrown Posted September 19, 2012 Author Share Posted September 19, 2012 CREATE TABLE `fixtures` (`id` int(11) NOT NULL ... Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379149 Share on other sites More sharing options...
Barand Posted September 19, 2012 Share Posted September 19, 2012 If you won't help me to help you then I'm gone. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379151 Share on other sites More sharing options...
tebrown Posted September 19, 2012 Author Share Posted September 19, 2012 Sorry, were you asking me to do this? <?php $test = mysql_query("SHOW CREATE TABLE fixtures") or die(mysql_error()); echo $test; ?> Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379152 Share on other sites More sharing options...
tebrown Posted September 19, 2012 Author Share Posted September 19, 2012 Found a solution. Thanks anyway! Cheers Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379157 Share on other sites More sharing options...
darkfreaks Posted September 19, 2012 Share Posted September 19, 2012 don't forget to click topic solved Quote Link to comment https://forums.phpfreaks.com/topic/268531-php-run-query/#findComment-1379160 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.