Is this code correct?
Posted: Mon Nov 17, 2003 3:30 pm
Hi! I was wondering if anyone here could help me look through the following lines of code and tell me whether it is corrrectly written for what I want it to do. Basically, what I need the code to do is to compare $itemfound with the user item. If the user already has the item, the code will get a different $itemfound until the $itemfound is something that the user does not have.
Did I write the do and while codes properly and whether does it go into infinte loop? Please tell me if there is a more efficient way to wrote the codes to achieve what I need.
Thanks.
Code: Select all
do {
// what item did the user won??
if ($itemtype == 'C')
{
$items_array = explode("##", $items_ch);
$newrand = rand(1,10);
$itemfound = $items_array[$newrand];
}
if ($itemtype == 'UC')
{
$items_array = explode("##", $items_ch);
$newrand = rand(1,10);
$itemfound = $items_array[$newrand];
}
if ($itemtype == 'R')
{
$items_array = explode("##", $items_ch);
$newrand = rand(1,10);
$itemfound = $items_array[$newrand];
}
if ($itemtype == 'VR')
{
$items_array = explode("##", $items_ch);
$newrand = rand(1,10);
$itemfound = $items_array[$newrand];
}
if (preg_match("/^@([A-Za-z]+[\_*|\s*|\-*|\&*|\(*|\)*]*)+/", $itemfound, $matches)) {
$temp_avatar_name = preg_replace("\@", "", $matches[0]);
$find_item_sql = "select * from phpbb_shops where name=".$item_avatar_name;
if ( !($find_item_result = $db->sql_query($find_item_sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error: '.mysql_error());
}
$find_item = mysql_fetch_array($find_item_result);
if (mysql_num_rows($find_item_result) < 1) { message_die(GENERAL_MESSAGE, 'No such item exists!'); }
$temp_find_item = "ß".$find_item['item_image_dir']."Þ";
$temp_user_bought_avatar = $row['user_bought_avatar'];
if (substr_replace($temp_user_bought_avatar, $temp_find_item, strpos($temp_user_bought_avatar, $temp_find_item), strlen($temp_find_item))) {
$item_repeat = 1;
}
else {
$item_repeat = 0;
}
}
else {
$item_repeat = 0;
}
}
while ($item_repeat != 0);
Thanks.