Jump to content

Recommended Posts

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.)

Link to comment
https://forums.phpfreaks.com/topic/54011-changing-mysql-database/
Share on other sites

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

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.

<?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

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.)

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";
?>

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.