Results 1 to 4 of 4

Thread: Php database query

  1. #1
    Join Date
    May 2008
    Posts
    248

    Php database query

    Hi
    I am trying table with the following structure
    ow-id-slot-amount
    ow is the owner, he is the id who will own the item. id will be the id of the item. sl is the position an am is the quantity. I would like to have a script that would find what is the highest slot and after that I would like to add a new entry into the next slot. My query to the database is something like this
    ORDER BY `SLOT` DESC with only one result, and then do a new entry with $query['slot'] + 1 as the slot.
    Is there any other way which is easier that this. Please help. Thanks in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Php database query

    Hi
    I have tried a query, just try it out. It will surely depend on the mysql version which your are using.
    Code:
    UPDATE table_name SET slot = slot+1 WHERE OWNDERID = (SELECT OWNERID FROM table_name ORDER BY SLOT DESC LIMIT 1) LIMIT 1
    Please do post back if it does not work with you.

  3. #3
    Join Date
    May 2008
    Posts
    248

    Re: Php database query

    Hi
    This is what i have tried, please check the following and if any thing wrong please advice me an alternative for that.
    Code:
       } else if ($page == "test") {
          $ch = $db->query("SELECT `amount` FROM `rscd_bank` WHERE `owner` = '" . $pun_user['id'] . "' AND `id` = '1295'") or die("error");
          $ch = $db->fetch_assoc($ch);
          $ch = $ch['amount'];
          
          if ($ch == 0) {
             $sl = $db->query("SELECT `sl` FROM `rscd_bank` WHERE `owner` = '" . $pun_user['id'] . "' ORDER BY `sl` DESC LIMIT 1") or die("error");
             $sl = $db->fetch_assoc($sl);
             $sl = $sl['sl'] + 1;
    
             $in = $db->query("in INTO `rscd_bank` (`owner` , `id` , `amount` , `sl`) VALUES ('" . $pun_user['id'] . "', '1295', '1', '" . $sl . "');");   
             
             $sl++;
          } else {
             $ch++;
             $up = $db->query("up `rscd_bank` SET `amount` = '" . $ch . "' WHERE `owner` = '" . $pun_user['id'] . "' AND `id` = '1295'") or die("error");
          }
          ?>
       <div class='menu'>

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Php database query

    Hi
    I think that the program is good and also efficient enough to work well. It should have no problem. I also tried a insert statement with a select from the table. But unfortunately it only works if the table is selected from the different location. Any way your program is almost correct.

Similar Threads

  1. Interrogating database with the query in MySQL
    By Xiomar in forum Software Development
    Replies: 3
    Last Post: 21-12-2010, 05:41 AM
  2. Query for columns in oracle database
    By Gerri in forum Windows Software
    Replies: 4
    Last Post: 10-02-2010, 08:27 PM
  3. Replies: 3
    Last Post: 09-07-2009, 05:12 PM
  4. Query Was Empty- error after inseting data into database
    By Gefry in forum Software Development
    Replies: 2
    Last Post: 18-05-2009, 06:43 PM
  5. SQL query to delete a row in database
    By Connect_Me in forum Software Development
    Replies: 3
    Last Post: 05-05-2009, 01:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,486,851.39929 seconds with 16 queries