Jump to content

using IF


desithugg

Recommended Posts

okay i have a button that i only want to appear once a certain row in the DB is zero or below zero
i have tried
[code]<?php
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('tpf');
if (!$db_selected) {
   die('Could not select database: ' . mysql_error());
}
$result = mysql_query("SELECT * from battle where me = '$user_currently_loged' LIMIT 1");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}
/* Use the result, assuming we're done with it afterwords */
$row = mysql_fetch_assoc($result);

/* Now we free up the result and continue on with our script */
mysql_free_result($result);
echo $dead = $row['my_hp']; ?>[/code]

thats the get there row that has to be below zero

[code]<?php if ($dead == 0) {
echo
<form action="battle.php" method="post">
<input readonly type="HIDDEN" name="my_hp" maxlength="500" value="<?php
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('tpf');
if (!$db_selected) {
die('Could not select database: ' . mysql_error());
}
$result = mysql_query("SELECT (my_hp - (((((2 * your_level / 5 + 2 )  * your_attack * your_sp_attack / my_defence ) /  50 ) + 2 ) * 2000 / 100 )) FROM battle WHERE me = '$user_currently_loged'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);

echo $row[0]; // 42
?>">
<input readonly type="HIDDEN" name="your_hp" maxlength="500" value="<?php
$link = mysql_connect('localhost', 'user', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('tpf');
if (!$db_selected) {
die('Could not select database: ' . mysql_error());
}
$result = mysql_query("SELECT (your_hp - (((((2 * my_level / 5 + 2 )  * my_attack * my_sp_attack / your_defence ) /  50 ) + 2 ) * 2000 / 100 )) FROM battle WHERE me = '$user_currently_loged'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);

echo $row[0]; // 42
?>">
<br>
<input type="submit" name="submit" value="Lost">
</form>?>
[/code]

this is what i have tried but it didnt seem to work so if any11 can help me with that id greatly appreciate it
Link to comment
https://forums.phpfreaks.com/topic/6903-using-if/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.