Residental mod (help)


  -----  
Author Message

tabor
Member

Tue Feb 12, 2008 4:51 pm   Post subject: Residental mod (help)
Hi Thoul,

I would like to fix this update table in Residental mod but it didn't work at all. Could you please take a little time to guide me?

Quote:


//start of table updates
$leftamount = round($irow['user_points'] - ($row['cost'] * $qtybuy));
$totalcost = $row['cost'] * $qtybuy;
$i = 1;
$useritems = "".$irow['user_items']."".$item."";
while ( $i < $qtybuy )
{
$useritems .= "".$item."";
$i++;
}
$newstock = $row['stock'] - $qtybuy;

if ( $newstock < 0 )
message_die(GENERAL_MESSAGE, $lang['House_too_many'] );

$newsold = $row['sold'] + $qtybuy;
$sql = "UPDATE " . USER_ITEMS_TABLE . "
SET user_items='$useritems'
WHERE user_id='$userdata[user_id]'";
if ( !($uresults = $db->sql_query($sql)) )
message_die(GENERAL_ERROR, ( $lang['House_error_4'] != '' ) ? sprintf( $lang['House_error_4'], $lang['House_profile_data'] ) : 'Fatal Error Updating House data!', "", __LINE__, __FILE__, $sql);

$sql = "UPDATE " . USERS_TABLE . "
SET user_points='$leftamount'
WHERE username='$userdata[username]'";
if ( !($uresults = $db->sql_query($sql)) )
message_die(GENERAL_ERROR, ( $lang['House_error_4'] != '' ) ? sprintf( $lang['House_error_4'], $lang['House_profile_data'] ) : 'Fatal Error Updating House data!', "", __LINE__, __FILE__, $sql);


I got below error:

Quote:

SQL Error : 1054 Unknown column 'user_items' in 'field list'


I am not good at sql so if you have time please take a look on it.

Thanks,
 

Thoul
Administrator

Tue Feb 12, 2008 9:08 pm   Post subject: Re: Residental mod (help)
I take it you're trying to update this for Shop 3? If so, you'll need to replace this query because items are stored differently in Shop 3:

Code:

$sql = "UPDATE " . USER_ITEMS_TABLE . "
SET user_items='$useritems'
WHERE user_id='$userdata[user_id]'";

with something like this:

Code:

$sql = "INSERT INTO " . USER_ITEMS_TABLE . "
(user_id, item_id, item_name) VALUES (" . $userdata['user_id'] . ", {ITEM_ID}, '$item')";


Please note that this isn't exact - from the code you posted, I can't tell what the item's id number is called here, so I used {ITEM-ID} just as a placeholder.
 

tabor
Member

Tue Feb 12, 2008 11:06 pm   Post subject:
Yes, I am using shop 3.1.0

Thanks for your help, it works Very Happy

I still having one more problem that when script checks for how many items I already owned and it failed on this error:

Quote:

Fatal Error Getting User Info On Sell Page


Its around those lines:

Quote:

