strange variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • none

    strange variables

    Hi, when i use the following code;

    $current_availa ble = mysql_query("SE LECT availableplaces FROM
    tblCourses WHERE course_id='$_PO ST[selectedcourse]'");
    $current_availa ble -= 1;
    mysql_query("UP DATE tblCourses SET
    availableplaces ='$current_avai lable' WHERE
    course_id='$_PO ST[selectedcourse]'");


    The variable $current_availa ble is initially 32, after running the
    above it is changed to 2.

    I'm really lost and would appreciate some direction.

    Many thanks
  • MJaC

    #2
    Re: strange variables

    none wrote:[color=blue]
    > Hi, when i use the following code;
    >
    > $current_availa ble = mysql_query("SE LECT availableplaces FROM
    > tblCourses WHERE course_id='$_PO ST[selectedcourse]'");
    > $current_availa ble -= 1;
    > mysql_query("UP DATE tblCourses SET
    > availableplaces ='$current_avai lable' WHERE
    > course_id='$_PO ST[selectedcourse]'");[/color]

    I think I understand what you want, however you are doing it wrong.
    Firstly you have an error, you need to fetch the result then decrement it.

    $course_places = mysql_query("SE LECT `availableplace s` - 1 FROM
    `tblCourses` WHERE `course_id`='$_ POST[selectedcourse]' LIMIT 1");
    $amount_availab le = mysql_result($c urrent_availabl e, 0, 'availableplace s');
    mysql_query("UP DATE `tblCourses` SET
    `availableplace s`='$amount_ava ilable' WHERE
    `course_id`='$_ POST[selectedcourse]' LIMIT 1");

    That should work, however there is a much faster, and easier way of
    doing it (UNLESS YOU WANT THE AMOUNT AVAILABLE)!

    mysql_query("UP DATE `tblCourses` SET
    `availableplace s`=`availablepl aces`-1 WHERE
    `course_id`='$_ POST[selectedcourse]' LIMIT 1");

    Comment

    • Nikolai Chuvakhin

      #3
      Re: strange variables

      kinskai@aol.com (none) wrote in message
      news:<863d38a1. 0404220935.3459 8ce8@posting.go ogle.com>...[color=blue]
      >
      > when i use the following code;
      >
      > $current_availa ble = mysql_query("SE LECT availableplaces FROM
      > tblCourses WHERE course_id='$_PO ST[selectedcourse]'");
      > $current_availa ble -= 1;
      >
      > The variable $current_availa ble is initially 32, after running the
      > above it is changed to 2.
      >
      > I'm really lost and would appreciate some direction.[/color]

      OK, here is your code again, slightly reformatted:

      $current_availa ble = mysql_query("SE LECT availableplaces
      FROM tblCourses WHERE course_id='$_PO ST[selectedcourse]'");

      This makes $current_availa ble a resource.

      $current_availa ble -= 1;

      Now all of a sudden you decide to treat $current_availa ble as if
      it were an integer. Needless to say, the results are not what
      you expect them to be...

      Cheers,
      NC

      Comment

      • none

        #4
        Re: strange variables

        nc@iname.com (Nikolai Chuvakhin) wrote in message news:<32d7a63c. 0404221505.f72a 83d@posting.goo gle.com>...[color=blue]
        > kinskai@aol.com (none) wrote in message
        > news:<863d38a1. 0404220935.3459 8ce8@posting.go ogle.com>...[color=green]
        > >
        > > when i use the following code;
        > >
        > > $current_availa ble = mysql_query("SE LECT availableplaces FROM
        > > tblCourses WHERE course_id='$_PO ST[selectedcourse]'");
        > > $current_availa ble -= 1;
        > >
        > > The variable $current_availa ble is initially 32, after running the
        > > above it is changed to 2.
        > >
        > > I'm really lost and would appreciate some direction.[/color]
        >
        > OK, here is your code again, slightly reformatted:
        >
        > $current_availa ble = mysql_query("SE LECT availableplaces
        > FROM tblCourses WHERE course_id='$_PO ST[selectedcourse]'");
        >
        > This makes $current_availa ble a resource.
        >
        > $current_availa ble -= 1;
        >
        > Now all of a sudden you decide to treat $current_availa ble as if
        > it were an integer. Needless to say, the results are not what
        > you expect them to be...
        >
        > Cheers,
        > NC[/color]


        Thanks for the input,

        I'm quite new to php but i suspected it may be something I was doing
        with the variables.

        The query;

        mysql_query("UP DATE `tblCourses` SET
        `availableplace s`=`availablepl aces`-1 WHERE
        `course_id`='$_ POST[selectedcourse]' LIMIT 1");

        worked a treat, but the first one (long way) threw an error as not
        been valid syntax.

        Cheers anyway :o)

        Comment

        Working...