>>  Site Map >>  Forums >>  General 6x

Forum module - topics in forum:



General 6x - Discussions reagarding any other PHP-Nuke Problems.



what if statements

How do you write a small bit of php that gives a what if answer

Code: :
if ($reserveprice < $newbid)
     $bidstatus = 1;   
     } else {
     $bidstatus = 0;


I thought this would work, but its not. any ideas Sad

I've put this argument within the shown .php below:-

Code: :
if (is_user($user)) {

    $result = $db->sql_query("select bids,buyer,bidstatus from ".$prefix."_auction_items where cid=$item");
    list($bids,$buyer,$bidstatus) = $db->sql_fetchrow($result);
    $bids++;
    if ($reserveprice < $newbid)
     $bidstatus = 1;   
     } else {
     $bidstatus = 0;
    $result = $db->sql_query("update ".$prefix."_auction_items set buyitnow='0', buyer='$username', price='$newbid', bids='$bids', bidstatus='$bidstatus' where cid='$item'");







There are two formats you can take when writing if else statments
    The first is when the answer to the if else is one line piece of code, if this is the case you dont need the { }:
    Code: :
    if ($reserveprice < $newbid)
       $bidstatus = 1;   
    else
       $bidstatus = 0;

  1. But when there is more than one line you are required to use the { }:
    Code: :
    if ($reserveprice < $newbid)
       {
       $bidstatus = 1;
       $total = 5;
       }   
    else
       {
       $bidstatus = 0;
       $total = 0;
       }

This applies to the individual if / else statment not the enitre set of statments for example
Code: :
if ($reserveprice < $newbid)
   {
   $bidstatus = 1;
   $total = 5;
   }   
else
   $bidstatus = 0;

The if has more than one line of code and needs the { } but the else only has one so it doesnt.

On your code above, you are missing the { on both the if / else parts so your codes should be
Code: :
if ($reserveprice < $newbid)
   {
   $bidstatus = 1;
   }   
else
   {
   $bidstatus = 0;
   }

You dont have to use the { } on that one but seen as you had them in i put them in properly. The Second piece was the same missing { }, in this case i have used both methods, on the main if statment you have to use the { } but on the small one inside I have used no { } as the answer is only a one liner.
Code: :
if (is_user($user))
   {
    $result = $db->sql_query("select bids,buyer,bidstatus from ".$prefix."_auction_items where cid=$item");
    list($bids,$buyer,$bidstatus) = $db->sql_fetchrow($result);
    $bids++;
   
    if ($reserveprice < $newbid)
        $bidstatus = 1;   
   else
        $bidstatus = 0;
      
      $result = $db->sql_query("update ".$prefix."_auction_items set buyitnow='0', buyer='$username', price='$newbid', bids='$bids', bidstatus='$bidstatus' where cid='$item'");
   }


Hope this helps Smile






I thought I had it licked thier, if you look at my site under the auction, the reserve is set at £60.00, yet the current price is @ £65.00 and bidstatus stil = 0.

I've pasted the full page code to see if i'm missing a piece of the jigsaw puzzle here.

I'm confused as to why this isn't working. As soon as bidstatus = 1, the auction will say reserve met, i know this is end is working perfectly fine.

Code: :
if (is_user($user)) {

    $result = $db->sql_query("select bids,buyer,bidstatus from ".$prefix."_auction_items where cid=$item");
    list($bids,$buyer,$bidstatus) = $db->sql_fetchrow($result);
    $bids++;
   
if ($newbid > $reserveprice)
        $bidstatus = 1;   
     else
        $bidstatus = 0;
     
    $result = $db->sql_query("update ".$prefix."_auction_items set buyitnow='0', buyer='$username', price='$newbid', bids='$bids', bidstatus='$bidstatus' where cid='$item'"); }

     
    if ($buyer <> '-') {
     $result = $db->sql_query("select email from ".$user_prefix."_users where username='$buyer'");
     list($toemail) = $db->sql_fetchrow($result);

     $header  ="From: $sitename\n";
     $header .="Content-Type: text/plain; charset=iso-8859-1\n";
     $header .="Content-Transfer-Encoding: 8bit\n";
     $subject="Sie wurden überboten! Artikelnummer:$item";

     $emailbody  ="Sie wurden überboten!\n";
     $emailbody .="$nukeurl/modules.php?name=auktion&file=viewitem&item=$item&catnow=$catnow\n";

     mail($toemail,$subject,$emailbody,$header);
   
   
}
{
    header("location: modules.php?name=auktion&file=viewitem&item=$item&catnow=$catnow");
     
}

if (is_admin($admin) && !is_user($user)) {

    $result = $db->sql_query("select bids,buyer,bidstatus from ".$prefix."_auction_items where cid=$item");
    list($bids,$buyer,$bidstatus) = $db->sql_fetchrow($result);
    $bids++;
 
 if ($newbid > $reserveprice)
        $bidstatus = 1;   
     else
        $bidstatus = 0;

    $result = $db->sql_query("update ".$prefix."_auction_items set buyer='Administrator',
                        buyitnow='0', price='$newbid', bids='$bids', bidstatus='$bidstatus' where cid='$item'"); }

    if ($buyer <> '-') {
     $result = $db->sql_query("select email from ".$user_prefix."_users where username='$buyer'");
     list($toemail) = $db->sql_fetchrow($result);

     $header  ="From: $sitename\n";
     $header .="Content-Type: text/plain; charset=iso-8859-1\n";
     $header .="Content-Transfer-Encoding: 8bit\n";
     $subject="Sie wurden überboten! Artikelnummer:$item";

     $emailbody  ="Sie wurden überboten!\n";
     $emailbody .="$nukeurl/modules.php?name=auktion&file=viewitem&item=$item&catnow=$catnow\n";

     mail($toemail,$subject,$emailbody,$header);
   
    }
{
    header("location: modules.php?name=auktion&file=viewitem&item=$item&catnow=$catnow");
     }


As soon as I put a bid on its inputting "1" into the bidstatus






I didnt go thourgh the code cause i dont know what it in relastion to so not sure if its going to work but you seem to be missing cetin things like i said in the above post, in this case you were missing the word else in both if staments. Try to lay them out the way i have done this way you can see what you have closed } and what you havent and if you missing anything.
Code: :
if (is_user($user))
   {
    $result = $db->sql_query("select bids,buyer,bidstatus from ".$prefix."_auction_items where cid=$item");
    list($bids,$buyer,$bidstatus) = $db->sql_fetchrow($result);
    $bids++;
   
   if ($newbid > $reserveprice)
        $bidstatus = 1;   
    else
        $bidstatus = 0;
     
    $result = $db->sql_query("update ".$prefix."_auction_items set buyitnow='0', buyer='$username', price='$newbid', bids='$bids', bidstatus='$bidstatus' where cid='$item'"); }
     
    if ($buyer <> '-')
      {
        $result = $db->sql_query("select email from ".$user_prefix."_users where username='$buyer'");
        list($toemail) = $db->sql_fetchrow($result);

        $header  ="From: $sitename\n";
        $header .="Content-Type: text/plain; charset=iso-8859-1\n";
        $header .="Content-Transfer-Encoding: 8bit\n";
        $subject="Sie wurden überboten! Artikelnummer:$item";

        $emailbody  ="Sie wurden überboten!\n";
        $emailbody .="$nukeurl/modules.php?name=auktion&file=viewitem&item=$item&catnow=$catnow\n";

        mail($toemail,$subject,$emailbody,$header);   
      }
   else
      {
       header("location: modules.php?name=auktion&file=viewitem&item=$item&catnow=$catnow");
        }
   }

if (is_admin($admin) && !is_user($user))
   {
    $result = $db->sql_query("select bids,buyer,bidstatus from ".$prefix."_auction_items where cid=$item");
    list($bids,$buyer,$bidstatus) = $db->sql_fetchrow($result);
    $bids++;
 
    if ($newbid > $reserveprice)
        $bidstatus = 1;   
    else
        $bidstatus = 0;

    $result = $db->sql_query("update ".$prefix."_auction_items set buyer='Administrator',
                        buyitnow='0', price='$newbid', bids='$bids', bidstatus='$bidstatus' where cid='$item'"); }

    if ($buyer <> '-')
      {
        $result = $db->sql_query("select email from ".$user_prefix."_users where username='$buyer'");
        list($toemail) = $db->sql_fetchrow($result);

        $header  ="From: $sitename\n";
        $header .="Content-Type: text/plain; charset=iso-8859-1\n";
        $header .="Content-Transfer-Encoding: 8bit\n";
        $subject="Sie wurden überboten! Artikelnummer:$item";

        $emailbody  ="Sie wurden überboten!\n";
        $emailbody .="$nukeurl/modules.php?name=auktion&file=viewitem&item=$item&catnow=$catnow\n";

        mail($toemail,$subject,$emailbody,$header);
       }
   else
      {
       header("location: modules.php?name=auktion&file=viewitem&item=$item&catnow=$catnow");
       }
   }





Attention! You are currently viewing sitemap page!
We strongly suggest to look at original content

Search from web

Valid HTML 4.01 Valid CSS