//check if has item
$sql = "select user_items, user_points from " . USERS_TABLE . " where username='$userdata[username]'";
if ( !($iresults = $db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error Getting User Info On Sell Page');
}
$irow = mysql_fetch_array($iresults);
if (substr_count($irow['user_items'],"".$item."") < 1)
{
message_die(GENERAL_MESSAGE, 'You dont have such an item.');
}
if (substr_count($irow['user_items'],"".$item."") < $qtysell)
{
message_die(GENERAL_MESSAGE, 'You dont have that many!');
}


I posted the whole shop script for you easy to see:

Quote:

//--------------------------------Shop Page START-----------------------------------------

if ($mode == 'SHOP')
{

$sql = "select * from ".HOUSE_SETTINGS_TABLE." where var=1";
if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error Getting House Configs!'); }
$crow = mysql_fetch_array($result);

$shop = $crow['shop_1'];
if (!isset($action))
{
$shopwelcome = "<tr><td class=\"row1\"><span class=\"gen\">
<img src=\"./images/house/shopkeeper.gif\" align=left hspace=12 v:shapes=\"_x0000_s1026\"> <br />
<b>Shopkeeper</b> <br />
<i>Welcome, how can i help you ?</i>
</span></td></tr>";


//start of shop restock code
$gsql = "select * from " . CONFIG_TABLE . " where config_name='restocks'";
if ( !($gresult = $db->sql_query($gsql)) ) { message_die(CRITICAL_ERROR, 'Fatal Error Getting Global Variable!'); }
$grow = mysql_fetch_array($gresult);
if ($grow['config_value'] == on)
{
$ssql = "select * from ".SHOP_TABLE." where restocktime!='0'";
if ( !($sresult = $db->sql_query($ssql)) ) { message_die(CRITICAL_ERROR, 'Fatal Error Checking Shops!'); }
$checktime = time();
for ($s = 0; $s < mysql_num_rows($sresult); $s++)
{
$srow = mysql_fetch_array($sresult);
if ($checktime - $srow['restockedtime'] > $srow['restocktime'])
{
$isql = "select * from ".SHOP_ITEMS_TABLE." where shop='$srow[shopname]'";
if ( !($iresult = $db->sql_query($isql)) ) { message_die(CRITICAL_ERROR, 'Error Getting Shop Items!'); }
for ($x = 0; $x < mysql_num_rows($iresult); $x++)
{
$irow = mysql_fetch_array($iresult);
if ($irow['stock'] < $irow['maxstock'])
{
$newstockam = $irow['stock'] + $srow['restockamount'];
if ($newstockam > $irow['maxstock']) { $newstockam = $irow['maxstock']; }
$u2sql="update ".SHOP_ITEMS_TABLE." set stock='$newstockam' where name='$irow[name]'";
if ( !($db->sql_query($u2sql)) ) { message_die(CRITICAL_ERROR, 'Fatal Error Updating Shop Stock!'); }
}
}
$susql = "update ".SHOP_TABLE." set restockedtime='$checktime' where shopname='$srow[shopname]'";
if ( !($db->sql_query($susql)) ) { message_die(CRITICAL_ERROR, 'Fatal Error Updating Shop Restocked Time!'); }
}
}
}
//end of shop restock code

//start of shop list page

$template->set_filenames(array(
'body' => 'house_shop_body.tpl')
);

// get shop details
$sql = "select * from ".SHOP_TABLE." where shopname='$shop'";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error Getting Shop Info for Shop Item List Page');
}
// ---

$row = mysql_fetch_array($result);
if (!isset($row['shopname'])) { message_die(GENERAL_MESSAGE, 'No Such Shop Exists!'); }
if (strtolower($row['shoptype']) == special) { message_die(GENERAL_MESSAGE, 'Invalid Page for Special Shop!'); }
// if (strtolower($row['shoptype']) == admin_only) { message_die(GENERAL_MESSAGE, 'No Such Shop Exists!'); }
$sql = "select * from ".SHOP_ITEMS_TABLE." where shop='$shop' order by name";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error Getting Shop Items for Shop Item List Page');
}
for ($er = 0; $er < mysql_num_rows($result); $er++)
{
$row = mysql_fetch_array($result);

if (file_exists("shop/images/".$row['name'].".jpg")) { $itemfilext = "jpg"; }
else { $itemfilext = "gif"; }

$useritemamount = 0;
if (strlen($userdata['user_items']) > 2)
{
$explodearray = explode("", str_replace("", "", $userdata['user_items']));
$arraycount = count($explodearray);
for ($sef = 0; $sef < $arraycount; $sef++)
{
if ($explodearray[$sef] == $row['name'])
{
++$useritemamount;
}
}
}

// Is item in stock?
If ($row['stock'] > 0)
{
$isiteminstock = '<span CLASS="gensmall"><BR><b>Shop has item:</b> Yes ('.$row['stock'].' left)</span>';
}
If ($row['stock'] <1)
{
$isiteminstock = '<span CLASS="gensmall"><BR><b>Shop has item:</b> No</span>';
}
$dummyvalue = 1;
$shops .= "
<tr>
<td class=\"row1\"><img src=\"shop/images/".$row['name'].".".$itemfilext."\" title=\"".ucfirst($row['name'])."\" alt=\"".$row['name']."\"></td>
<td class=\"row2\"><span class=\"gensmall\"><b>".ucfirst($row['name'])."</b> <br /> <i>".ucfirst($row['ldesc'])."</i> ".$arena_info." ".$isiteminstock."</span></td>
<td class=\"row1\"><span class=\"gensmall\">Costs: <b>".$row['cost']."</b> ".$pointsname." <br /><br />You have: <b>".$useritemamount."</b></span></td>
<td class=\"row1\"><span class=\"gensmall\">
<form action=\"".append_sid("house.".$phpEx."?mode=SHOP&action=SHOPBUY&item=".$row[name])."\" method=\"post\">
<b>Amount:</b> <input class=\"post\" type=\"text\" maxlength=\"3\" size=\"3\" name=\"qtybuy\" value=\"".($dummyvalue)."\">
<input type=\"submit\" class=\"button\" value=\"Buy\"></b></form>
<form action=\"".append_sid("house.".$phpEx."?mode=SHOP&action=SHOPSELL&item=".$row[name])."\" method=\"post\">
<b>Amount:</b> <input class=\"post\" type=\"text\" maxlength=\"3\" size=\"3\" name=\"qtysell\" value=\"".$dummyvalue."\">
<input type=\"submit\" class=\"button\" value=\"Sell\"></b></form></span></td></tr>";
}

$shopinforow = "<tr><td class=\"row1\"><span class=\"gen\">Icon</span></td><td class=\"row2\"><span class=\"gen\">Description</span></td><td class=\"row1\"><span class=\"gen\">Personal</span></td><td class=\"row1\"><span class=\"gen\">Shop Actions</span></td></tr>";
$page_title = "".ucwords($shop)." Inventory";
$shoptablerows = 4;
$return = '<td class="row1" align="center" valign="center"><form action="'.append_sid('house.' . $phpEx).'" method="post"><span class="genmed">Back to main house page<br><input type="submit" value="MAIN" name="mode"></span></form></td>';

$uselocation = " - House Shop";
$title = "House Shop";
$page_title = "House Shop";
$shoptitle = "House Shop";

}

