Forum Moderators: coopster

Message Too Old, No Replies

If any column is equal to $var perfom action.

im so Confused

         

dkin

3:08 am on Jan 13, 2005 (gmt 0)

10+ Year Member



Im trying to run a code which will be activated when a user deletes an item from his inventory. I want the item to be deleted and a different tables cell to be updated.

My columns are set like this

weapon armor greaves etc etc

this is my code

##Connect to User Database
$uresult = mysql_query("SELECT * FROM user_char where username = '$username'", $link) or die ("query 1: " . mysql_error());

if ($urow = mysql_fetch_array($uresult) == $sitem)
{
$resresult = mysql_query("UPDATE user_char set $item_type2 = '' where username = '$username'", $link);
echo $sitem.''.$username.''.$item_type2;
}
else
{
echo $sitem.''.$username.''.$item_type2;
}

I keep getting the else activated.

$sitem = the item name
$item_type2 = greaves or helmet etc

Thank you

jatar_k

3:13 am on Jan 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



because this is wrong

$urow = mysql_fetch_array($uresult) == $sitem

extract the row to urow then compare the proper element in the array

like so

$urow = mysql_fetch_array($uresult) 
if ($urow['itemname'] == $sitem) {
$resresult = mysql_query("UPDATE user_char set $item_type2 = '' where username = '$username'", $link);
echo $sitem.''.$username.''.$item_type2;
} else {
echo $sitem.''.$username.''.$item_type2;
}

though $urow['itemname'] may not be the right column name

dkin

3:29 am on Jan 13, 2005 (gmt 0)

10+ Year Member



thats the thing, Im trying to match it with item_type.

The user_char database has columns named greaves, bracers, helmet etc

and those column names are held in the variable item type.

can I say something like if $sitem == (any cell in row where username = '$username')?

dkin

11:30 am on Jan 13, 2005 (gmt 0)

10+ Year Member



anyone? this is my biggest problem at the moment.

Salsa

5:10 pm on Jan 13, 2005 (gmt 0)

10+ Year Member



This thread [webmasterworld.com] answers how to do exactly what you want. I'm surprised you didn't read it.

dkin

9:53 pm on Jan 13, 2005 (gmt 0)

10+ Year Member



that tells me how to do it in the same database. I cant even really explain it because I have so many personal issues Im just so confused right now. This is my code you may be able to see what i am trying to do by looking at it.

function resell()
{
global $funds, $sell, $money, $username, $id, $link, $sitem, $username, $item_type2;
$money = $funds + $sell;

##Connect to User Database
$uresult = mysql_query("SELECT $item_type2 FROM user_char where username = '$username'", $link) or die ("query 1: " . mysql_error());
$urow = mysql_fetch_array($uresult) or die ("query 1: " . mysql_error());

if ($urow['$item_type2'] == $sitem)
{
$resresult = mysql_query("UPDATE user_char set $item_type2 = '' where username = '$username'", $link);
echo 'GOOD'.$sitem.''.$username.''.$item_type2;
}
else
{
echo 'BAD'.''.$urow[$item_type2].''.$sitem.''.$username.''.$item_type2;
index();
exit;
}

$sresult = mysql_query("UPDATE user_char set gold = '$money' where username = '$username'", $link);
$sdelete = mysql_query("DELETE FROM purchased where id = '$id' order by type asc", $link);

if ($sresult == TRUE && $sdelete == TRUE)
{
echo 'Item deleted and your gold has been updated. You now have '.$money.' gold.';
index();
}
else
{
echo 'Actions not executed';
index();
}

##End Function
}

dkin

3:03 am on Jan 14, 2005 (gmt 0)

10+ Year Member



figured it out, thanks.

it was the quotes here. $urow['$item_type2']