Snooble Posted March 20, 2008 Share Posted March 20, 2008 Right this is simple but i wonder if you have another way of me doing it. i have 2 number in a database... column WIN and column LOSE i want to create another column in the database (MYSQL) that subtracts LOSE from WIN and stores it in a column called RATING. can i do this through phpmyadmin? EXAMPLE WIN = 10, LOSE = 3. WIN - LOSE = 7 RATING = 7 I want it to remain updated... is the only way i can do it by entering a php script on EVERY page of my website (as wins and losses can happen at anytime)? thanks Sam Quote Link to comment https://forums.phpfreaks.com/topic/97157-problem-i-just-cant-solve-database-values/ Share on other sites More sharing options...
jkewlo Posted March 20, 2008 Share Posted March 20, 2008 Ok then why dont u jsut have it add them together then a insert statement to insert it into the Rating. as a stored value. Quote Link to comment https://forums.phpfreaks.com/topic/97157-problem-i-just-cant-solve-database-values/#findComment-497136 Share on other sites More sharing options...
Snooble Posted March 20, 2008 Author Share Posted March 20, 2008 $rating = $list['w'] + $list['l']; $sql = "UPDATE users SET rating = '$rating' where id = '$list['id']'" would work fine but it means i must pull info from the database every page load.. can i not create a script in the database itself? like in excel when you can create formulas between cells? Thanks Sam Quote Link to comment https://forums.phpfreaks.com/topic/97157-problem-i-just-cant-solve-database-values/#findComment-497140 Share on other sites More sharing options...
cooldude832 Posted March 20, 2008 Share Posted March 20, 2008 you shouldn't need to store any simple calculated value from a database you can query for it as you need it $q = "Select Wins-Losses as Win_Loss from `ratings`"; Quote Link to comment https://forums.phpfreaks.com/topic/97157-problem-i-just-cant-solve-database-values/#findComment-497144 Share on other sites More sharing options...
Snooble Posted March 20, 2008 Author Share Posted March 20, 2008 The reason i need the value is cause i wish to use an ORDER BY query to sort my rows... any way of doing that? Thanks Sam Quote Link to comment https://forums.phpfreaks.com/topic/97157-problem-i-just-cant-solve-database-values/#findComment-497147 Share on other sites More sharing options...
jkewlo Posted March 20, 2008 Share Posted March 20, 2008 $sql=" SELECT * FROM tablename ORDER by Rating"; Quote Link to comment https://forums.phpfreaks.com/topic/97157-problem-i-just-cant-solve-database-values/#findComment-497150 Share on other sites More sharing options...
jkewlo Posted March 20, 2008 Share Posted March 20, 2008 also make a config file that loads into everypage with the include function that calls it. and yes u will have to if u want that page to be dynamic i suppose? Quote Link to comment https://forums.phpfreaks.com/topic/97157-problem-i-just-cant-solve-database-values/#findComment-497153 Share on other sites More sharing options...
Snooble Posted March 20, 2008 Author Share Posted March 20, 2008 I know how to include files and order by using sql... but you can only order by a column value... i want to know if i can create a formula between columns in the mysql database? column a minus column b = column c. yes or no? thanks Sam Quote Link to comment https://forums.phpfreaks.com/topic/97157-problem-i-just-cant-solve-database-values/#findComment-497157 Share on other sites More sharing options...
Sulman Posted March 20, 2008 Share Posted March 20, 2008 I guess you update the win/loss everytime the player finishes a game? if so then why don't you calculate the rating everytime you update the win/loss columns and insert the new rating into the rating column? That way it is truly dynamic for each user and you only have to modify the existing code. Quote Link to comment https://forums.phpfreaks.com/topic/97157-problem-i-just-cant-solve-database-values/#findComment-497158 Share on other sites More sharing options...
cooldude832 Posted March 20, 2008 Share Posted March 20, 2008 The reason i need the value is cause i wish to use an ORDER BY query to sort my rows... Order By can be done off a calculated pulled value $q = "Select Wins-Losses as Win_Loss from `ratings` Order By Win_Loss"; Quote Link to comment https://forums.phpfreaks.com/topic/97157-problem-i-just-cant-solve-database-values/#findComment-497179 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.