if ($action == "SHOPBUY")
{
if (!isset($item))
{
message_die(GENERAL_MESSAGE, 'No Item Chosen!');
}
$template->set_filenames(array(
'body' => 'house_shop_body.tpl')
);


//make sure item exists
$sql = "select * from ".SHOP_ITEMS_TABLE." where name='$item'";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error Getting Item Info For Buy Page');
}
$row = mysql_fetch_array($result);
if (!isset($row['shop']))
{
message_die(GENERAL_MESSAGE, 'Such item does not exist!');
}
if ($row['stock'] < 1)
{
message_die(GENERAL_MESSAGE, 'Out of stock!');
}

if (($qtybuy == 0) || !is_numeric($qtybuy))
{
message_die(GENERAL_MESSAGE, 'Please select an amount!');
}

if ($row['stock'] < $qtybuy)
{
message_die(GENERAL_MESSAGE, 'The shop does not have so many!');
}

$sql = "select * from ".SHOP_TABLE." where shopname='$row[shop]'";
if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error'); }
$row1 = mysql_fetch_array($result);

//end check on item exists
//
//check points & if has item
$sql = "SELECT * FROM " . USER_ITEMS_TABLE . "
WHERE user_id='$userdata[user_id]'";
if ( !($iresults = $db->sql_query($sql)) )
message_die(GENERAL_ERROR, ( $lang['House_error_2'] != '' ) ? sprintf( $lang['House_error_2'], $lang['House_profile_data'] ) : 'Fatal Error Getting House data!', "", __LINE__, __FILE__, $sql);
$irow = mysql_fetch_array($iresults);

$sql = "SELECT user_points FROM " . USERS_TABLE . "
WHERE username='$userdata[username]'";
if ( !($iresults = $db->sql_query($sql)) )
message_die(GENERAL_ERROR, ( $lang['House_error_2'] != '' ) ? sprintf( $lang['House_error_2'], $lang['House_profile_data'] ) : 'Fatal Error Getting House data!', "", __LINE__, __FILE__, $sql);
$irow = mysql_fetch_array($iresults);

$gsql = "SELECT * FROM " . CONFIG_TABLE . "
WHERE config_name='multibuys'";
if ( !($gresult = $db->sql_query($gsql)) )
message_die( CRITICAL_ERROR, ( $lang['House_error_2'] != '' ) ? sprintf( $lang['House_error_2'], $lang['House_config_settings'] ) : 'Fatal Error Getting Configuration Settings!', "", __LINE__, __FILE__, $sql );
$grow = mysql_fetch_array($gresult);
if ( $grow['config_value'] == off )
{
if ( substr_count($irow['user_items'],"".$item."") > 0 )
message_die( GENERAL_MESSAGE, $lang['House_already_own_item'] );
}

