lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Jonathan Hunter once stated:
> Hi Guys,
> 
> Im quite new to Lua and Im having an issue with extracting particular data
> where there a multiple rows in a database I want to deal with so was
> wondering if someone could help?
> 
> Basically using a function, Im extracting data from a Mysql table that has
> multiple rows, and its looping through the rows as expected.
> 
> Now I have setup a number of entries for Time of day and I want to stop the
> loop (exit it) as soon as there is a match, and Id like to know how to
> achieve this.
> 
> Basically I want to perform a query such as;
> 
> select priority,dayofmonth,month,year,dayofmonth from timeofday_new where
> todname='sales' order by priority;
> +----------+------------+-------+------+------------+
> | priority | dayofmonth | month | year | dayofmonth |
> +----------+------------+-------+------+------------+
> |        1 | 20         | 9     | 2015 | 20         |
> |        2 | 14-17      | 9     | 2015 | 14-17      |
> 

  What's wrong with this? (and please excuse the SQL, I'm not terribly
familiar with it and you would generally need to either bind the values you 
want to search to a prepared statement or build the SQL on the fly)


        t = os.date("*t")

        SELECT prority /* and other required fields */
        FROM timeofday_new
        WHERE
                todname = 'sales'     
                AND year = t.year     
                AND month = t.month   
                AND dayofmonth = t.day
        ORDER BY priority
  
  Let SQL do the work for you.  Or am I missing something?

  -spc