cheechm Posted June 2, 2007 Share Posted June 2, 2007 Hi, Is there a way to change a Mysql database so the if the "result" column= win and a link is clicked to change it it automatically changes to lose without the user have to type anything/click anything. (Also vice versa) Thanks (I hope you understand what I am trying to do, it is quite hard to explain.) Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/ Share on other sites More sharing options...
chocopi Posted June 2, 2007 Share Posted June 2, 2007 so are you saying that you want a link like this: [iurl=#]Change to Win[/iurl] [iurl=#]Change to Lose[/iurl] Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267020 Share on other sites More sharing options...
shocker-z Posted June 2, 2007 Share Posted June 2, 2007 why use seperate databases? i mean you could just check the result of your query.. $result=mysql_query("SELECT result from table where userid = '$ID'"); $row=mysql_fetch_array($result); if ($row['result'] == 'win') { mysql_select_db('win', $link) or die("Select DB Error: ".mysql_error()); } else { mysql_select_db('lose' , $link) or die("Select DB Error: ".mysql_error()); } but i cant see the need to do this?? why not just use tables? Liam Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267021 Share on other sites More sharing options...
cheechm Posted June 2, 2007 Author Share Posted June 2, 2007 Example of what I am trying to do: One database called "data" Inside data is a table called "results" Inside results are the columns "eventname, yeargroup, team, result" I have a php file with the following code inside: <?php $con = mysql_connect(""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("data", $con); $result = mysql_query("SELECT * FROM results"); while($row = mysql_fetch_array($result)) { $link = 'addevent.php?eventname=' . $row['EventName'] . '&result=' . $row['Result']; $link2 = 'confirmdeleter.php?eventname=' . $row['EventName'] . '&Result=' . $row['Result']; echo $row['EventName'] . " " . $row['Year'] ." / ". $row['Team'] . " / " . $row['Result'] ; echo " "; echo " / "; echo "<a href='".$link."'> +change result </a>"; echo "/"; echo "<a href='".$link2."'> -delete </a>"; echo "/"; echo "<br />"; } mysql_close($con) ?> What I want to hapen is when "$link" is clicked, for the data in the column called "result" to change to win when the result entered is lose, and change to lose when the result entered is win. I hope that is clearer. Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267028 Share on other sites More sharing options...
iLLeLogicaL Posted June 2, 2007 Share Posted June 2, 2007 <?php if(isset($_GET['change'])) { switch($_GET['change']) { case "lose": mysql_query("UPDATE some_table SET result='lose' WHERE result='win'") or die(mysql_error()); // You don't even need the "WHERE result='win' if you just want to change all entries break; case "win": mysql_query("UPDATE some_table SET result='win' WHERE result='lose'") or die(mysql_error()); // Same comment as above break; default: // Do nothing break; } } else { // Do nothing? } ?> UNTESTED Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267032 Share on other sites More sharing options...
cheechm Posted June 2, 2007 Author Share Posted June 2, 2007 I have put it in like this <?php $eventname = $_GET['eventname']; $result = $_GET['result']; $con = mysql_connect(); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("b7_463487_LPS", $con); if(isset($_GET['result'])) { switch($_GET['result']) { case "loss": mysql_query("UPDATE results SET Result='loss' WHERE EventName='$eventname' Result='win'") or die(mysql_error()); // You don't even need the "WHERE Result='win' if you just want to change all entries break; case "win": mysql_query("UPDATE result SET Result='win' WHERE EventName='$eventname' Result='loss'") or die(mysql_error()); // Same comment as above break; default: // Do nothing break; } } else { // Do nothing? } echo "$eventname is now filed as a $result"; ?> however, it never changes whether is it a win or a loss. It just say it is a win. (Because it is initally filed as a win.) Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267042 Share on other sites More sharing options...
chocopi Posted June 2, 2007 Share Posted June 2, 2007 in your queries dont you need && mysql_query("UPDATE results SET Result='loss' WHERE EventName='$eventname' && Result='win'") or die(mysql_error()); I am probably wrong, but just thought i would mention it Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267047 Share on other sites More sharing options...
iLLeLogicaL Posted June 2, 2007 Share Posted June 2, 2007 IT does change, If it was a win and you set the result as 'lose' then it will change the result to lose & vice versa But you made a simple mistake AND a very big one <?php $eventname = $_GET['eventname']; $result = $_GET['result']; // Want to have your database hacked? // Then you should surely post your login information here (CENSORED NOW) $con = mysql_connect($host,$user,$password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); if(isset($_GET['result'])) { switch($_GET['result']) { case "loss": mysql_query("UPDATE results SET Result='loss' WHERE EventName='$eventname' && Result='win'") or die(mysql_error()); // You don't even need the "WHERE Result='win' if you just want to change all entries // You can select multiple where's but use bools break; case "win": mysql_query("UPDATE result SET Result='win' WHERE EventName='$eventname' && Result='loss'") or die(mysql_error()); // Same comment as above break; default: // Do nothing break; } } else { // Do nothing? } echo "$eventname is now filed as a $result"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267050 Share on other sites More sharing options...
cheechm Posted June 2, 2007 Author Share Posted June 2, 2007 I can't seem to make that work. It still ouputs what is orgianally selected in the database. Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267094 Share on other sites More sharing options...
chocopi Posted June 2, 2007 Share Posted June 2, 2007 is the tablename 'result' or 'results' as the code that iLLeLogicaL uses both in the sql code So it would be this: <?php $eventname = $_GET['eventname']; $result = $_GET['result']; // Want to have your database hacked? // Then you should surely post your login information here (CENSORED NOW) $con = mysql_connect($host,$user,$password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); if(isset($_GET['result'])) { switch($_GET['result']) { case "loss": mysql_query("UPDATE results SET Result='loss' WHERE EventName='$eventname' && Result='win'") or die(mysql_error()); // You don't even need the "WHERE Result='win' if you just want to change all entries // You can select multiple where's but use bools break; case "win": mysql_query("UPDATE results SET Result='win' WHERE EventName='$eventname' && Result='loss'") or die(mysql_error()); // Same comment as above break; default: // Do nothing break; } } else { // Do nothing? } echo "$eventname is now filed as a $result"; ?> or <?php $eventname = $_GET['eventname']; $result = $_GET['result']; // Want to have your database hacked? // Then you should surely post your login information here (CENSORED NOW) $con = mysql_connect($host,$user,$password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); if(isset($_GET['result'])) { switch($_GET['result']) { case "loss": mysql_query("UPDATE result SET Result='loss' WHERE EventName='$eventname' && Result='win'") or die(mysql_error()); // You don't even need the "WHERE Result='win' if you just want to change all entries // You can select multiple where's but use bools break; case "win": mysql_query("UPDATE result SET Result='win' WHERE EventName='$eventname' && Result='loss'") or die(mysql_error()); // Same comment as above break; default: // Do nothing break; } } else { // Do nothing? } echo "$eventname is now filed as a $result"; ?> Hope that helps, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267108 Share on other sites More sharing options...
cheechm Posted June 2, 2007 Author Share Posted June 2, 2007 Table name is Results. The is a column called result Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267122 Share on other sites More sharing options...
chocopi Posted June 2, 2007 Share Posted June 2, 2007 ok try this: <?php $eventname = $_GET['eventname']; $result = $_GET['result']; // Want to have your database hacked? // Then you should surely post your login information here (CENSORED NOW) $con = mysql_connect($host,$user,$password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); if(isset($_GET['result'])) { switch($_GET['result']) { case "loss": mysql_query("UPDATE Results SET result='loss' WHERE EventName='$eventname' && Result='win'") or die(mysql_error()); // You don't even need the "WHERE Result='win' if you just want to change all entries // You can select multiple where's but use bools break; case "win": mysql_query("UPDATE Results SET result='win' WHERE EventName='$eventname' && Result='loss'") or die(mysql_error()); // Same comment as above break; default: // Do nothing break; } } else { // Do nothing? } echo "$eventname is now filed as a $result"; ?> Hope it helps, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267124 Share on other sites More sharing options...
iLLeLogicaL Posted June 3, 2007 Share Posted June 3, 2007 And you might want to set the mysql connections back to the original, then you should have no problem at all Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267381 Share on other sites More sharing options...
cheechm Posted June 3, 2007 Author Share Posted June 3, 2007 Thanks for all the help so far, but that doesn't seem to solve it. It is still ouputting what is orgianally selected in the database. Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267385 Share on other sites More sharing options...
iLLeLogicaL Posted June 3, 2007 Share Posted June 3, 2007 It can't. Then you made a mistake somewhere because the code posted above does change the value of result. Quote Link to comment https://forums.phpfreaks.com/topic/54011-changing-mysql-database/#findComment-267420 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.