if ( $irow['user_points'] < ( $row['cost'] * $qtybuy ) )
{
message_die( GENERAL_MESSAGE, sprintf( $lang['House_not_enough_points_item'], $pointsname, ($row['cost'] * $qtybuy), $pointsname, $qtybuy, $item ) );
}
//end of check for points and is has item
//

if ($row['stock'] < $qtybuy)
{
message_die(GENERAL_MESSAGE, 'The shop does not have that many!');
}

//start of table updates
$leftamount = round($irow['user_points'] - ($row['cost'] * $qtybuy));
$totalcost = $row['cost'] * $qtybuy;
$i = 1;
$useritems = "".$irow['user_items']."".$item."";
while ( $i < $qtybuy )
{
$useritems .= "".$item."";
$i++;
}
$newstock = $row['stock'] - $qtybuy;

if ( $newstock < 0 )
message_die(GENERAL_MESSAGE, $lang['House_too_many'] );

$newsold = $row['sold'] + $qtybuy;
$sql = "INSERT INTO " . USER_ITEMS_TABLE . "
(user_id, item_id, item_name) VALUES (" . $userdata['user_id'] . ", {$row['id']}, '$item')";
if ( !($uresults = $db->sql_query($sql)) )
message_die(GENERAL_ERROR, ( $lang['House_error_4'] != '' ) ? sprintf( $lang['House_error_4'], $lang['House_profile_data'] ) : 'Fatal Error Updating House data!', "", __LINE__, __FILE__, $sql);

$sql = "UPDATE " . USERS_TABLE . "
SET user_points='$leftamount'
WHERE username='$userdata[username]'";
if ( !($uresults = $db->sql_query($sql)) )
message_die(GENERAL_ERROR, ( $lang['House_error_4'] != '' ) ? sprintf( $lang['House_error_4'], $lang['House_profile_data'] ) : 'Fatal Error Updating House data!', "", __LINE__, __FILE__, $sql);


$sql="update ".SHOP_ITEMS_TABLE." set stock='$newstock', sold='$newsold' where name='$item'";
if ( !($db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error Updating Shop Items In Buy Page');
}
$useritemamount = substr_count($irow['user_items'],"".$item."") +$qtybuy;
//end of table updates
//
//start of echoes

$shopaction = "<tr><td colspan=\"6\" class=\"row1\"><span class=\"gen\">You buy <b>".$qtybuy." ".ucwords($item)."</b> for <b>".$totalcost." ".$pointsname."</b>, and have <b>".$leftamount." ".$pointsname."</b> left. </span></td></tr>";
$shopinforow = '';

$shopwelcome = "<tr><td class=\"row1\"><span class=\"gen\">
<img src=\"./images/house/shopkeeper.gif\" align=left hspace=12 v:shapes=\"_x0000_s1026\"> <br />
<b>Shopkeeper</b> <br />
<i>Hope you find a good place for it ?</i>
</span></td></tr>";

//
//update item info
$sql = "select * from ".SHOP_ITEMS_TABLE." where name='$item'";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error Refreshing Shop Info In Buy Page');
}
//end update
//
if (file_exists("shop/images/".$row['name'].".jpg")) { $itemfilext = "jpg"; }
else { $itemfilext = "gif"; }

$shoptablerows = 6;

$return = '<td class="row1" align="center" valign="center" colspan="3"><form action="'.append_sid('house.' . $phpEx).'" method="post"><span class="genmed">Back to main house page<br><input type="submit" value="MAIN" name="mode"></span></form></td><td class="row1" align="center" valign="center" colspan="3"><form action="'.append_sid('house.' . $phpEx).'" method="post"><span class="genmed">Back to furniture shop<br><input type="submit" value="SHOP" name="mode"></span></form></td>';
$shoptitle = "House Shop";


$uselocation = " - House Shop";
$title = "House Shop";
$page_title = "House Shop";



}

if ($action == "SHOPSELL")
{
if (!isset($item))
{
message_die(GENERAL_MESSAGE, 'No Item Chosen!');
}
$template->set_filenames(array(
'body' => 'house_shop_body.tpl')
);
if ( !$userdata['session_logged_in'] )
{
$redirect = "shop.$phpEx&action=sell&item=$item";
$redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}

//make sure item exists
$sql = "select * from ".SHOP_ITEMS_TABLE." where name='$item'";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error Getting Item Info For Buy Page');
}
$row = mysql_fetch_array($result);
if (!isset($row['shop']))
{
message_die(GENERAL_MESSAGE, 'Such an item does not exist!');
}



