Jump to content

How do I...


Pi_Mastuh

Recommended Posts

I want to have it seach for an ID number in a table and if it finds it then to check if a value is above zero, if it is then dissplay error message one. If it's not, see if a second value is above zero and if it is display error message 2. How do I do that?
Link to comment
Share on other sites

ok, i c, well could do it a few differnet ways but couldnt u just get both values, check the first one then if its above 0 display error if its not check the second one etc.
like this:
[code]
$row = mysql_fetch_array(mysql_query("SELECT * FROM `table` WHERE `id`='1'"));

if($row['value1'] > 0){
echo "error msg #1";
}elseif($row['value2'] > 0){
echo "error msg #2";
}else{
echo "they are both 0";
}
[/code]

but i am still not sure if thats what ur asking.
Link to comment
Share on other sites

Well, i'm going to explain what I think you're saying. You want to check for a row with a certain id number and display an error if another value in that row is above zero.

[code]$sql = "SELECT * FROM `table` WHERE `id` = 1 AND `othernumber` > 0";
$result = mysql_query($sql);
if (mysql_num_rows($result)
{
    echo "ERROR!";
}[/code]
Link to comment
Share on other sites

from readin ur post i would agree with ProjectFear's approach. however i would suggest modifying the code as follows:

[code]
$query = sprintf("SELECT * FROM table WHERE id='1'");
$result = mysql_query($query);
if (!$result) {
die ('Invalid Query' . mysql_error());
}

$nums = mysql_num_rows($result);
if (!$nums) {
die ('Sorry, no entries found.');
}

while ($row = mysql_fetch_array($result)) {

if($row['value1'] > 0){
die (error msg #1');
}elseif($row['value2'] > 0){
die ('error msg #2');
}else{
echo "they are both 0";
break;
}

}
[/code]

This should work. It provides better scripting practice and some error handling.
Link to comment
Share on other sites

I'm using this:
[code]$sql = "SELECT count(*) as atkItem FROM Dualequip WHERE petID = '$monopetID'";
  $result1 = mysql_query($sql);
$query_data = mysql_fetch_array($result1);
$atkItem = $query_data['atkItem'];

if ($atkItem > 0)
{
$SQL = "SELECT * FROM Dualequip WHERE petID = '$monopetID'";
$result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
$query_data = mysql_fetch_array($result);
$atkValue = $query_data['atkValue'];
$defValue = $query_data['defValue'];
if ($atkValue > 0)
{
$no = 0;
}
elseif ($defValue > 0)
{
$no = 1;
}
else
{
$no = 3;
}
}[/code] and [code]if ($no == 0 AND $food == "Weapon" AND $atkValue > o)
{
echo "<p align=center>$monopetName already has an attack item equipped!<br><br><a href='../myitems.php'>Back to Your Inventory</a>";
}
elseif ($no == 1 AND $food == "Weapon" AND $defValue > o)
{
echo "<p align=center>$monopetName already has an defense item equipped!<br><br><a href='../myitems.php'>Back to Your Inventory</a>";
}
elseif ($food == "Weapon")
{
$sql = "INSERT INTO Dualequip (preuserID, petID, itemID, atkValue, defValue)
VALUES ('$preuserID', '$monopetID', '$itemID', '$atkValue', '$defValue')";
mysql_query("DELETE FROM myitemschibi WHERE itemID = '".$_POST['itemID']."'");

$result = mysql_query($sql) or die("There was an error equiping the weapon. Sorry.");
echo "<p align=center>You have equipped <b>".$monopetName."</b> with <b>".$itemName."</b>!<br><br><a href='../myitems.php'>Back to Your Inventory</a>";
}[/code] but the pet i'm using to test has 3 items equipped when it should only be 1. It's not blocking it.
Link to comment
Share on other sites

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.