SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Store multiple values in a variable

    I am using an while loop over a select statement and it's doing some calucaltion.Each iteration I am getting a value.But I have no idea how to store this value.Can anyone give me an idea how to do this?

    I want to process everthing in mysql and then returns all values to server side.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Please post your code.
    And what do you mean by "return all values to server side"? The PHP script IS server side.

  3. #3
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SET i=0;
    WHILE i<total_count DO

    select rate_margin*2 INTO @b from rate LIMIT i,1;

    SET i = i + 1;
    END WHILE;
    Select @b;
    I am getting only last value

  4. #4
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,435
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    You could save it into an array.
    PHP Code:
    $result_array = array();
    SET i=0;
     WHILE 
    i<total_count DO 

     
    select rate_margin*2 INTO @b from rate LIMIT i,1;
    $store_array[] = put your data here on each loop and it will build an array
     
    SET i 1;
     
    END WHILE;
     
    Select @b

  5. #5
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't want to use any server side code.Everything to be done in Mysql.You showed me some PHP code.I don't need this way.Any other ways

    Temporary table is the solution

    Any Idea how to do is temporary table ?

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,863
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Multiple values should be stored as multiple table rows. If your database doesn't currently allow for this then the design needs to be redone.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Multiple values should be stored as multiple table rows. If your database doesn't currently allow for this then the design needs to be redone.
    NO need of redesiging database table.If you would have looked my question you will never say like this.I have mentioned that I need to loop through the select statement and every time I get a value from select query and I need to store this value.Temprory table is the solution for this.I have sucessfully created temp table and able to store multiple value.

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,237
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by aniltc View Post
    .....
    Temprory table is the solution for this.I have sucessfully created temp table and able to store multiple value.
    Please share your solution so others facing a similar problem can benefit.


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
  •