$sql = "select * from ".SHOP_TABLE." where shopname='$row[shop]'";
if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error'); }
$row1 = mysql_fetch_array($result);

//check if has item
$sql = "select user_items, user_points from " . USERS_TABLE . " where username='$userdata[username]'";
if ( !($iresults = $db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error Getting User Info On Sell Page');
}
$irow = mysql_fetch_array($iresults);
if (substr_count($irow['user_items'],"".$item."") < 1)
{
message_die(GENERAL_MESSAGE, 'You dont have such an item.');
}
if (substr_count($irow['user_items'],"".$item."") < $qtysell)
{
message_die(GENERAL_MESSAGE, 'You dont have that many!');
}
//start of table updates
$gsql = "select * from " . CONFIG_TABLE . " where config_name='sellrate'";
if ( !($gresult = $db->sql_query($gsql)) )
{
message_die(CRITICAL_ERROR, 'Getting Global Variables!');
}
$plusamount = $qtysell * (round($row['cost'] / 100 * 75));
$leftamount = $irow['user_points'] + $plusamount;
//need to remove all from user items
$j=1;
$useritems = substr_replace($irow['user_items'], "", strpos($irow['user_items'], "".$item.""), strlen("".$item.""));
while ($j < $qtysell)
{
$useritems = substr_replace($useritems, "", strpos($useritems, "".$item.""), strlen("".$item.""));
$j++;
}

$newstock = $row['stock'] + $qtysell;
$newsold = $row['sold'] - $qtysell;
$sql="update " . USERS_TABLE . " set user_points='$leftamount', where username='$userdata[username]'";
if ( !($uresults = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Fatal Error Updating User Information On Sell Page');
}

$sql = "DELETE FROM " . USER_ITEMS_TABLE . "
WHERE user_id = {$userdata['user_id']}
AND item_id = {$row['id']}
AND worn = 0
LIMIT " . $amount;
if ( !($db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error: updating item information');
}


$sql="update ".SHOP_ITEMS_TABLE." set stock='$newstock', sold='$newsold' where name='$item'";
if ( !($iresults = $db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error Updating Item Information on Sell Page');
}
//end of table updates
//
//start of echoes
$useritemamount = substr_count($irow['user_items'],"".$item."") -1;
$shopaction = "<tr><td colspan=\"6\" class=\"row1\"><span class=\"gen\">You sell <b>".$qtysell." ".ucwords($item)."</b> for <b>".$plusamount." ".$pointsname."</b> and now have <b>".$leftamount." ".$pointsname."</b>. </span></td></tr>";
$shopinforow = '';

// START SHOP CONVERSATIONS

$shopwelcome = "<tr><td class=\"row1\"><span class=\"gen\">
<img src=\"./images/house/shopkeeper.gif\" align=left hspace=12 v:shapes=\"_x0000_s1026\"> <br />
<b>Shopkeeper</b> <br />
<i>Here is your money.</i>
</span></td></tr>";

// END SHOP CONVERSATIONS

//
//update item info
$sql = "select * from ".SHOP_ITEMS_TABLE." where name='$item'";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error Updating Shop Info on Sell Page');
}
//end update
//
if (file_exists("shop/images/".$row['name'].".jpg")) { $itemfilext = "jpg"; }
else { $itemfilext = "gif"; }

$shoptablerows = 6;

$return = '<td class="row1" align="center" valign="center" colspan="3"><form action="'.append_sid('house.' . $phpEx).'" method="post"><span class="genmed">Back to main house page<br><input type="submit" value="MAIN" name="mode"></span></form></td><td class="row1" align="center" valign="center" colspan="3"><form action="'.append_sid('house.' . $phpEx).'" method="post"><span class="genmed">Back to furniture shop<br><input type="submit" value="SHOP" name="mode"></span></form></td>';
$shoptitle = "House Shop";


$uselocation = " - House Shop";
$title = "House Shop";
$page_title = "House Shop";


}
}
//--------------------------------Shop Page END-----------------------------------------


Thanks,
 

tabor
Member

Sun Jul 20, 2008 1:11 pm   Post subject: Re: Residental mod (help)
Thoul,

I still need help on this. Can't figure out what to change. Please!

Thanks
 

Page 1 of 1
Display posts from previous: